Skip to content

Commit

Permalink
fix empty spaces and tensors part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jutho committed Feb 11, 2020
1 parent 41d457c commit 669e4fb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/spaces/cartesianspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vector space that is implicitly assumed in most of matrix algebra.
struct CartesianSpace <: EuclideanSpace{ℝ}
d::Int
end
CartesianSpace(d::Integer; dual = false) = CartesianSpace(Int(d))
CartesianSpace(d::Integer = 0; dual = false) = CartesianSpace(Int(d))

Base.getindex(::RealNumbers) = CartesianSpace
Base.getindex(::RealNumbers, d::Int) = CartesianSpace(d)
Expand Down
2 changes: 1 addition & 1 deletion src/spaces/complexspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct ComplexSpace <: EuclideanSpace{ℂ}
d::Int
dual::Bool
end
ComplexSpace(d::Integer; dual = false) = ComplexSpace(Int(d), dual)
ComplexSpace(d::Integer = 0; dual = false) = ComplexSpace(Int(d), dual)

# convenience constructor
Base.:^(::ComplexNumbers, d::Int) = ComplexSpace(d)
Expand Down
2 changes: 1 addition & 1 deletion src/spaces/generalspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct GeneralSpace{𝕜} <: ElementarySpace{𝕜}
end
end
end
GeneralSpace{𝕜}(d::Int; dual::Bool = false, conj::Bool = false) where {𝕜} =
GeneralSpace{𝕜}(d::Int = 0; dual::Bool = false, conj::Bool = false) where {𝕜} =
GeneralSpace{𝕜}(d, dual, conj)

dim(V::GeneralSpace) = V.d
Expand Down
5 changes: 3 additions & 2 deletions src/spaces/representationspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ Base.getindex(::ComplexNumbers, d1::Pair{G,Int}, dims::Pair{G,Int}...) where {G<
# Corresponding methods:
# properties
dim(V::GenericRepresentationSpace) =
mapreduce(c->dim(c)*V.dims[c], +, keys(V.dims); init = 0)
mapreduce(c->dim(c)*V.dims[c], +, keys(V.dims); init = zero(dim(one(sectortype(V)))))
dim(V::GenericRepresentationSpace{G}, c::G) where {G<:Sector} =
get(V.dims, isdual(V) ? dual(c) : c, 0)

dim(V::FiniteRepresentationSpace{G}) where {G<:Sector} =
reduce(+, dc*dim(c) for (dc,c) in zip(V.dims, values(G)); init = 0)
reduce(+, dc*dim(c) for (dc,c) in zip(V.dims, values(G));
init = zero(dim(one(sectortype(V)))))
dim(V::FiniteRepresentationSpace{G}, c::G) where {G<:Sector} =
V.dims[findindex(values(G), isdual(V) ? dual(c) : c)]

Expand Down
10 changes: 5 additions & 5 deletions test/tensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,19 +275,19 @@ for (G,V) in ((Trivial, Vtr), (ℤ₂, Vℤ₂), (ℤ₃, Vℤ₃), (U₁, VU₁
@test N*N' id(codomain(N))
end
@testset "rightorth with $alg" for alg in (TensorKit.RQ(), TensorKit.RQpos(), TensorKit.LQ(), TensorKit.LQpos(), TensorKit.Polar(), TensorKit.SVD(), TensorKit.SDD())
L, Q = @inferred rightorth(t; alg = alg)
@test L == t
@test dim(Q) == dim(R) == 0
L, Q = @inferred rightorth(copy(t'); alg = alg)
@test Q == t'
@test dim(Q) == dim(L) == 0
end
@testset "rightnull with $alg" for alg in (TensorKit.LQ(), TensorKit.SVD(), TensorKit.SDD())
M = @inferred rightnull(t; alg = alg)
M = @inferred rightnull(copy(t'); alg = alg)
@test M*M' id(codomain(M))
@test M'*M id(domain(M))
end
@testset "tsvd with $alg" for alg in (TensorKit.SVD(), TensorKit.SDD())
U, S, V = @inferred tsvd(t; alg = alg)
@test U == t
@test dim(Q) == dim(R) == dim(V)
@test dim(U) == dim(S) == dim(V)
end
end

Expand Down

0 comments on commit 669e4fb

Please sign in to comment.