qutip / QuantumToolbox.jl

Quantum Toolbox in Julia
https://qutip.org/QuantumToolbox.jl/
BSD 3-Clause "New" or "Revised" License
46 stars 16 forks source link

Type instabilities when generating a `QuantumObject` #177

Closed albertomercurio closed 4 months ago

albertomercurio commented 4 months ago

The simple code below fails when running the type-inference test

using Test
using QuantumToolbox

A = sprand(ComplexF64, 100, 100, 0.1)

@inferred QuantumObject(A)
return type QuantumObject{SparseMatrixCSC{ComplexF64, Int64}, OperatorQuantumObject} does not match inferred return type Union{QuantumObject{SparseMatrixCSC{ComplexF64, Int64}, BraQuantumObject}, QuantumObject{SparseMatrixCSC{ComplexF64, Int64}, KetQuantumObject}, QuantumObject{SparseMatrixCSC{ComplexF64, Int64}, OperatorQuantumObject}}

I think that we should fix it using multiple dispatch when calling it.