MCPcopy Index your code
hub / github.com/numpy/numpy / _div

Function _div

numpy/polynomial/polyutils.py:519–552  ·  view source on GitHub ↗

Helper function used to implement the `` div`` functions. Implementation uses repeated subtraction of c2 multiplied by the nth basis. For some polynomial types, a more efficient approach may be possible. Parameters ---------- mul_f : function(array_like, array_like) -

(mul_f, c1, c2)

Source from the content-addressed store, hash-verified

517
518
519def _div(mul_f, c1, c2):
520 """
521 Helper function used to implement the ``<type>div`` functions.
522
523 Implementation uses repeated subtraction of c2 multiplied by the nth basis.
524 For some polynomial types, a more efficient approach may be possible.
525
526 Parameters
527 ----------
528 mul_f : function(array_like, array_like) -> array_like
529 The ``<type>mul`` function, such as ``polymul``
530 c1, c2
531 See the ``<type>div`` functions for more detail
532 """
533 # c1, c2 are trimmed copies
534 [c1, c2] = as_series([c1, c2])
535 if c2[-1] == 0:
536 raise ZeroDivisionError # FIXME: add message with details to exception
537
538 lc1 = len(c1)
539 lc2 = len(c2)
540 if lc1 < lc2:
541 return c1[:1] * 0, c1
542 elif lc2 == 1:
543 return c1 / c2[-1], c1[:1] * 0
544 else:
545 quo = np.empty(lc1 - lc2 + 1, dtype=c1.dtype)
546 rem = c1
547 for i in range(lc1 - lc2, - 1, -1):
548 p = mul_f([0] * i + [1], c2)
549 q = rem[-1] / p[-1]
550 rem = rem[:-1] - q * p[:-1]
551 quo[i] = q
552 return quo, trimseq(rem)
553
554
555def _add(c1, c2):

Callers

nothing calls this directly

Calls 2

as_seriesFunction · 0.85
trimseqFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…