diff --git a/src/ExponentialUtilities.jl b/src/ExponentialUtilities.jl index 1dd4919..0b79f55 100644 --- a/src/ExponentialUtilities.jl +++ b/src/ExponentialUtilities.jl @@ -27,6 +27,7 @@ include("exp.jl") include("exp_baseexp.jl") include("exp_noalloc.jl") include("exp_generic.jl") +include("exp_sparse.jl") include("phi.jl") include("arnoldi.jl") include("krylov_phiv.jl") diff --git a/src/exp.jl b/src/exp.jl index 9ad97b6..50a7f08 100644 --- a/src/exp.jl +++ b/src/exp.jl @@ -33,6 +33,7 @@ ExpMethodDiagonalization() = ExpMethodDiagonalization(true); Computes the matrix exponential with the method specified in `method`. The contents of `A` are modified, allowing for fewer allocations. The `method` parameter specifies the implementation and implementation parameters, e.g. [`ExpMethodNative`](@ref), [`ExpMethodDiagonalization`](@ref), [`ExpMethodGeneric`](@ref), [`ExpMethodHigham2005`](@ref). Memory needed can be preallocated and provided in the parameter `cache` such that the memory can be recycled when calling `exponential!` several times. The preallocation is done with the command [`alloc_mem`](@ref): `cache=alloc_mem(A,method)`. +`A` may not be sparse matrix type, since exp(A) is likely to be dense. Example diff --git a/src/exp_sparse.jl b/src/exp_sparse.jl new file mode 100644 index 0000000..3b771db --- /dev/null +++ b/src/exp_sparse.jl @@ -0,0 +1,9 @@ + +for expmeth in [ExpMethodDiagonalization, ExpMethodGeneric, ExpMethodHigham2005, ExpMethodHigham2005Base, ExpMethodNative] + @eval function exponential!(A::AbstractSparseArray, method::$expmeth, cache=nothing) + throw(ErrorException("exp(A) on a sparse matrix is generally dense. This operation is "* + "not allowed with exponential. If you wished to compute exp(At)*v, see expv. "* + "Otherwise to override this error, densify the matrix before calling, "* + "i.e. exponential!(Matrix(A))")) + end +end \ No newline at end of file diff --git a/test/basictests.jl b/test/basictests.jl index 6cb644e..08da3b7 100644 --- a/test/basictests.jl +++ b/test/basictests.jl @@ -99,7 +99,7 @@ end if VERSION >= v"1.9" @testset "exponential! sparse" begin A = sparse([1, 2, 1], [2, 1, 1], [1.0, 2.0, 3.0]) - exponential!(copy(A), ExpMethodGeneric()) ≈ exp(Array(A)) + @test_throws ErrorException exponential!(A) end end