Skip to content

Commit 977b7d3

Browse files
committed
modify show for AbstractSpace and CompoundDimensions
1 parent 6e1fe7b commit 977b7d3

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/qobj/arithmetic_and_attributes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ end
5353
function check_mul_dims(from::SVector{NA,AbstractSpace}, to::SVector{NB,AbstractSpace}) where {NA,NB}
5454
(from != to) && throw(
5555
DimensionMismatch(
56-
"The quantum object with dims = $from can not multiply a quantum object with dims = $to on the right-hand side.",
56+
"The quantum object with (right) dims = $(dims_to_list(from)) can not multiply a quantum object with (left) dims = $(dims_to_list(to)) on the right-hand side.",
5757
),
5858
)
5959
return nothing

src/qobj/dimensions.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function CompoundDimensions(dims::Union{AbstractVector{T},NTuple{N,T}}) where {T
4646
)
4747
end
4848

49-
Base.show(io::IO, D::CompoundDimensions) = print(io, "[", D.to, ", ", D.from, "]")
49+
#Base.show(io::IO, D::CompoundDimensions) = print(io, "[", D.to, ", ", D.from, "]")
5050

5151
_gen_dims(dims::AbstractDimensions) = dims
5252
_gen_dims(dims::Union{AbstractVector{T},NTuple{N,T}}) where {T<:Integer,N} = Dimensions(dims)
@@ -59,6 +59,13 @@ dims_to_list(dimsvec::SVector{N,AbstractSpace}) where {N} = vcat(map(dims_to_lis
5959
dims_to_list(dims::Dimensions) = dims_to_list(dims.to)
6060
dims_to_list(dims::CompoundDimensions) = SVector{2}(dims_to_list(dims.to), dims_to_list(dims.from))
6161

62+
# for printing `dims_to_list(CompoundDimensions)`
63+
function Base.show(io::IO, svec::SVector{2,SVector{N,T}}) where {N,T<:Int}
64+
print(io, "[")
65+
join(io, svec, ", ")
66+
print(io, "]")
67+
end
68+
6269
Base.length(::AbstractDimensions{N}) where {N} = N
6370

6471
# need to specify return type `Int` for `_get_space_size`

src/qobj/space.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ export AbstractSpace, Field, Space
22

33
abstract type AbstractSpace end
44

5+
# for printing `AbstractDimensions`
6+
function Base.show(io::IO, svec::SVector{N,AbstractSpace}) where {N}
7+
print(io, "[")
8+
join(io, svec, ", ")
9+
print(io, "]")
10+
end
11+
512
# this replaces Space(1), so that we don't need to store the value `1`
613
struct Field <: AbstractSpace end
714
Base.getproperty(s::Field, key::Symbol) = getproperty(s, Val{key}())

0 commit comments

Comments
 (0)