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)
| 441 | |
| 442 | |
| 443 | def _fromroots(line_f, mul_f, roots): |
| 444 | """ |
| 445 | Helper function used to implement the ``<type>fromroots`` functions. |
| 446 | |
| 447 | Parameters |
| 448 | ---------- |
| 449 | line_f : function(float, float) -> ndarray |
| 450 | The ``<type>line`` function, such as ``polyline`` |
| 451 | mul_f : function(array_like, array_like) -> ndarray |
| 452 | The ``<type>mul`` function, such as ``polymul`` |
| 453 | roots |
| 454 | See the ``<type>fromroots`` functions for more detail |
| 455 | """ |
| 456 | if len(roots) == 0: |
| 457 | return np.ones(1) |
| 458 | else: |
| 459 | [roots] = as_series([roots], trim=False) |
| 460 | roots.sort() |
| 461 | p = [line_f(-r, 1) for r in roots] |
| 462 | n = len(p) |
| 463 | while n > 1: |
| 464 | m, r = divmod(n, 2) |
| 465 | tmp = [mul_f(p[i], p[i + m]) for i in range(m)] |
| 466 | if r: |
| 467 | tmp[0] = mul_f(tmp[0], p[-1]) |
| 468 | p = tmp |
| 469 | n = m |
| 470 | return p[0] |
| 471 | |
| 472 | |
| 473 | def _valnd(val_f, c, *args): |