Skip to content

Commit

Permalink
fix type instabilities for exp
Browse files Browse the repository at this point in the history
  • Loading branch information
ytdHuang committed Aug 19, 2024
1 parent 5499a17 commit 9b3c9bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/qobj/arithmetic_and_attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ function _spexp(A::SparseMatrixCSC{T,M}; threshold = 1e-14, nonzero_tol = 1e-20)
m = checksquare(A) # Throws exception if not square

mat_norm = norm(A, Inf)
mat_norm == 0 && return eye(m).data
mat_norm == 0 && return sparse(T(1) * I, m, m)
scaling_factor = nextpow(2, mat_norm) # Native routine, faster
A = A ./ scaling_factor
delta = 1
Expand Down
11 changes: 11 additions & 0 deletions test/quantum_objects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,17 @@
@test logm(expm(Ms)) expm(logm(Md))
@test cosm(Ms) (e_p + e_m) / 2
@test sinm(Ms) (e_p - e_m) / 2im

@testset "Type Inference" begin
@inferred expm(Md)
@inferred expm(Ms)
@inferred logm(Md)
@inferred logm(Ms)
@inferred sinm(Md)
@inferred sinm(Ms)
@inferred cosm(Md)
@inferred cosm(Ms)
end
end

@testset "tidyup" begin
Expand Down

0 comments on commit 9b3c9bd

Please sign in to comment.