diff --git a/Project.toml b/Project.toml index e05fbafe..ac7eccf8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "QuantumOpticsBase" uuid = "4f57444f-1401-5e15-980d-4471b28d5678" -version = "0.4.3" +version = "0.4.4" [deps] Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" diff --git a/src/operators_dense.jl b/src/operators_dense.jl index d1e9a23b..df9ed6e9 100644 --- a/src/operators_dense.jl +++ b/src/operators_dense.jl @@ -32,6 +32,13 @@ Base.eltype(op::Operator) = eltype(op.data) Base.eltype(::Type{T}) where {BL,BR,D,T<:Operator{BL,BR,D}} = eltype(D) Base.size(op::Operator) = size(op.data) Base.size(op::Operator, d::Int) = size(op.data, d) +function Base.convert(::Type{Operator{BL,BR,T}}, op::Operator{BL,BR,S}) where {BL,BR,T,S} + if T==S + return op + else + return Operator{BL,BR,T}(op.basis_l, op.basis_r, convert(T, op.data)) + end +end # Convert data to CuArray with cu(::Operator) Adapt.adapt_structure(to, x::Operator) = Operator(x.basis_l, x.basis_r, Adapt.adapt(to, x.data)) diff --git a/test/test_operators.jl b/test/test_operators.jl index bd20b4b4..03689925 100644 --- a/test/test_operators.jl +++ b/test/test_operators.jl @@ -140,4 +140,9 @@ Lop1 = LazyTensor(b1^2, b2^2, 2, sparse(randoperator(b1, b2))) @test_throws ErrorException size(dense(Lop1), 0) # check for consistency @test_throws ErrorException size(dense(Lop1), -1) +# issue 106 | https://github.com/qojulia/QuantumOpticsBase.jl/issues/106 +a = destroy(FockBasis(5)) +@test dagger(a^2) == dagger(a)^2 +@test convert(Base._return_type(*, Tuple{typeof(a'), typeof(a')}), a') == a' + end # testset