Skip to content
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

Disallow exponential!() for sparse matrices #182

Merged
merged 4 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading