-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
RFC - Change signature of methods A_ldiv_B!(A, B) to A_ldiv_B!(X, A, B) #216
Comments
I really love this. It's more convenient to use and more consistent. |
+1 |
Sometimes, we may want to solve |
@lindahua Are you referring to the |
+1 |
@lindahua: I think @KristofferC is proposing adding additional |
Thanks for clarification. +1 |
The consistency here sounds great to me. We'd want to be careful about aliasing scenarios, I imagine |
I don't think this is a pattern we should encourage, as it is going to break in some cases, e.g.: julia> X = randn(5,5)
5x5 Array{Float64,2}:
1.33502 0.168431 -1.24184 0.152598 0.368737
-0.984189 -0.112196 -0.0336856 -0.281819 0.881885
1.35078 0.7121 -1.2564 0.316167 -0.14738
1.01016 -1.84001 -0.577902 0.286557 -1.2575
0.560689 2.57815 1.20324 -1.54285 1.1421
julia> A_mul_B!(X,X,X)
5x5 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 As a blatant plug, can I suggest the |
Regarding |
It seems to me that the problem with this kind of aliasing situation is that depending on the type of |
To be honest, I don't really see the issue with the potential aliasing problem. I would argue if you are using |
I think the better approach is that of BLAS and LAPACK where you only use output arrays if the algorithm requires. Therefore, it would be preferable if Pardiso and SuiteSparse changed their signatures to update I completely agree with @KristofferC's last comment that users of the |
Writers of the |
I think the approach should be to note that aliasing of input arguments is illegal in general and comment specifically when aliasing is ok. |
I would suggest that the user should operate on the assumption that the 3-argument form can't be aliased, and we should provide the 2-argument form (or use an |
The easy thing about the BLAS/LAPACK approach is that aliasing is never okay. I'd also like to add that Julia/LLVM has a hard time optimizing the loads and stores of arrays because of the aliasing. This only applies to the functions implemented in Julia but anyway. The more vector arguments, the more potential aliasing to make optimizations harder. |
Bump. It seemed like almost everyone was in favor of this. |
I've started on UMFPACK, at least for real types. |
I just looked at CHOLMOD's |
This is great. Looking forward to when this is merged. |
UMFPACK is much easier. Just swap a |
For the LAPACK versions that solve |
Are you asking if we should support three argument |
Yes. |
For now, we should probably support the three argument version for all |
3-arg form added in JuliaLang/julia#16702 |
Can this be closed then? |
Still lacks CHOLMOD if I understand things correctly. |
I made an implementation for It currently only supports Float64 (not Complex128), but that should be (relatively) easy to add. I solved the problem of references by making sure CHOLMOD does all the allocations. I think the code works as expected, I have not found any memory leaks at least. There were some problems that makes the code a bit ugly (and unsafe?). For example if RHS has less than 4 columns (say 1), CHOLMOD still wants to allocate work-space Y to be 4-by-n. If less is supplied (or more) it will free and reallocate 4-by-n workspace. I solved this by manually setting |
I believe this can be closed but please do reopen if necessary. |
Currently, the methods for solving linear system of equations in place (
A_ldiv_B!
) takes two argumentsA
andB
. In some cases, callingA_ldiv_B!(A, B)
will updateB
, in some cases not, see: #201.There are many solvers that does not support updating
B
directly but instead needs a preallocated solution array passed into them to store the solution in. This is true for i.e.UMFPACK
which means that currently there is no way to callA_ldiv_B!
for sparseA
and have it not allocate the solution array at each call.It also means that there is no clean way to keep your RHS
B
intact while calling in place solvers. Instead you need to copyB
before the call sinceB
gets overwritten.I believe that a more natural signature for these methods would be
A_ldiv_B!(X, A, B)
whereX
is the preallocated array to store the solution. This has symmetry withA_mul_B!(X, A, B)
and it leaves the RHS untouched.I might have missed a good reason why the current signatures are the way there are but from my point of view this looks cleaner. It is also the path I took in https://github.com/KristofferC/Pardiso.jl where I have the following solve methods:
Any comments on the sensibility and feasibility for this suggestion?
The text was updated successfully, but these errors were encountered: