Skip to content

Commit

Permalink
Constructor fixes (#185)
Browse files Browse the repository at this point in the history
* some constructor fixes

* add fix and tests

* more isometry constructor fixes
  • Loading branch information
Jutho authored Dec 8, 2024
1 parent 40e74d7 commit 9f553b0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
__pycache__
.ipynb*
Manifest.toml
.vscode
.vscode
benchmark
experimental
refs
*.mathcha

10 changes: 4 additions & 6 deletions src/fusiontrees/fusiontrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,11 @@ function FusionTree{I}(uncoupled::NTuple{N}, coupled=one(I),
_abelianinner(map(s -> convert(I, s),
(uncoupled..., dual(coupled)))))
end
function FusionTree(uncoupled::Tuple{I,Vararg{I}}, coupled::I=one(I),
isdual=ntuple(n -> false, length(uncoupled))) where {I<:Sector}
FusionStyle(I) isa UniqueFusion ||
error("fusion tree requires inner lines if `FusionStyle(I) <: MultipleFusion`")
return FusionTree{I}(uncoupled, coupled, isdual,
_abelianinner((uncoupled..., dual(coupled))))
function FusionTree(uncoupled::NTuple{N,I}, coupled::I,
isdual=ntuple(n -> false, length(uncoupled))) where {N,I<:Sector}
return FusionTree{I}(uncoupled, coupled, isdual)
end
FusionTree(uncoupled::Tuple{I,Vararg{I}}) where {I<:Sector} = FusionTree(uncoupled, one(I))

# Properties
sectortype(::Type{<:FusionTree{I}}) where {I<:Sector} = I
Expand Down
7 changes: 3 additions & 4 deletions src/tensors/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ the spacetype does not have a Euclidean inner product, an error will be thrown.
See also [`isomorphism`](@ref) and [`isometry`](@ref).
"""
function unitary(::Type{A}, V::TensorMapSpace{S,N₁,N₂}) where {A<:VecOrNumber,S,N₁,N₂}
function unitary(A::Type, V::TensorMapSpace{S,N₁,N₂}) where {S,N₁,N₂}
InnerProductStyle(S) === EuclideanInnerProduct() || throw_invalid_innerproduct(:unitary)
return isomorphism(A, V)
end
Expand Down Expand Up @@ -155,9 +155,8 @@ for morphism in (:isomorphism, :unitary, :isometry)
@eval begin
$morphism(V::TensorMapSpace) = $morphism(Float64, V)
$morphism(codomain::TensorSpace, domain::TensorSpace) = $morphism(codomain domain)
function $morphism(::Type{T}, codomain::TensorSpace,
domain::TensorSpace) where {T<:VecOrNumber}
return $morphism(T, codomain domain)
function $morphism(A::Type, codomain::TensorSpace, domain::TensorSpace)
return $morphism(A, codomain domain)
end
$morphism(t::AbstractTensorMap) = $morphism(storagetype(t), space(t))
end
Expand Down
37 changes: 37 additions & 0 deletions test/fusiontrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,43 @@ ti = time()
@testset "Fusion tree $Istr: printing" begin
@test eval(Meta.parse(sprint(show, f))) == f
end
@testset "Fusion tree $Istr: constructor properties" begin
u = one(I)
@constinferred FusionTree((), u, (), (), ())
@constinferred FusionTree((u,), u, (false,), (), ())
@constinferred FusionTree((u, u), u, (false, false), (), (1,))
@constinferred FusionTree((u, u, u), u, (false, false, false), (u,), (1, 1))
@constinferred FusionTree((u, u, u, u), u, (false, false, false, false), (u, u),
(1, 1, 1))
@test_throws MethodError FusionTree((u, u, u), u, (false, false), (u,), (1, 1))
@test_throws MethodError FusionTree((u, u, u), u, (false, false, false), (u, u),
(1, 1))
@test_throws MethodError FusionTree((u, u, u), u, (false, false, false), (u,),
(1, 1, 1))
@test_throws MethodError FusionTree((u, u, u), u, (false, false, false), (), (1,))

f = FusionTree((u, u, u), u, (false, false, false), (u,), (1, 1))
@test sectortype(f) == I
@test length(f) == 3
@test FusionStyle(f) == FusionStyle(I)
@test BraidingStyle(f) == BraidingStyle(I)

if FusionStyle(I) isa UniqueFusion
@constinferred FusionTree((), u, ())
@constinferred FusionTree((u,), u, (false,))
@constinferred FusionTree((u, u), u, (false, false))
@constinferred FusionTree((u, u, u), u)
@constinferred FusionTree((u, u, u, u))
@test_throws MethodError FusionTree((u, u), u, (false, false, false))
else
errstr = "fusion tree requires inner lines if `FusionStyle(I) <: MultipleFusion`"
@test_throws errstr FusionTree((), u, ())
@test_throws errstr FusionTree((u,), u, (false,))
@test_throws errstr FusionTree((u, u), u, (false, false))
@test_throws errstr FusionTree((u, u, u), u)
@test_throws errstr FusionTree((u, u, u, u))
end
end
@testset "Fusion tree $Istr: insertat" begin
N = 4
out2 = ntuple(n -> randsector(I), N)
Expand Down

0 comments on commit 9f553b0

Please sign in to comment.