-
Notifications
You must be signed in to change notification settings - Fork 42
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
Laziness of *(LinearMap, Matrix) #156
Comments
This is very old default behavior of
Due to the existence of |
Right but this breaks downstream users who just expect LinearMaps to behave as essentially sparse matrices (which is a very reasonable thing to do). Eg I can't write
It's also confusing to me to have * be lazy but mul! be eager. If you want laziness for A*X you probably want laziness for X also, so it's reasonable to ask the user to do LinearMap(X). The rule op(lazy, lazy) => lazy and op(lazy, eager) => eager seems reasonable to me, no? |
There is no right or wrong here, just two points of view, and one which has been the default perhaps since the creation of the package. What's wrong with function block_richardson(A,X, B)
while iteration
Xnext = X - alpha * (convert(AbstractMatrix, A * X) - B)
end
end ? I mean, of course, one can change the |
It would anyway be better to write something like
In the original version, after having created I guess we do currently not define the behaviour of |
It's forcing LinearMap's idiosyncrasies onto solvers (which may not be designed with LinearMaps in mind), so it's kind of nullifying the point of LinearMap, which is (to me) to write a solver as if A was a matrix. @Jutho the above snippet was of course a simplification. I use |
I don't think this was ever the premise of |
"as if" is the key point here: it's essentially duck typing. LinearMaps quacks like a duck for all the operations it defines, except I believe for this one. |
So it's really just this one line, cause in the loop you are also using |
I don't quite agree; this is the first line of the README: "Linear maps are also known as linear transformations or linear operators acting on vectors. The only requirement for a LinearMap is that it can act on a vector (by multiplication) efficiently." If you define Or do you want |
I'd just define it the way it's defined now with AbstractVector. If for some reason you do
I tend to think of packages like LinearMaps as "implement all the methods you can using this interface", so that I don't have to think about it. Agree that it comes down to preferences and intended use for LinearMaps. |
Indeed, I also agree it's very much a matter of opinion. Hence, one final opinion from my side :-). The point of In my (very limited) mind set, block-Krylov methods are maybe the only place where you do actually want |
I didn't even see that +(::LinearMap, ::Matrix) was defined. Personally I would just leave all of these undefined, and only define lazy operations between LinearMaps. LinearMap are nontrivial data structures with large performance implications, and so I would be as explicit as possible. But I don't really use FunctionMap composition a lot so that might be my biases showing.
I think the difference is that you see matrices as operator by default, and I see matrices as bunches of vectors by default. There are lots of contexts where this makes sense - in my field of electronic structure, there are a bunch of electrons that each have their orbitals, which are naturally stored as one matrix, with each column being an electron. |
I agree a matrix can be much more, but I think that my perspective is that in the context of LinearMaps.jl, a As for a list of vectors, because I typically deal with vectors which are not |
OK, it's not the design I would have hoped for, but I appreciate that it's internally consistent and useful for other tasks - thanks for the clarification.
Yeah that's always an unpleasant ambiguity of figuring out the right layout... We went with matrix because of more efficient BLAS, typically for computing overlap matrices and such. |
I still think the |
@antoine-levitt (and anyone else who hits this thread), just FYI part of the reason I developed https://github.com/JeffFessler/LinearMapsAA.jl was to make the operators behave more like an |
Nice! Very cool that you can just reuse the LinearMaps machinery in an outside type. |
From the docs of Base.:*
This is annoying when eg implementing block iterative solvers. Is there any reason this does that instead of just applying A on each column?
The text was updated successfully, but these errors were encountered: