3737for op in (:(+ ), :(- ), :(* ))
3838 @eval begin
3939 function LinearAlgebra. $op (A:: AbstractQuantumObject , B:: AbstractQuantumObject )
40- A. dims != B. dims &&
41- throw (DimensionMismatch (" The two quantum object don't have the same Hilbert dimension." ))
40+ check_dims (A, B)
4241 if A isa QuantumObjectEvolution || B isa QuantumObjectEvolution
4342 return QuantumObjectEvolution ($ (op)(A. data, B. data), A. type, A. dims)
4443 end
@@ -57,56 +56,56 @@ function LinearAlgebra.:(*)(
5756 A:: AbstractQuantumObject{DT1,OperatorQuantumObject} ,
5857 B:: QuantumObject{DT2,KetQuantumObject} ,
5958) where {DT1,DT2}
60- A . dims != B . dims && throw ( DimensionMismatch ( " The two quantum object don't have the same Hilbert dimension. " ) )
59+ check_dims (A, B )
6160 return QuantumObject (A. data * B. data, Ket, A. dims)
6261end
6362function LinearAlgebra.:(* )(
6463 A:: QuantumObject{DT1,BraQuantumObject} ,
6564 B:: AbstractQuantumObject{DT2,OperatorQuantumObject} ,
6665) where {DT1,DT2}
67- A . dims != B . dims && throw ( DimensionMismatch ( " The two quantum object don't have the same Hilbert dimension. " ) )
66+ check_dims (A, B )
6867 return QuantumObject (A. data * B. data, Bra, A. dims)
6968end
7069function LinearAlgebra.:(* )(
7170 A:: QuantumObject{DT1,KetQuantumObject} ,
7271 B:: QuantumObject{DT2,BraQuantumObject} ,
7372) where {DT1,DT2}
74- A . dims != B . dims && throw ( DimensionMismatch ( " The two quantum object don't have the same Hilbert dimension. " ) )
73+ check_dims (A, B )
7574 return QuantumObject (A. data * B. data, Operator, A. dims)
7675end
7776function LinearAlgebra.:(* )(
7877 A:: QuantumObject{DT1,BraQuantumObject} ,
7978 B:: QuantumObject{DT2,KetQuantumObject} ,
8079) where {DT1,DT2}
81- A . dims != B . dims && throw ( DimensionMismatch ( " The two quantum object don't have the same Hilbert dimension. " ) )
80+ check_dims (A, B )
8281 return A. data * B. data
8382end
8483function LinearAlgebra.:(* )(
8584 A:: AbstractQuantumObject{DT1,SuperOperatorQuantumObject} ,
8685 B:: QuantumObject{DT2,OperatorQuantumObject} ,
8786) where {DT1,DT2}
88- A . dims != B . dims && throw ( DimensionMismatch ( " The two quantum object don't have the same Hilbert dimension. " ) )
87+ check_dims (A, B )
8988 return QuantumObject (vec2mat (A. data * mat2vec (B. data)), Operator, A. dims)
9089end
9190function LinearAlgebra.:(* )(
9291 A:: QuantumObject{DT1,OperatorBraQuantumObject} ,
9392 B:: QuantumObject{DT2,OperatorKetQuantumObject} ,
9493) where {DT1,DT2}
95- A . dims != B . dims && throw ( DimensionMismatch ( " The two quantum object don't have the same Hilbert dimension. " ) )
94+ check_dims (A, B )
9695 return A. data * B. data
9796end
9897function LinearAlgebra.:(* )(
9998 A:: AbstractQuantumObject{DT1,SuperOperatorQuantumObject} ,
10099 B:: QuantumObject{DT2,OperatorKetQuantumObject} ,
101100) where {DT1,DT2}
102- A . dims != B . dims && throw ( DimensionMismatch ( " The two quantum object don't have the same Hilbert dimension. " ) )
101+ check_dims (A, B )
103102 return QuantumObject (A. data * B. data, OperatorKet, A. dims)
104103end
105104function LinearAlgebra.:(* )(
106105 A:: QuantumObject{<:AbstractArray{T1},OperatorBraQuantumObject} ,
107106 B:: AbstractQuantumObject{<:AbstractArray{T2},SuperOperatorQuantumObject} ,
108107) where {T1,T2}
109- A . dims != B . dims && throw ( DimensionMismatch ( " The two quantum object don't have the same Hilbert dimension. " ) )
108+ check_dims (A, B )
110109 return QuantumObject (A. data * B. data, OperatorBra, A. dims)
111110end
112111
@@ -445,8 +444,8 @@ Matrix cosine of [`QuantumObject`](@ref), defined as
445444Note that this function only supports for [`Operator`](@ref) and [`SuperOperator`](@ref)
446445"""
447446LinearAlgebra. cos (
448- A:: QuantumObject{<:AbstractMatrix{T} ,ObjType} ,
449- ) where {T ,ObjType<: Union{OperatorQuantumObject,SuperOperatorQuantumObject} } = (exp (1im * A) + exp (- 1im * A)) / 2
447+ A:: QuantumObject{DT ,ObjType} ,
448+ ) where {DT ,ObjType<: Union{OperatorQuantumObject,SuperOperatorQuantumObject} } = (exp (1im * A) + exp (- 1im * A)) / 2
450449
451450@doc raw """
452451 diag(A::QuantumObject, k::Int=0)
0 commit comments