-
Notifications
You must be signed in to change notification settings - Fork 42
Allow vectors for LinearMap storage #171
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #171 +/- ##
==========================================
+ Coverage 99.63% 99.64% +0.01%
==========================================
Files 14 14
Lines 1089 1130 +41
==========================================
+ Hits 1085 1126 +41
Misses 4 4
Continue to review full report at Codecov.
|
Thanks a lot for this, @dkarrasch! Would you consider adding a specialization Base.sum(maps::LinearMapTupleOrVector) = LinearCombination(...) to this PR? It would be very helpful for our current use case in MGVI.jl. |
That already works via the |
It does, and we're using it, but it results in a tuple-backed Specializing sum would result in an sum of an array of linear maps being turned into an array-backed |
Now I got it. Then how about making |
Sounds good! Actually, instead of specializing Base.mapreduce(::typeof(identity), ::typeof(Base.add_sum), ::AbstractVector{<:LinearMap}) = LinearCombination(...)
I'm not quite sure I got that - doesn't the vector |
Ah, sorry, it's about |
So, do you think you'll need an overload of |
Having |
Saw your commits regarding |
Again, thanks a lot for this @dkarrasch ! Will this be v3.5.2 or v v3.6.0? |
You're very welcome! This is a new feature, so this will be v3.6. If you can share some showcase/benchmark for this feature, please leave a link here. I'd be curious to see what difference this makes in real-world usage. |
These maps can also be constructed using Base.prod, which leads to an indexing problem if the number of maps is one. using LinearMaps
m = LinearMap(cumsum,3)
typeof(m*m) #Tuple type
typeof(prod([m,m])) #Vector type
typeof(prod([m])) #Vector type, and leads to an indexing problem:
prod([m])*ones(3) #ERROR: BoundsError: attempt to access 1-element Vector{LinearMaps.FunctionMap{Float64, typeof(cumsum), Nothing}} at index [2] The error originates from here: LinearMaps.jl/src/composition.jl Lines 207 to 211 in f8eaf98
|
This extends the
maps
fied of higher-orderLinearMap
s to be a vector, rather than only a tuple. It does not change default behavior. To construct such maps, one would need to call non-exported constructors directly ("expert use").Closes #169. @oschulz