@@ -138,10 +138,7 @@ Note that `A` and `B` should be [`Ket`](@ref) or [`OperatorKet`](@ref)
138138!!! note
139139 `A ⋅ B` (where `⋅` can be typed by tab-completing `\c dot` in the REPL) is a synonym of `dot(A, B)`.
140140"""
141- function LinearAlgebra. dot (
142- A:: QuantumObject{OpType} ,
143- B:: QuantumObject{OpType} ,
144- ) where {OpType<: Union{Ket,OperatorKet} }
141+ function LinearAlgebra. dot (A:: QuantumObject{OpType} , B:: QuantumObject{OpType} ) where {OpType<: Union{Ket,OperatorKet} }
145142 check_dimensions (A, B)
146143 return LinearAlgebra. dot (A. data, B. data)
147144end
@@ -159,11 +156,7 @@ Supports the following inputs:
159156!!! note
160157 `matrix_element(i, A, j)` is a synonym of `dot(i, A, j)`.
161158"""
162- function LinearAlgebra. dot (
163- i:: QuantumObject{Ket} ,
164- A:: AbstractQuantumObject{Operator} ,
165- j:: QuantumObject{Ket} ,
166- )
159+ function LinearAlgebra. dot (i:: QuantumObject{Ket} , A:: AbstractQuantumObject{Operator} , j:: QuantumObject{Ket} )
167160 check_dimensions (i, A, j)
168161 return LinearAlgebra. dot (i. data, A. data, j. data)
169162end
@@ -205,9 +198,7 @@ Base.conj(A::AbstractQuantumObject) = get_typename_wrapper(A)(conj(A.data), A.ty
205198
206199Lazy matrix transpose of the [`AbstractQuantumObject`](@ref).
207200"""
208- Base. transpose (
209- A:: AbstractQuantumObject{OpType} ,
210- ) where {OpType<: Union{Operator,SuperOperator} } =
201+ Base. transpose (A:: AbstractQuantumObject{OpType} ) where {OpType<: Union{Operator,SuperOperator} } =
211202 get_typename_wrapper (A)(transpose (A. data), A. type, transpose (A. dimensions))
212203
213204@doc raw """
@@ -224,25 +215,18 @@ Base.adjoint(A::AbstractQuantumObject{OpType}) where {OpType<:Union{Operator,Sup
224215 get_typename_wrapper (A)(adjoint (A. data), A. type, adjoint (A. dimensions))
225216Base. adjoint (A:: QuantumObject{Ket} ) = QuantumObject (adjoint (A. data), Bra, adjoint (A. dimensions))
226217Base. adjoint (A:: QuantumObject{Bra} ) = QuantumObject (adjoint (A. data), Ket, adjoint (A. dimensions))
227- Base. adjoint (A:: QuantumObject{OperatorKet} ) =
228- QuantumObject (adjoint (A. data), OperatorBra, adjoint (A. dimensions))
229- Base. adjoint (A:: QuantumObject{OperatorBra} ) =
230- QuantumObject (adjoint (A. data), OperatorKet, adjoint (A. dimensions))
218+ Base. adjoint (A:: QuantumObject{OperatorKet} ) = QuantumObject (adjoint (A. data), OperatorBra, adjoint (A. dimensions))
219+ Base. adjoint (A:: QuantumObject{OperatorBra} ) = QuantumObject (adjoint (A. data), OperatorKet, adjoint (A. dimensions))
231220
232221@doc raw """
233222 inv(A::AbstractQuantumObject)
234223
235224Matrix inverse of the [`AbstractQuantumObject`](@ref). If `A` is a [`QuantumObjectEvolution`](@ref), the inverse is computed at the last computed time.
236225"""
237- LinearAlgebra. inv (
238- A:: AbstractQuantumObject{OpType} ,
239- ) where {OpType<: Union{Operator,SuperOperator} } =
226+ LinearAlgebra. inv (A:: AbstractQuantumObject{OpType} ) where {OpType<: Union{Operator,SuperOperator} } =
240227 QuantumObject (sparse (inv (Matrix (A. data))), A. type, A. dimensions)
241228
242- LinearAlgebra. Hermitian (
243- A:: QuantumObject{OpType} ,
244- uplo:: Symbol = :U ,
245- ) where {OpType<: Union{Operator,SuperOperator} } =
229+ LinearAlgebra. Hermitian (A:: QuantumObject{OpType} , uplo:: Symbol = :U ) where {OpType<: Union{Operator,SuperOperator} } =
246230 QuantumObject (Hermitian (A. data, uplo), A. type, A. dimensions)
247231
248232@doc raw """
@@ -269,8 +253,7 @@ julia> tr(a' * a)
269253190.0 + 0.0im
270254```
271255"""
272- LinearAlgebra. tr (A:: QuantumObject{OpType} ) where {OpType<: Union{Operator,SuperOperator} } =
273- tr (A. data)
256+ LinearAlgebra. tr (A:: QuantumObject{OpType} ) where {OpType<: Union{Operator,SuperOperator} } = tr (A. data)
274257LinearAlgebra. tr (
275258 A:: QuantumObject{OpType,DimsType,<:Union{<:Hermitian{TF},Symmetric{TR}}} ,
276259) where {OpType<: Operator ,DimsType,TF<: BlasFloat ,TR<: Real } = real (tr (A. data))
@@ -312,15 +295,9 @@ julia> norm(ψ)
3122951.0
313296```
314297"""
315- LinearAlgebra. norm (
316- A:: QuantumObject{OpType} ,
317- p:: Real = 2 ,
318- ) where {OpType<: Union{Ket,Bra,OperatorKet,OperatorBra} } =
298+ LinearAlgebra. norm (A:: QuantumObject{OpType} , p:: Real = 2 ) where {OpType<: Union{Ket,Bra,OperatorKet,OperatorBra} } =
319299 norm (A. data, p)
320- function LinearAlgebra. norm (
321- A:: QuantumObject{OpType} ,
322- p:: Real = 1 ,
323- ) where {OpType<: Union{Operator,SuperOperator} }
300+ function LinearAlgebra. norm (A:: QuantumObject{OpType} , p:: Real = 1 ) where {OpType<: Union{Operator,SuperOperator} }
324301 p == 2.0 && return norm (A. data, 2 )
325302 return norm (svdvals (A), p)
326303end
@@ -340,10 +317,8 @@ Support for the following types of [`QuantumObject`](@ref):
340317
341318Also, see [`norm`](@ref) about its definition for different types of [`QuantumObject`](@ref).
342319"""
343- LinearAlgebra. normalize (
344- A:: QuantumObject{ObjType} ,
345- p:: Real = 2 ,
346- ) where {ObjType<: Union{Ket,Bra} } = QuantumObject (A. data / norm (A, p), A. type, A. dimensions)
320+ LinearAlgebra. normalize (A:: QuantumObject{ObjType} , p:: Real = 2 ) where {ObjType<: Union{Ket,Bra} } =
321+ QuantumObject (A. data / norm (A, p), A. type, A. dimensions)
347322LinearAlgebra. normalize (A:: QuantumObject{Operator} , p:: Real = 1 ) =
348323 QuantumObject (A. data / norm (A, p), A. type, A. dimensions)
349324
@@ -358,29 +333,17 @@ Support for the following types of [`QuantumObject`](@ref):
358333
359334Also, see [`norm`](@ref) about its definition for different types of [`QuantumObject`](@ref).
360335"""
361- LinearAlgebra. normalize! (
362- A:: QuantumObject{ObjType} ,
363- p:: Real = 2 ,
364- ) where {ObjType<: Union{Ket,Bra} } = (rmul! (A. data, 1 / norm (A, p)); A)
336+ LinearAlgebra. normalize! (A:: QuantumObject{ObjType} , p:: Real = 2 ) where {ObjType<: Union{Ket,Bra} } =
337+ (rmul! (A. data, 1 / norm (A, p)); A)
365338LinearAlgebra. normalize! (A:: QuantumObject{Operator} , p:: Real = 1 ) = (rmul! (A. data, 1 / norm (A, p)); A)
366339
367- LinearAlgebra. triu! (
368- A:: QuantumObject{OpType} ,
369- k:: Integer = 0 ,
370- ) where {OpType<: Union{Operator,SuperOperator} } = (triu! (A. data, k); A)
371- LinearAlgebra. tril! (
372- A:: QuantumObject{OpType} ,
373- k:: Integer = 0 ,
374- ) where {OpType<: Union{Operator,SuperOperator} } = (tril! (A. data, k); A)
375- LinearAlgebra. triu (
376- A:: QuantumObject{OpType} ,
377- k:: Integer = 0 ,
378- ) where {OpType<: Union{Operator,SuperOperator} } =
340+ LinearAlgebra. triu! (A:: QuantumObject{OpType} , k:: Integer = 0 ) where {OpType<: Union{Operator,SuperOperator} } =
341+ (triu! (A. data, k); A)
342+ LinearAlgebra. tril! (A:: QuantumObject{OpType} , k:: Integer = 0 ) where {OpType<: Union{Operator,SuperOperator} } =
343+ (tril! (A. data, k); A)
344+ LinearAlgebra. triu (A:: QuantumObject{OpType} , k:: Integer = 0 ) where {OpType<: Union{Operator,SuperOperator} } =
379345 QuantumObject (triu (A. data, k), A. type, A. dimensions)
380- LinearAlgebra. tril (
381- A:: QuantumObject{OpType} ,
382- k:: Integer = 0 ,
383- ) where {OpType<: Union{Operator,SuperOperator} } =
346+ LinearAlgebra. tril (A:: QuantumObject{OpType} , k:: Integer = 0 ) where {OpType<: Union{Operator,SuperOperator} } =
384347 QuantumObject (tril (A. data, k), A. type, A. dimensions)
385348
386349LinearAlgebra. lmul! (a:: Number , B:: QuantumObject ) = (lmul! (a, B. data); B)
@@ -416,14 +379,11 @@ Matrix exponential of [`QuantumObject`](@ref)
416379
417380Note that this function only supports for [`Operator`](@ref) and [`SuperOperator`](@ref)
418381"""
419- Base. exp (
420- A:: QuantumObject{ObjType,DimsType,<:AbstractMatrix} ,
421- ) where {ObjType<: Union{Operator,SuperOperator} ,DimsType} =
382+ Base. exp (A:: QuantumObject{ObjType,DimsType,<:AbstractMatrix} ) where {ObjType<: Union{Operator,SuperOperator} ,DimsType} =
422383 QuantumObject (to_sparse (exp (A. data)), A. type, A. dimensions)
423384Base. exp (
424385 A:: QuantumObject{ObjType,DimsType,<:AbstractSparseMatrix} ,
425- ) where {ObjType<: Union{Operator,SuperOperator} ,DimsType} =
426- QuantumObject (_spexp (A. data), A. type, A. dimensions)
386+ ) where {ObjType<: Union{Operator,SuperOperator} ,DimsType} = QuantumObject (_spexp (A. data), A. type, A. dimensions)
427387
428388function _spexp (A:: SparseMatrixCSC{T,M} ; threshold = 1e-14 , nonzero_tol = 1e-20 ) where {T<: Number ,M<: Int }
429389 m = checksquare (A) # Throws exception if not square
@@ -477,8 +437,7 @@ Matrix cosine of [`QuantumObject`](@ref), defined as
477437
478438Note that this function only supports for [`Operator`](@ref) and [`SuperOperator`](@ref)
479439"""
480- Base. cos (A:: QuantumObject{ObjType} ) where {ObjType<: Union{Operator,SuperOperator} } =
481- (exp (1im * A) + exp (- 1im * A)) / 2
440+ Base. cos (A:: QuantumObject{ObjType} ) where {ObjType<: Union{Operator,SuperOperator} } = (exp (1im * A) + exp (- 1im * A)) / 2
482441
483442@doc raw """
484443 diag(A::QuantumObject, k::Int=0)
@@ -487,10 +446,8 @@ Return the `k`-th diagonal elements of a matrix-type [`QuantumObject`](@ref)
487446
488447Note that this function only supports for [`Operator`](@ref) and [`SuperOperator`](@ref)
489448"""
490- LinearAlgebra. diag (
491- A:: QuantumObject{ObjType} ,
492- k:: Int = 0 ,
493- ) where {ObjType<: Union{Operator,SuperOperator} } = diag (A. data, k)
449+ LinearAlgebra. diag (A:: QuantumObject{ObjType} , k:: Int = 0 ) where {ObjType<: Union{Operator,SuperOperator} } =
450+ diag (A. data, k)
494451
495452@doc raw """
496453 proj(ψ::QuantumObject)
@@ -773,12 +730,8 @@ function SparseArrays.permute(
773730 return QuantumObject (reshape (permutedims (reshape (A. data, dims... ), Tuple (perm)), size (A)), A. type, order_dimensions)
774731end
775732
776- _dims_and_perm (
777- :: ObjType ,
778- dims:: SVector{N,Int} ,
779- order:: AbstractVector{Int} ,
780- L:: Int ,
781- ) where {ObjType<: Union{Ket,Bra} ,N} = reverse (dims), reverse ((L + 1 ) .- order)
733+ _dims_and_perm (:: ObjType , dims:: SVector{N,Int} , order:: AbstractVector{Int} , L:: Int ) where {ObjType<: Union{Ket,Bra} ,N} =
734+ reverse (dims), reverse ((L + 1 ) .- order)
782735
783736# if dims originates from Dimensions
784737_dims_and_perm (:: Operator , dims:: SVector{N,Int} , order:: AbstractVector{Int} , L:: Int ) where {N} =
0 commit comments