-
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
Make LinearMap * I returns same LinearMap #57
Comments
A complication is that |
@JeffFessler That’s correct, which makes me think that @platawiec What exactly is your concern about the |
@dkarrasch The specific use-case is for optionally providing pre-conditioners to matrix-free operator representations of linear maps. For instance, IterativeSolvers.jl handles this by supplying a custom I suppose the larger point here is how abstractions (pre-conditioners for this particular use-case) and the interface exposed to the user interact with implementation details. I had the idea that it may be appropriate for LinearMaps to handle the "tidying up," as you called it. But I think it's also perfectly valid for "tidying" to lie outside the scope of LinearMaps. The only remaining concern I have is that, if "tidying" is not the concern of LinearMaps, then there may be repeated code in downstream packages, trying to handle the tidying on their own. |
I would like to avoid copyto! anywhere possible. Maybe there's a different way to avoid that, like using the generic 5-arg mul! perhaps? #56 |
I was curious what other objects do with |
Well, as expected, if I introduce function Base.:(*)(A1::LinearMap, A2::UniformScaling{Bool})
if A2.λ
return A1
else
return A1 * A2.λ # this could be further reduced to a new ZeroMap type
end
end (and similarly the other one) that product becomes type-unstable. The inferred type, however, is a julia> @inferred A*I
ERROR: return type LinearMaps.WrappedMap{Float64,Array{Float64,2}} does not match i
nferred return type Union{LinearMaps.CompositeMap{Float64,Tuple{LinearMaps.UniformS
calingMap{Bool},LinearMaps.WrappedMap{Float64,Array{Float64,2}}}}, LinearMaps.Wrapp
edMap{Float64,Array{Float64,2}}} This may be not too bad, actually; at least, AFAIU, Julia is able to handle type instabilities with small type unions. @Jutho any opinion on that matter? Anyway, I'm not sure we would want to iterate over longer |
what about the more general case of, say,
|
I've been thinking about it. The issue is that this introduces type instability. If we restrict this to only |
Just FYI, you can use |
@platawiec fyi I have added the "simply return A" feature to https://github.com/JeffFessler/LinearMapsAA.jl |
I've been thinking and working on that issue here now for a while. It seems to me, that this is probably not an issue with Given that
Now, in some linalg function, you could have
where you could then even do dispatch on the type of Generally, I came to appreciate the purity of how this package was designed by @Jutho. As an example, you can have a real matrix, but wrap it in a Sorry for the long text, but I suffered quite some pain while trying and failing, just to realize that I finally agree with my initial gut feeling. PS: Looking at some of the earlier comments, there was concern that we "create |
Currently,
*(A::LinearMap, I::UniformScaling{Bool})::CompositeMap
That is, a new map is constructed. Could we simply return
A
in this case (and related cases involving multiplication/division by the identity?)The text was updated successfully, but these errors were encountered: