(which)
| 1700 | return x if isinstance(x, Number) else x() |
| 1701 | |
| 1702 | def pick_bound(which): |
| 1703 | def _pb(): |
| 1704 | fmin_tup = f_memo(x_min) |
| 1705 | fmax_tup = f_memo(x_max) |
| 1706 | fmin = fmin_tup[0] |
| 1707 | fmax = fmax_tup[0] |
| 1708 | |
| 1709 | if which(fmin): |
| 1710 | return x_min |
| 1711 | elif which(fmax): |
| 1712 | return x_max |
| 1713 | else: |
| 1714 | raise ValueError("failed to bracket the root in find_root_deriv") |
| 1715 | |
| 1716 | return _pb |
| 1717 | |
| 1718 | def in_bounds(x, f, df, a, b): |
| 1719 | return (f - (df * (x - a))) * (f - (df * (x - b))) < 0 |