Open mcarmesin opened 1 week ago
I'm not 100% sure what the behavior you'd want here is. The matrix exponential of a sparse matrix is dense unless the matrix is diagonal. Diagonal GPU matrices would use Diagonal{CuArray}
, so that wouldn't be this type. Which means that the result here is almost certainly dense. Should this just dispatch to exp(CuArray(A))
? It seems having the user actually have to request that isn't the worst thing as a somewhat safety measure, since generally asking for a densifying operation on a sparse matrix is a bad idea.
What the user would almost certainly want to do instead here is exp(At)*v
operations, which can be done sparsely. My understanding is that as long as A*v
is supported in the array type, which it is here, then it should just work. So then erroring and having people use expv
and phiv
is the better option.
I agree that densifying would be not a good solution for various reasons. Probably it would be best, to have exponential!() undefined for sparse matrices, like the base exp!(). Btw. exponential!() is also broken for SparseMatrixCSC():
ERROR: pointer_from_objref cannot be used on immutable objects
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] pointer_from_objref
@ ./pointer.jl:269 [inlined]
[3] ldiv_for_generated!(C::SparseMatrixCSC{…}, A::SparseMatrixCSC{…}, B::SparseMatrixCSC{…})
@ ExponentialUtilities ~/.julia/packages/ExponentialUtilities/xLH9y/src/exp_noalloc.jl:32
[4] exp_gen!(cache::Vector{SparseMatrixCSC{Float64, Int64}}, A::SparseMatrixCSC{Float64, Int64}, ::Val{4})
@ ExponentialUtilities ~/.julia/packages/ExponentialUtilities/xLH9y/src/exp_generated/exp_4.jl:63
[5] exponential!(A::SparseMatrixCSC{Float64, Int64}, method::ExpMethodHigham2005, _cache::Tuple{Vector{…}, SparseVector{…}})
@ ExponentialUtilities ~/.julia/packages/ExponentialUtilities/xLH9y/src/exp_noalloc.jl:101
[6] exponential!(A::SparseMatrixCSC{Float64, Int64}, method::ExpMethodHigham2005)
@ ExponentialUtilities ~/.julia/packages/ExponentialUtilities/xLH9y/src/exp_noalloc.jl:83
[7] exponential!(A::SparseMatrixCSC{Float64, Int64})
@ ExponentialUtilities ~/.julia/packages/ExponentialUtilities/xLH9y/src/exp.jl:15
[8] top-level scope
@ ~/CN/test_cu_sparse_exponentiation.jl:10
Btw. exponential!() is also broken for SparseMatrixCSC():
Yeah we should probably just throw an error on <: AbstractSparseMatrix
saying
exp(A)
on a sparse matrix is generally dense. This operation is not allowed withexponential
. If you wished to computeexp(At)*v
, seeexpv
. Otherwise to override this error, densify the matrix before calling, i.e.exponential(Matrix(A))
Describe the bug 🐞
Calculating the matrix exponential of a CUDA sparse matrix fails with trowing the exception ArgumentError: Attempt to use a freed reference. or Error: Scalar Indexing is disallowed when selecting
ExpMethodGeneric()
Expected behavior
Calculation of the matrix exponential like
exp(A)
Minimal Reproducible Example 👇
Error & Stacktrace ⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()