Helper function used to implement the `` fromroots`` functions. Parameters ---------- line_f : function(float, float) -> ndarray The `` line`` function, such as ``polyline`` mul_f : function(array_like, array_like) -> ndarray The `` mul`` function
(line_f, mul_f, roots)
| 458 | |
| 459 | |
| 460 | def _fromroots(line_f, mul_f, roots): |
| 461 | """ |
| 462 | Helper function used to implement the ``<type>fromroots`` functions. |
| 463 | |
| 464 | Parameters |
| 465 | ---------- |
| 466 | line_f : function(float, float) -> ndarray |
| 467 | The ``<type>line`` function, such as ``polyline`` |
| 468 | mul_f : function(array_like, array_like) -> ndarray |
| 469 | The ``<type>mul`` function, such as ``polymul`` |
| 470 | roots |
| 471 | See the ``<type>fromroots`` functions for more detail |
| 472 | """ |
| 473 | if len(roots) == 0: |
| 474 | return np.ones(1) |
| 475 | else: |
| 476 | [roots] = as_series([roots], trim=False) |
| 477 | roots.sort() |
| 478 | p = [line_f(-r, 1) for r in roots] |
| 479 | n = len(p) |
| 480 | while n > 1: |
| 481 | m, r = divmod(n, 2) |
| 482 | tmp = [mul_f(p[i], p[i+m]) for i in range(m)] |
| 483 | if r: |
| 484 | tmp[0] = mul_f(tmp[0], p[-1]) |
| 485 | p = tmp |
| 486 | n = m |
| 487 | return p[0] |
| 488 | |
| 489 | |
| 490 | def _valnd(val_f, c, *args): |