(alpha1)
| 98 | fc = [0] |
| 99 | |
| 100 | def phi(alpha1): |
| 101 | # it's necessary to check boundary condition here for the coefficient |
| 102 | # as the callback could be evaluated for negative value of alpha by |
| 103 | # `scalar_search_armijo` function here: |
| 104 | # |
| 105 | # https://github.com/scipy/scipy/blob/11509c4a98edded6c59423ac44ca1b7f28fba1fd/scipy/optimize/linesearch.py#L686 |
| 106 | # |
| 107 | # see more details https://github.com/PythonOT/POT/issues/502 |
| 108 | alpha1 = np.clip(alpha1, alpha_min, alpha_max) |
| 109 | # The callable function operates on nx backend |
| 110 | fc[0] += 1 |
| 111 | alpha10 = nx.from_numpy(alpha1) |
| 112 | fval = f(xk0 + alpha10 * pk0, *args) |
| 113 | if isinstance(fval, float): |
| 114 | # prevent bug from nx.to_numpy that can look for .cpu or .gpu |
| 115 | return fval |
| 116 | else: |
| 117 | return nx.to_numpy(fval) |
| 118 | |
| 119 | if old_fval is None: |
| 120 | phi0 = phi(0.0) |
no test coverage detected