Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[newton] fixed bugs with residual being exactly 0 #932

Merged
merged 3 commits into from Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pymor/algorithms/newton.py
Expand Up @@ -11,7 +11,7 @@

@defaults('miniter', 'maxiter', 'rtol', 'atol', 'relax', 'stagnation_window', 'stagnation_threshold')
def newton(operator, rhs, initial_guess=None, mu=None, error_norm=None, least_squares=False,
miniter=0, maxiter=100, rtol=-1., atol=-1., relax=1.,
miniter=0, maxiter=100, rtol=0., atol=0., relax=1.,
stagnation_window=3, stagnation_threshold=np.inf,
return_stages=False, return_residuals=False):
"""Basic Newton algorithm.
Expand Down
9 changes: 7 additions & 2 deletions src/pymortests/algorithms/stuff.py
Expand Up @@ -13,10 +13,10 @@
from pymortests.fixtures.operator import MonomOperator


def _newton(order, **kwargs):
def _newton(order, initial_value=1.0, **kwargs):
mop = MonomOperator(order)
rhs = NumpyVectorSpace.from_numpy([0.0])
guess = NumpyVectorSpace.from_numpy([1.0])
guess = NumpyVectorSpace.from_numpy([initial_value])
return newton(mop, rhs, initial_guess=guess, **kwargs)


Expand All @@ -31,5 +31,10 @@ def test_newton_fail():
_ = _newton(0, maxiter=10, stagnation_threshold=np.inf)


def test_newton_residual_is_zero(order=5):
U, _ = _newton(order, initial_value=0.0)
assert float_cmp(U.to_numpy(), 0.0)


if __name__ == "__main__":
runmodule(filename=__file__)