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)
| 534 | |
| 535 | |
| 536 | def _div(mul_f, c1, c2): |
| 537 | """ |
| 538 | Helper function used to implement the ``<type>div`` functions. |
| 539 | |
| 540 | Implementation uses repeated subtraction of c2 multiplied by the nth basis. |
| 541 | For some polynomial types, a more efficient approach may be possible. |
| 542 | |
| 543 | Parameters |
| 544 | ---------- |
| 545 | mul_f : function(array_like, array_like) -> array_like |
| 546 | The ``<type>mul`` function, such as ``polymul`` |
| 547 | c1, c2 |
| 548 | See the ``<type>div`` functions for more detail |
| 549 | """ |
| 550 | # c1, c2 are trimmed copies |
| 551 | [c1, c2] = as_series([c1, c2]) |
| 552 | if c2[-1] == 0: |
| 553 | raise ZeroDivisionError() |
| 554 | |
| 555 | lc1 = len(c1) |
| 556 | lc2 = len(c2) |
| 557 | if lc1 < lc2: |
| 558 | return c1[:1]*0, c1 |
| 559 | elif lc2 == 1: |
| 560 | return c1/c2[-1], c1[:1]*0 |
| 561 | else: |
| 562 | quo = np.empty(lc1 - lc2 + 1, dtype=c1.dtype) |
| 563 | rem = c1 |
| 564 | for i in range(lc1 - lc2, - 1, -1): |
| 565 | p = mul_f([0]*i + [1], c2) |
| 566 | q = rem[-1]/p[-1] |
| 567 | rem = rem[:-1] - q*p[:-1] |
| 568 | quo[i] = q |
| 569 | return quo, trimseq(rem) |
| 570 | |
| 571 | |
| 572 | def _add(c1, c2): |