Skip to content

Commit

Permalink
Merge pull request #182 from mcarmesin/master
Browse files Browse the repository at this point in the history
Disallow exponential!() for sparse matrices
  • Loading branch information
ChrisRackauckas authored Nov 16, 2024
2 parents ec8588d + 230e046 commit 1ad3203
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ExponentialUtilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions src/exp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/exp_sparse.jl
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/basictests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1ad3203

Please sign in to comment.