Inference check for `exp`
Closed this issue · 0 comments
ytdHuang commented
The matrix exponential has type inference issue.
using Test, QuantumToolbox
@inferred exp(-1.0im * sigmax())
ERROR message:
return type
QuantumObject{SparseMatrixCSC{ComplexF64, Int64}, OperatorQuantumObject}
does not match inferred return type
Union{QuantumObject{Diagonal{ComplexF64, Vector{ComplexF64}}, OperatorQuantumObject}, QuantumObject{SparseMatrixCSC{ComplexF64, Int64}, OperatorQuantumObject}}
I believe this issue originates from this line: https://github.com/qutip/QuantumToolbox.jl/blob/main/src/qobj/arithmetic_and_attributes.jl#L400
If the input operator is an "empty" sparse matrix, the returned identity operator is in the type of Diagonal
matrix.
We should convert it to SparseMatrixCSC
in the inner function _spexp
.