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

Use 3-arg ldiv! #81

Merged
merged 4 commits into from
Dec 22, 2021
Merged

Use 3-arg ldiv! #81

merged 4 commits into from
Dec 22, 2021

Conversation

simonbyrne
Copy link
Contributor

Unless you need it to operate in-place, it would probably make more sense to use the 3-arg ldiv! everywhere

Unless you need it to operate in-place, it would probably make more sense to use the 3-arg `ldiv!` everywhere
@ChrisRackauckas
Copy link
Member

No, we cannot do this because using 3-argument ldiv breaks downstream. This is why DiffEqBase was using it. See JuliaLang/julia#33143 (comment) for details. This was already changed in #76 and I don't think we'd change the default here given how breaking the 3-argument one is due to the GC bugs.

@simonbyrne
Copy link
Contributor Author

I seem to recall that for our Schur solve, which we treat as a factorization, couldn't generally be solved in-place. What if you defined your own 3-arg _ldiv! function that we could intercept?

@simonbyrne
Copy link
Contributor Author

Do you ever need to solve non-square matrices?

@simonbyrne
Copy link
Contributor Author

simonbyrne commented Dec 21, 2021

Okay, how about this (it's not pretty, I will concede that).

bors bot added a commit to CliMA/ClimaCore.jl that referenced this pull request Dec 21, 2021
374: add overload 2-arg ldiv r=simonbyrne a=simonbyrne

Hopefully should fix #371.

See SciML/LinearSolve.jl#81 for discussion of underlying issue.

Co-authored-by: Simon Byrne <[email protected]>
@simonbyrne
Copy link
Contributor Author

Also, there is an upstream issue: JuliaLang/LinearAlgebra.jl#897

@@ -1,11 +1,20 @@
function _ldiv!(x, A, b)
# work around https://github.com/JuliaLang/julia/issues/43507
if @which(ldiv!(x,A,b)) == which(ldiv!,Tuple{LU{Float64, Matrix{Float64}},Vector{Float64}})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this resolve at compile time, or compile away?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does look like a runtime thing, so not ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could just make it

function _ldiv!(x, A, b)
        copyto!(x, b)
        ldiv!(A, x)
end

and then it could be monkey-patched if need be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or just

_ldiv!(x, A, b) = ldiv!(x, A, b)
function _ldiv!(x::Vector, A::Matrix, b::Vector)
        copyto!(x, b)
        ldiv!(A, x)
end

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factorization instead of Matrix, but yeah

@ChrisRackauckas ChrisRackauckas merged commit f3e62ee into SciML:main Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants