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

fix type instabilities for exp #206

Merged
merged 1 commit into from
Aug 20, 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
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