-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
parametrize Diagonal on the wrapped vector type #22718
Conversation
Another idea, define something like abstract type AbstractDiagonal{T} <: AbstractMatrix{T} end
struct Diagonal{T} <: AbstractDiagonal{T}
diag::Vector{T}
end and relax methods in base to |
Actually, we have |
base/linalg/diagonal.jl
Outdated
1 ⋅ ⋅ | ||
⋅ 5 ⋅ | ||
⋅ ⋅ 9 | ||
``` | ||
""" | ||
|
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.
no blank between docstring and what it's documenting
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.
Woops, fixed.
da3c427
to
12b92f7
Compare
The thing with my alternative approach is that it is not enough to subtype Also, I searched through all registered packages, and this diff would fix the breakage part of this PR: diff --git a/src/LowRankMatrix.jl b/src/LowRankMatrix.jl
index 7989736..a59da0e 100644
--- a/src/LowRankMatrix.jl
+++ b/src/LowRankMatrix.jl
@@ -8,7 +8,7 @@ Store the singular value decomposition of a matrix:
"""
immutable LowRankMatrix{T} <: AbstractLowRankMatrix{T}
U::Matrix{T}
- Σ::Diagonal{T}
+ Σ::Diagonal{T,Vector{T}}
V::Matrix{T}
temp::Vector{T}
end Edit: And for |
not sure whether these are covered in benchmarks but let's see @nanosoldier |
Your benchmark job has completed - no performance regressions were detected. A full report can be found here. cc @jrevels |
test/linalg/diagonal.jl
Outdated
@@ -312,7 +312,7 @@ end | |||
end | |||
|
|||
# allow construct from range | |||
@test Diagonal(linspace(1,3,3)) == Diagonal([1.,2.,3.]) | |||
@test Diagonal(linspace(1,3,3)) ≈ Diagonal([1.,2.,3.]) |
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.
These should be elementwise equal - is this better expressed as all(Diagonal(linspace(1,3,3)) .== Diagonal([1.0,2.0,3.0]))
?
I must admit to being surprised that 1:2 == [1,2]
is false in the first place, as other AbstractVector
s are compared elementwise. I hunted this down to #5778 which seems to be a bit of a thorny issue.
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.
Will presumably be fixed by #16401? @nalimilan
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.
Right. As you say, that's a thorny issue... ;-) Until then, better use all
indeed.
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.
Updated.
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.
superficially lgtm! :)
Rebased. |
Rebased. |
Is this first use of triangular dispatch in base? Probably not... |
Because why not? Ref e.g. JuliaArrays/StaticArrays.jl#235
IIUC this could potentially be bad for people that now have
::Diagonal{T}
fields in user defined types though, since theses types will not be fully parametrized?If this is accepted, the same thing should probably be done with
Bidiagonal
and[Sym]Tridiagonal
.