-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
diagm and spdiagm #457
Comments
Requiring |
Yea, I know and agree that it is suboptimal, but it would be nice to get rid of the |
If this is being redesigned, could JuliaArrays/OffsetArrays.jl#25 be taken into account? |
Would |
I'm in favor of those last three deprecations in the issue description, as that would allow us to not have to think about what the indices for OffsetArrays.jl could then choose to have cc: @timholy |
@fredrikekre, |
It is unsatisfying to have the |
Alternative suggestions welcome. |
My suggestion is to keep spdiagm |
Here is another inconsistency: julia> diagm(rand(3), 4)
7×7 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.519002 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.812178 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.64331
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.0
julia> full(spdiagm(rand(3), 4))
3×7 Array{Float64,2}:
0.0 0.0 0.0 0.0 0.696544 0.0 0.0
0.0 0.0 0.0 0.0 0.0 0.100363 0.0
0.0 0.0 0.0 0.0 0.0 0.0 0.979094 Which behavior do we want here? |
Imo the first one. |
From searching a bit it seems that the option to supply the resulting size for |
I think we are done here -- now we have |
Good job! |
Current state of affairs
There is currently a lot of inconsistencies between
diagm
andspdiagm
. Some methods ofdiagm
and its behavior:diagm(v::AbstractVector, k)
: place vectorv
on thek
th diagonaldiagm(v::SparseMatrixCSC)
: NoteSparseMatrixCSC
, notSparseVector
, and it has to be of size(n,1)
or(1,n)
. This places places the entries on the0
th diagonal (no choice).diagm(v::BitMatrix)
: Same thing here, matrix of size(n,1)
or(1,n)
and no choice of placement.spdiagm
is a bit more flexible: we can supply multiple vectors for multiple diagonals, e.g.spdiagm((v1, v2), (k1,k2))
places vectorv1
andv2
on diagonalk1
andk2
respectively. We can also specify the resulting matrix size, e.g.spdiagm((v1, v2), (k1,k2), m, n)
which will create am×n
matrix. Is this actually useful? Looking at the code, it seems like its there to kind of mirror thesparse(I,J,V)
/sparse(I,J,V,m,n)
methods.Action plan
The most obvious things are:
diagm(A::SparseMatrixCSC)
in favor ofspdiagm(sparsevec(A))
(#23341)diagm(A::BitMatrix)
in favor ofdiagm(vec(A))
(#23373)Change to nicer
Pair
API instead of thediagm(tuple_of_vecs, tuple_of_diags)
methods.spdiagm(tuple_of_vecs, tuple_of_diags)
in favor ofspdiagm(p::Pair{<:Integer,<:AbstractVector}...)
(#23757)diagm(p::Pair{<:Integer,<:AbstractVector}...)
to match the spdiagm method. (#24047)Then some other things:
spdiagm
and always return a square matrix likediagm
. (#23757)So when we are here, we have
diagm
andspdiagm
that match each other. Where could we go from here? We deletespdiagm
! 🎉spdiagm(vecs, diags)
in favor ofdiagm(sparsevec.(vecs), diags)
So now we only have
diagm
. Lets delete that too?diagm(v::AbstractVector)
in favor ofMatrix(Diagonal(v))
diagm(v::SparseVector)
in favor ofsparse(Diagonal(v))
diagm(v::BitVector)
in favor ofBitMatrix(Diagonal(v))
The only problem with this is that we can't really specify diagonals easily anymore, and lose the option to supply more than one vector. So perhaps this last step was just too much.
The text was updated successfully, but these errors were encountered: