@@ -30,10 +30,11 @@ mutable struct Ket{B,T} <: AbstractKet{B,T}
3030 end
3131end
3232
33- Base. zero (x:: Bra ) = Bra (x. basis, zero (x. data))
34- Base. zero (x:: Ket ) = Ket (x. basis, zero (x. data))
35- eltype (:: Type{K} ) where {K <: Ket{B,V} } where {B,V} = eltype (V)
36- eltype (:: Type{K} ) where {K <: Bra{B,V} } where {B,V} = eltype (V)
33+ Base. zero (x:: T ) where {T<: Union{Bra,Ket} } = T (x. basis, zero (x. data))
34+ Base. eltype (:: Type{K} ) where {K <: Ket{B,V} } where {B,V} = eltype (V)
35+ Base. eltype (:: Type{K} ) where {K <: Bra{B,V} } where {B,V} = eltype (V)
36+ Base. size (x:: Union{Bra,Ket} ) = size (x. data)
37+ @inline Base. axes (x:: Union{Bra,Ket} ) = axes (x. data)
3738
3839Bra {B} (b:: B , data:: T ) where {B,T} = Bra {B,T} (b, data)
3940Ket {B} (b:: B , data:: T ) where {B,T} = Ket {B,T} (b, data)
@@ -51,6 +52,8 @@ Ket{B}(b::B) where B = Ket{B}(ComplexF64, b)
5152Bra (b:: Basis ) = Bra (ComplexF64, b)
5253Ket (b:: Basis ) = Ket (ComplexF64, b)
5354
55+ Base. copy (a:: T ) where {T<: Union{Bra,Ket} } = T (a. basis, copy (a. data))
56+
5457== (x:: Ket{B} , y:: Ket{B} ) where {B} = (samebases (x, y) && x. data== y. data)
5558== (x:: Bra{B} , y:: Bra{B} ) where {B} = (samebases (x, y) && x. data== y. data)
5659== (x:: Ket , y:: Ket ) = false
@@ -80,6 +83,9 @@ Base.isapprox(x::Bra, y::Bra; kwargs...) = false
8083/ (a:: Ket , b:: Number ) = Ket (a. basis, a. data ./ b)
8184/ (a:: Bra , b:: Number ) = Bra (a. basis, a. data ./ b)
8285
86+ - (a:: T ) where {T<: Union{Ket,Bra} } = T (a. basis, - a. data)
87+ norm (x:: Union{Ket,Bra} ) = norm (x. data)
88+ normalize! (x:: Union{Ket,Bra} ) = (normalize! (x. data); x)
8389
8490"""
8591 dagger(x)
@@ -278,4 +284,4 @@ RecursiveArrayTools.recursivecopy!(dest::Ket{B,A},src::Ket{B,A}) where {B,A} = c
278284RecursiveArrayTools. recursivecopy! (dest:: Bra{B,A} ,src:: Bra{B,A} ) where {B,A} = copyto! (dest, src)
279285RecursiveArrayTools. recursivecopy (x:: T ) where {T<: Union{Ket, Bra} } = copy (x)
280286RecursiveArrayTools. recursivecopy (x:: AbstractArray{T} ) where {T<: Union{Ket, Bra} } = copy (x)
281- RecursiveArrayTools. recursivefill! (x:: T , a) where {T<: Union{Ket, Bra} } = fill! (x, a)
287+ RecursiveArrayTools. recursivefill! (x:: T , a) where {T<: Union{Ket, Bra} } = fill! (x, a)
0 commit comments