I am trying to perform svd
on the identity matrix I
but it seems like whatever the type of I
is, it's raising an error?
ii = svd(I(3))
error:
MethodError: no method matching LinearAlgebra.SVD(::SparseArrays.SparseMatrixCSC{Float64, Int64}, ::BitVector, ::SparseArrays.SparseMatrixCSC{Bool, Int64})
Closest candidates are:
LinearAlgebra.SVD(::AbstractArray{T, N} where N, !Matched::Vector{Tr}, !Matched::AbstractArray{T, N} where N) where {T, Tr} at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.6/LinearAlgebra/src/svd.jl:68
svd(::LinearAlgebra.Diagonal{Bool, Vector{Bool}})@diagonal.jl:690
top-level scope@Local: 1[inlined]
Am I correct in this? If so, that seems odd that this isn't available out of the box
The problem is that I
doesn't have a size, it is a generic representation. If you type I(3)
you get the 3x3 sparse identity. And then an error message will be thrown saying that for sparse matrices you could use Arpack.jl
Oh I meant to put I(3)
so I just edited the message above. But that's weird those aren't compatible. How does Arpack.jl fix this?
Oh wait it looks like it has it's own version of svds
. I will give that a try
Could do svd(collect(I(3)))
julia> ii = svd(I(3) |> collect)
SVD{Float64, Float64, Matrix{Float64}}
U factor:
3×3 Matrix{Float64}:
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
singular values:
3-element Vector{Float64}:
1.0
1.0
1.0
Vt factor:
3×3 Matrix{Float64}:
1.0 0.0 0.0
0.0 1.0 0.0
0.0 0.0 1.0
Alternatively, Matrix(I(3))
:smile:
Thank you, both of those are super easy solutions
svd(1.0I(3))
also works
Oh interesting that works!
Last updated: Nov 22 2024 at 04:41 UTC