Skip to content

Commit

Permalink
lambertw: test maxiter= and convergence warning
Browse files Browse the repository at this point in the history
  • Loading branch information
alyst committed May 23, 2022
1 parent c54078e commit 1dc13d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lambertw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function lambertw_root_finding(z::T, x0::T, maxits::Integer) where T <: Number
lastx = x
lastdiff = xdiff
end
converged || @warn("lambertw(", z, ") did not converge in ", maxits, " iterations.")
converged || @warn "lambertw($z) did not converge in $maxits iterations."
return x
end

Expand Down
6 changes: 6 additions & 0 deletions test/lambertw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ end
@test lambertw(complex(-3.0, -4.0), 1) Complex(0.5887666813694675, 2.7118802109452247) atol=1e-14
@test lambertw(complex(.3, .3)) Complex(0.26763519642648767, 0.1837481231767825)

# test maxiter keyword and convergence warning
@test_logs (:warn, "lambertw(-0.2) did not converge in 3 iterations.") @inferred(lambertw(-0.2, -1, maxiter=3))
@test lambertw(-0.2, -1, maxiter=5) == lambertw(-0.2, -1)
@test_logs (:warn, "lambertw(0.3 + 0.3im) did not converge in 3 iterations.") @inferred(lambertw(complex(.3, .3), maxiter=3))
@test lambertw(complex(.3, .3), maxiter=5) == lambertw(complex(.3, .3))

# bug fix
# The routine will start at -1/e + eps * im, rather than -1/e + 0im,
# otherwise root finding will fail
Expand Down

0 comments on commit 1dc13d8

Please sign in to comment.