@@ -17,7 +17,7 @@ function Dimensions(dims::Union{AbstractVector{T},NTuple{N,T}}) where {T<:Intege
1717 L = length (dims)
1818 (L > 0 ) || throw (DomainError (dims, " The argument dims must be of non-zero length" ))
1919
20- return Dimensions {L} (SVector {L,Space } (Space .(dims)))
20+ return Dimensions {L} (SVector {L,AbstractSpace } (Space .(dims)))
2121end
2222Dimensions (dims:: Int ) = Dimensions (SVector {1,Int} (dims))
2323Dimensions (dims:: Any ) = throw (
@@ -28,9 +28,6 @@ Dimensions(dims::Any) = throw(
2828
2929Base. show (io:: IO , D:: Dimensions ) = print (io, D. to)
3030
31- # this creates a list of Space(1), it's used to generate `from` for Ket, and `to` for Bra)
32- oneDimensions (N:: Int ) = Dimensions (SVector {N,AbstractSpace} (ntuple (i -> Space (1 ), Val (N))))
33-
3431struct CompoundDimensions{N} <: AbstractDimensions{N}
3532 # note that the number `N` should be the same for both `to` and `from`
3633 to:: SVector{N,AbstractSpace} # space acting on the left
@@ -52,7 +49,7 @@ function CompoundDimensions(
5249 ),
5350 )
5451
55- return CompoundDimensions {L1} (SVector {L1,Space } (Space .(to)), SVector {L1,Space } (Space .(from)))
52+ return CompoundDimensions {L1} (SVector {L1,AbstractSpace } (Space .(to)), SVector {L1,AbstractSpace } (Space .(from)))
5653end
5754CompoundDimensions (to:: Int , from:: Int ) = CompoundDimensions (SVector {1,Int} (to), SVector {1,Int} (from))
5855
@@ -61,16 +58,17 @@ Base.show(io::IO, D::CompoundDimensions) = print(io, "[", D.to, ", ", D.from, "]
6158_gen_dims (dims:: AbstractDimensions ) = dims
6259_gen_dims (dims:: Any ) = Dimensions (dims)
6360
64- dimsvec_to_list (dimsvec:: SVector{N,AbstractSpace} ) where {N} = SVector {N,Int} (ntuple (i -> dimsvec[i]. size, Val (N)))
61+ # obtain dims in the type of SVector with integers
62+ dims_to_list (dimsvec:: SVector{N,AbstractSpace} ) where {N} = SVector {N,Int} (ntuple (i -> dimsvec[i]. size, Val (N)))
63+ dims_to_list (dims:: Dimensions ) = dims_to_list (dims. to)
64+ dims_to_list (dims:: CompoundDimensions ) = SVector {2} (dims_to_list (dims. to), dims_to_list (dims. from))
6565
66- Base.:(== )(vect:: AbstractVector{T} , dims:: Dimensions ) where {T} = vect == dimsvec_to_list (dims. to)
67- Base.:(== )(vect:: AbstractVector{T} , dims:: CompoundDimensions ) where {T} = vect == [dimsvec_to_list (dims. to), dimsvec_to_list (dims. from)]
66+ Base.:(== )(vect:: AbstractVector{T} , dims:: AbstractDimensions ) where {T} = vect == dims_to_list (dims)
6867Base.:(== )(dims:: AbstractDimensions , vect:: AbstractVector{T} ) where {T} = vect == dims
6968
7069Base. length (:: AbstractDimensions{N} ) where {N} = N
7170
7271Base. prod (dims:: Dimensions ) = prod (dims. to)
73- Base. prod (spaces:: SVector{1,<:AbstractSpace} ) = spaces[1 ]. size # for `Dimensions.to` has only a single Space
7472
7573LinearAlgebra. transpose (dims:: Dimensions ) = dims
7674LinearAlgebra. transpose (dims:: CompoundDimensions ) = CompoundDimensions (dims. from, dims. to) # switch `to` and `from`
0 commit comments