-
-
Notifications
You must be signed in to change notification settings - Fork 24
Conversation
Codecov Report
@@ Coverage Diff @@
## main #22 +/- ##
==========================================
- Coverage 91.32% 89.47% -1.86%
==========================================
Files 8 8
Lines 219 247 +28
==========================================
+ Hits 200 221 +21
- Misses 19 26 +7
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Just do
|
src/klement.jl
Outdated
@@ -16,7 +16,7 @@ function SciMLBase.solve(prob::NonlinearProblem, | |||
x = float(prob.u0) | |||
fₙ = f(x) | |||
T = eltype(x) | |||
J = ArrayInterfaceCore.zeromatrix(x) + I | |||
J = init_J(x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this to Broyden too
I didn't manage to get the program non-allocating on static-arrays due to Just tell me if I can improve anything, |
src/klement.jl
Outdated
F = lu(J, check = false) | ||
|
||
iszero(fₙ) && | ||
return SciMLBase.build_solution(prob, alg, xₙ, fₙ; | ||
retcode = ReturnCode.Success) | ||
# Singularity test | ||
if any(abs.(F.U[diagind(F.U)]) .< singular_tol) | ||
J = init_J(xₙ) | ||
F = lu(J, check = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does one more LU factorization than is needed. Instead, move the factorization to the top
src/klement.jl
Outdated
return SciMLBase.build_solution(prob, alg, xₙ, fₙ; | ||
retcode = ReturnCode.Success) | ||
# Singularity test | ||
if any(abs.(F.U[diagind(F.U)]) .< singular_tol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allocates unnecessarily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get abs(F.factors[end, end])
to work for static arrays (F.factors
gives error)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And for non-static arrays abs(F.factors[end, end])
worked fine if J
was non-singular.
But it didn't work as I excpected when J
was singular, i.e. it gave abs(F.factors[end, end])=3.0
and abs(F.factors[end-1, end-1])=0.0
, resulting in the solver ending up with NaN
as output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's open up an issue on this. It may need to be specialized more, but for now we can go with this.
Trying to solve #20 and #19.
I tried the approach described in #18
But I have not used the singularity test @YingboMa explained:
"Or
F = lu(J)
, and the singularity check is thenabs(F.factors[end, end]) < singular_tol
"Although that solution was faster I was afraid that the LU-decomposition
lu(J)
could result in an error ifJ
was singular.Therefore I read about good approaches to checking for a singular matrix and found that
was a good approach (https://stackoverflow.com/questions/13145948/how-to-find-out-if-a-matrix-is-singular and https://discourse.julialang.org/t/checking-for-singularity-of-matrix/54746/4)
Is this OK, or do you want me to change something?