-
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
Why no getindex() ? #38
Comments
Isn't |
Yes
My real goal here is that I want LinearMaps to be a subtype of AbstractMatrix (which requires Using multiplication as a default means to provide I also have an idea about |
First, there is a
if I'm not mistaken.
I don't think this is a fair statement. After all, all you're using is multiplication with a very special vector, which is supported by More generally, I have a very hard time understanding what you're trying to do. If you want everything to work like with a matrix, then why not work with matrices? You can convert any I think one of the main reasons why there is no BTW, for an implementation of matrix-free iterative "matrix" algorithms see the packages listed at the end of our README. |
@JeffFessler , what is |
@Jutho and @dkarrasch thanks for the fast replies. I especially appreciate the explanation about Based on my Matlab experience, having built-in indexing ability like I am going to make a fork with a Thanks! In case you are curious about the Matlab version, the high-level link is here: BTW, yes cgls is CG LS and that is just an example. |
@JeffFessler I'm afraid I still haven't quite understood what's the actual purpose of Maybe, there is a difference in intentions between your MATLAB package and @Jutho's @JeffFessler could you try to be more specific about what exactly you're targetting at? Why exactly do you need
The resulting method should then apply to |
Thanks for the reply. I understand the reluctance about making I don't understand the reluctance to provide the convenience of Support for The Matlab "SPOT" package has both And the Julia package |
When I first started using Julia, now several years ago (Julia 0.3 or maybe even 0.2), I also assumed that any linear map should be a subtype of Returning to the specific proposal, I still don't understand the specific use case. If you want to apply an algorithm that requires If the algorithm that you want to apply does not need an efficient Similarly, in Julia, there is no specific supertype for e.g. iterators, because many objects behave as iterators and represent them in various ways. The type hierarchy is often about the specific representation. And all methods that accept iterators just accept any type. It's up to the user not to insert a non-iterable object into a method that expects an iterator. If you do, you will likely get a In fact, the reason that I personally moved away from using LinearMaps.jl myself, is because it did not go far enough. Not only do I want my linear maps to be completely generic, I also do not want to restrict to |
I've provided url's for 3 distinct packages that all provide the convenience of You've made an key observation that "there is no common super type for all objects that behave as a linear map." Perhaps that is what I am really missing here. I wish Julia had an |
That's an interesting proposal, but how would it work. How would you only make I think what you are looking for is the concept of an interface or traits system, which is independent from type hierarchies, exists in many languages, and has been discussed in Julia, but so far has not been formalized or acquired syntax. There are packages for prototyping and experimenting with this, e.g. https://github.com/andyferris/Traitor.jl |
@JeffFessler If you don't like the duck-typing (which is used in |
Just in case anyone else lands here looking for |
In case anyone else comes looking for |
@dkarrasch If I may add to the discussion: Having the option of a custom getindex could be very useful. Oftentimes you might have custom methods for computing individual entries and you might want to use that alongside your efficient methods for multiplication. Fast multipole method comes to mind. If you are curious I have such a use case with a custom type written and used here: https://github.com/bonevbs/HssMatrices.jl/blob/main/src/linearmap.jl |
I think it is perfectly legitimate to define struct IndexableLinearMap{T,A<:LinearMap,F} <: LinearMap{T}
lmap::A
getidxs::F
end
# redirect most functions to the lmap field
adjoint(A::IndexableLinearMap) = IndexableLinearMap(adjoint(A), (i,j) -> conj(A.getidxs(j,i)))
mul!(y, A::IndexableLinearMap, x) = mul!(y, A.lmap, x)
# all your getindex-overloads for IndexableLinearMap In fact, this might be a feature for the package, because it gives indexability but at the same time forces the user to take responsability of it. The big danger is that if |
I agree, this is probably the best way to do it. I only recently realised the dangers of Julia's type system being the silent use of fall-back routines, at the cost of performance. |
What about having a |
If I recall correctly, constant propagation also works for keyword arguments in Julia 1.x for some lower bound on x, so this could be possible while still having a dedicated |
I think I have a draft here. Will put it out tomorrow. |
Reviews and comments welcome in #145. |
Why is
getindex
not supported (quite explicitly in the README) for LinearMaps?It seems like it would be pretty easy to provide the functionality as a convenience to users even if it would be somewhat inefficient. For example here is a rough start on
A[i,j]
I am less sure how getindex works for
A[:,j]
which is what I really want.Of course I could do this type of overloading myself locally, but why not benefit all users?
I've done this in Matlab by the way so I expected it to be even easier in Julia!
The text was updated successfully, but these errors were encountered: