Skip to content

Commit b968f33

Browse files
committed
MAINT: remove the converged keyword to newton that was just added.
Added in scipygh-8357, seems unnecessary.
1 parent 747ee93 commit b968f33

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

scipy/optimize/tests/test_zeros.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_array_newton_zero_der_failures(self):
119119
# test failures and zero_der
120120
with pytest.warns(RuntimeWarning):
121121
results = zeros.newton(lambda y: y**2 - 2, [0., 0.],
122-
lambda y: 2*y, converged=True)
122+
lambda y: 2*y, full_output=True)
123123
assert_allclose(results.root, 0)
124124
assert results.zero_der.all()
125125
assert not results.converged.any()
@@ -292,14 +292,14 @@ def colebrook_eqn(darcy_friction, re, dia):
292292
with pytest.warns(RuntimeWarning):
293293
result = zeros.newton(
294294
colebrook_eqn, x0=[0.01, 0.2, 0.02223, 0.3], maxiter=2,
295-
args=[reynolds_number, diameter], converged=True
295+
args=[reynolds_number, diameter], full_output=True
296296
)
297297
assert not result.converged.all()
298298
# they all fail
299299
with pytest.raises(RuntimeError):
300300
result = zeros.newton(
301301
colebrook_eqn, x0=[0.01] * 2, maxiter=2,
302-
args=[reynolds_number, diameter], converged=True
302+
args=[reynolds_number, diameter], full_output=True
303303
)
304304

305305

scipy/optimize/zeros.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def _results_select(full_output, r):
8181

8282

8383
def newton(func, x0, fprime=None, args=(), tol=1.48e-8, maxiter=50,
84-
fprime2=None, full_output=False, disp=True, converged=False):
84+
fprime2=None, full_output=False, disp=True):
8585
"""
8686
Find a zero using the Newton-Raphson or secant method.
8787
@@ -93,14 +93,7 @@ def newton(func, x0, fprime=None, args=(), tol=1.48e-8, maxiter=50,
9393
9494
If `x0` is a sequence, then `newton` returns an array, and `func` must be
9595
vectorized and return a sequence or array of the same shape as its first
96-
argument. If an optional argument, `converged`, is `True`, then the
97-
return is a named tuple `(root, converged, zero_der)` in which `root` is an
98-
array of the locations where `func` is zero, `converged` is an array, same
99-
size as `root`, of booleans that are `True` where `func` converged, and
100-
`zero_der` is another boolean array of the same size where `func` had a
101-
zero derivative.
102-
103-
If `x0` is a sequence, then arguments `full_output` and `disp` are ignored.
96+
argument.
10497
10598
Parameters
10699
----------
@@ -128,28 +121,31 @@ def newton(func, x0, fprime=None, args=(), tol=1.48e-8, maxiter=50,
128121
is used.
129122
full_output : bool, optional
130123
If `full_output` is False (default), the root is returned.
131-
If True, the return value is ``(x, r)``, where ``x`` is the root, and
132-
``r`` is a `RootResults` object.
124+
If True and `x0` is scalar, the return value is ``(x, r)``, where ``x``
125+
is the root and ``r`` is a `RootResults` object.
126+
If True and `x0` is non-scalar, the return value is ``(x, converged,
127+
zero_der)`` (see Returns section for details).
133128
disp : bool, optional
134129
If True, raise a RuntimeError if the algorithm didn't converge, with
135130
the error message containing the number of iterations and current
136-
function value. *Note: this has little to do with displaying, however
131+
function value. Ignored if `x0` is not scalar.
132+
*Note: this has little to do with displaying, however
137133
the `disp` keyword cannot be renamed for backwards compatibility.*
138-
converged : bool, optional
139-
Only used if `x0` is a sequence. If True, two extras boolean arrays of
140-
converged and zero derivatives are appended to the return.
134+
141135
142136
Returns
143137
-------
144138
root : float, sequence, or ndarray
145139
Estimated location where function is zero.
146-
r : RootResults
147-
Present if ``full_output=True``. Object containing information about
148-
the convergence. In particular, ``r.converged`` is True if the routine
149-
converged.
140+
r : RootResults, optional
141+
Present if ``full_output=True`` and `x0` is scalar.
142+
Object containing information about the convergence. In particular,
143+
``r.converged`` is True if the routine converged.
150144
converged : ndarray of bool, optional
145+
Present if ``full_output=True`` and `x0` is non-scalar.
151146
For vector functions, indicates which elements converged successfully.
152147
zero_der : ndarray of bool, optional
148+
Present if ``full_output=True`` and `x0` is non-scalar.
153149
For vector functions, indicates which elements had a zero derivative.
154150
155151
See Also
@@ -184,7 +180,6 @@ class of similar problems can be solved together.
184180
185181
Examples
186182
--------
187-
188183
>>> from scipy import optimize
189184
>>> import matplotlib.pyplot as plt
190185
@@ -248,7 +243,7 @@ class of similar problems can be solved together.
248243
raise ValueError("maxiter must be greater than 0")
249244
if not np.isscalar(x0):
250245
return _array_newton(func, x0, fprime, args, tol, maxiter, fprime2,
251-
converged)
246+
full_output)
252247

253248
# Convert to float (don't use float(x0); this works also for complex x0)
254249
p0 = 1.0 * x0
@@ -314,8 +309,7 @@ class of similar problems can be solved together.
314309
return _results_select(full_output, (p, funcalls, itr + 1, _ECONVERR))
315310

316311

317-
def _array_newton(func, x0, fprime, args, tol, maxiter, fprime2,
318-
converged=False):
312+
def _array_newton(func, x0, fprime, args, tol, maxiter, fprime2, full_output):
319313
"""
320314
A vectorized version of Newton, Halley, and secant methods for arrays.
321315
@@ -409,7 +403,7 @@ def _array_newton(func, x0, fprime, args, tol, maxiter, fprime2,
409403
raise RuntimeError(msg)
410404
warnings.warn(msg, RuntimeWarning)
411405

412-
if converged:
406+
if full_output:
413407
result = namedtuple('result', ('root', 'converged', 'zero_der'))
414408
p = result(p, ~failures, zero_der)
415409

0 commit comments

Comments
 (0)