-
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 A*I return A #63
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should
@test LA * I == LA == I * LA
perhaps be
@test LA * I === LA === I * LA
at line 416?
otherwise looks good to me.
I don't have enough understanding of type instability to really know the impact, but my hope would be the effect would be small because I imagine the typical use case is something like |
This is exactly the issue that I worry about: at compilation time, the code will not know of which type |
Codecov Report
@@ Coverage Diff @@
## master #63 +/- ##
=========================================
- Coverage 98.62% 92.52% -6.1%
=========================================
Files 8 8
Lines 435 468 +33
=========================================
+ Hits 429 433 +4
- Misses 6 35 +29
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #63 +/- ##
==========================================
+ Coverage 98.62% 98.83% +0.21%
==========================================
Files 8 8
Lines 435 430 -5
==========================================
- Hits 429 425 -4
+ Misses 6 5 -1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was curious about the multiplication with ZeroMap using
zero(promote_type(eltype(A), eltype(x)), ...)
instead of just the simpler zero(eltype(x),
but i suppose it is consistent with how an actual matrix of zeros would work in multiplication.
@@ -37,6 +37,18 @@ function Base.:(+)(A₁::LinearMap, A₂::LinearMap) | |||
return LinearCombination{T}(tuple(A₁, A₂)) | |||
end | |||
Base.:(-)(A₁::LinearMap, A₂::LinearMap) = +(A₁, -A₂) | |||
function Base.:(+)(O::ZeroMap, A::LinearMap) | |||
size(O) == size(A) || throw(DimensionMismatch("+")) | |||
T = promote_type(eltype(O), eltype(A)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the point of computing T
if then anyway A
is returned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. This situation here is supposed to occur when the ZeroMap
was created out of a CompositeMap
that had a ZeroMap
factor. So that map does have its own eltype, which probably should not get lost here. So I guess what should be returned is actually LinearMap{T}(A)
. At least that's what I meant to do originally, but then forgot about it in the next line.
Base.:(+)(A::LinearMap, O::ZeroMap) = +(O, A) | ||
function Base.:(+)(O₁::ZeroMap, O₂::ZeroMap) | ||
size(O₁) == size(O₂) || throw(DimensionMismatch("+")) | ||
T = promote_type(eltype(O₁), eltype(O₂)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
I am not too fond of the type instability. Another way to resolve this, is to special case the multiplication rule of Yet another solution is to have a |
@Jutho Feel free to close this. I agree that we should avoid type instabilities. I think I did what you suggest here
in #69. The first draft is probably a bit hacky, but it works and avoids the issues here. I think it's generally the way to go, so to address algebraic tricks/reductions (which depend on cheap checks on scalars or sizes) in the multiplication functions, rather than on the constructor/type level. I have done something similar now in the Kronecker PR #61. |
Related to #57.