-
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
Support for arrays in addition to tuples in LinearCombination #169
Comments
I'm glad to hear LinearMaps.jl is used. @jagot took a similar approach in #84, but then didn't finish because it didn't do the job he needed, but you may find some inspiration there. On the other hand, using LinearMaps, Statistics
A = LinearMap(rand(3,3))
B = A + A + A
julia> mean(B.maps)
3×3 LinearMaps.ScaledMap{Float64} with scale: 0.3333333333333333 of
3×3 LinearMaps.LinearCombination{Float64} with 3 maps:
3×3 LinearMaps.WrappedMap{Float64} of
3×3 Matrix{Float64}
3×3 LinearMaps.ScaledMap{Float64} with scale: 1.0 of
3×3 LinearMaps.WrappedMap{Float64} of
3×3 Matrix{Float64}
3×3 LinearMaps.WrappedMap{Float64} of
3×3 Matrix{Float64} The fact that the maps form a tuple shouldn't be a big restriction, because these tuples are all lazy, i.e., adding another map to an existing Statistics.mean(A::LinearCombination) = mean(A.maps) which would add another dependency just for the sake of this one method, but that's not too bad. Oh, but wait, what would change if the |
Yes, the problem is the load on the compiler, with new data types created all the time for tuples of different length (and n can be hundreds of even thousands in our use case). Mean itself works fine indeed already.
Yes, forgot to mention, I would like to specialize Just wanted to check with you before preparing a PR. |
It's awesome! We found it to be a very powerful abstraction. We use it for lazy Jacobians too, with both left- and right-multiplication (backed by ForwardDiff and Zygote, by default). |
Before you start with your own PR, check out #84. It does a few more things (to block concatenation), but it already has the |
Thanks, will do! Should I just base a PR on top of #84? |
That was just a suggestion for a quick start. It's not important which way you go. #84 has more things that we might keep for when there is actual interest in it. |
Ok, I'll start with |
We use LinearMaps extensively in MGVI.jl. We're adding support for Newton-CG-optimization now which needs means of linear maps. The number of maps in the mean/sum is not fixed though, so we'd like to use an array of maps instead of a tuple in
LinearCombination
. Would a pull request to extendLinearCombination
that way be welcome?The text was updated successfully, but these errors were encountered: