Skip to content

Commit 1a2f4be

Browse files
committed
improve tests and docs
1 parent 3f14b8e commit 1a2f4be

File tree

8 files changed

+48
-73
lines changed

8 files changed

+48
-73
lines changed

docs/src/lib/sectors.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Finally, these are used to define large manipulations of fusion-splitting tree p
113113
are then used in the index manipulation of `AbstractTensorMap` objects. The following methods
114114
defined on fusion splitting tree pairs have an associated definition for tensors.
115115
```@docs
116-
repartition
116+
repartition(::FusionTree{I,N₁}, ::FusionTree{I,N₂}, ::Int) where {I<:Sector,N₁,N₂}
117117
transpose(::FusionTree{I}, ::FusionTree{I}, ::IndexTuple{N₁}, ::IndexTuple{N₂}) where {I<:Sector,N₁,N₂}
118118
braid(::FusionTree{I}, ::FusionTree{I}, ::IndexTuple, ::IndexTuple, ::IndexTuple{N₁}, ::IndexTuple{N₂}) where {I<:Sector,N₁,N₂}
119119
permute(::FusionTree{I}, ::FusionTree{I}, ::IndexTuple{N₁}, ::IndexTuple{N₂}) where {I<:Sector,N₁,N₂}

docs/src/lib/spaces.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ isepimorphic
108108
isisomorphic
109109
```
110110

111+
Inserting trivial space factors or removing such factors for `ProductSpace` instances
112+
can be done with the following methods.
113+
```@docs
114+
insertleftunit(::ProductSpace, ::Val{i}) where {i}
115+
insertrightunit(::ProductSpace, ::Val{i}) where {i}
116+
removeunit(::ProductSpace, ::Val{i}) where {i}
117+
```
118+
111119
There are also specific methods for `HomSpace` instances, that are used in determining
112120
the resuling `HomSpace` after applying certain tensor operations.
113121

@@ -116,6 +124,7 @@ flip(W::HomSpace{S}, I) where {S}
116124
TensorKit.permute(::HomSpace{S}, ::Index2Tuple{N₁,N₂}) where {S,N₁,N₂}
117125
TensorKit.select(::HomSpace{S}, ::Index2Tuple{N₁,N₂}) where {S,N₁,N₂}
118126
TensorKit.compose(::HomSpace{S}, ::HomSpace{S}) where {S}
119-
insertleftunit(::HomSpace, ::Int)
120-
insertrightunit(::HomSpace, ::Int)
127+
insertleftunit(::HomSpace, ::Val{i}) where {i}
128+
insertrightunit(::HomSpace, ::Val{i}) where {i}
129+
removeunit(::HomSpace, ::Val{i}) where {i}
121130
```

docs/src/lib/tensors.md

+15-7
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ Base.getindex(::AbstractTensorMap, ::Vararg{SliceIndex})
137137
Base.setindex!(::AbstractTensorMap, ::Any, ::Vararg{SliceIndex})
138138
```
139139

140+
The tensor data can also be filled with random numbers via
141+
```@docs
142+
Random.rand!
143+
Random.randn!
144+
Random.randexp!
145+
```
146+
140147
## `AbstractTensorMap` operations
141148

142149
The operations that can be performed on an `AbstractTensorMap` can be organized into the
@@ -171,14 +178,15 @@ type `add_transform!`, for additional expert-mode options that allows for additi
171178
scaling, as well as the selection of a custom backend.
172179

173180
```@docs
174-
permute(::AbstractTensorMap, ::Index2Tuple{N₁,N₂}; ::Bool) where {N₁,N₂}
175-
braid(::AbstractTensorMap, ::Index2Tuple, ::IndexTuple; ::Bool)
176-
transpose(::AbstractTensorMap, ::Index2Tuple; ::Bool)
177-
repartition(::AbstractTensorMap, ::Int, ::Int; ::Bool)
181+
permute(::AbstractTensorMap, ::Index2Tuple{N₁,N₂}) where {N₁,N₂}
182+
braid(::AbstractTensorMap, ::Index2Tuple, ::IndexTuple)
183+
transpose(::AbstractTensorMap, ::Index2Tuple)
184+
repartition(::AbstractTensorMap, ::Int, ::Int)
178185
flip(t::AbstractTensorMap, I)
179-
twist(::AbstractTensorMap, ::Int; ::Bool)
180-
insertleftunit(::AbstractTensorMap, ::Int)
181-
insertrightunit(::AbstractTensorMap, ::Int)
186+
twist(::AbstractTensorMap, ::Int)
187+
insertleftunit(::AbstractTensorMap, ::Val{i}) where {i}
188+
insertrightunit(::AbstractTensorMap, ::Val{i}) where {i}
189+
removeunit(::AbstractTensorMap, ::Val{i}) where {i}
182190
```
183191

184192
```@docs

src/spaces/homspace.jl

+6-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ Insert a trivial vector space, isomorphic to the underlying field, at position `
180180
which can be specified as an `Int` or as `Val(i)` for improved type stability.
181181
More specifically, adds a left monoidal unit or its dual.
182182
183-
See also [`insertrightunit`](@ref), [`removeunit`](@ref).
183+
See also [`insertrightunit`](@ref insertrightunit(::HomSpace, ::Val{i}) where {i}),
184+
[`removeunit`](@ref removeunit(::HomSpace, ::Val{i}) where {i}).
184185
"""
185186
function insertleftunit(W::HomSpace, ::Val{i}=Val(numind(W) + 1);
186187
conj::Bool=false, dual::Bool=false) where {i}
@@ -198,7 +199,8 @@ Insert a trivial vector space, isomorphic to the underlying field, after positio
198199
which can be specified as an `Int` or as `Val(i)` for improved type stability.
199200
More specifically, adds a right monoidal unit or its dual.
200201
201-
See also [`insertleftunit`](@ref), [`removeunit`](@ref).
202+
See also [`insertleftunit`](@ref insertleftunit(::HomSpace, ::Val{i}) where {i}),
203+
[`removeunit`](@ref removeunit(::HomSpace, ::Val{i}) where {i}).
202204
"""
203205
function insertrightunit(W::HomSpace, ::Val{i}=Val(numind(W));
204206
conj::Bool=false, dual::Bool=false) where {i}
@@ -216,7 +218,8 @@ This removes a trivial tensor product factor at position `1 ≤ i ≤ N`, where
216218
can be specified as an `Int` or as `Val(i)` for improved type stability.
217219
For this to work, the space at position `i` has to be isomorphic to the field of scalars.
218220
219-
This operation undoes the work of [`insertleftunit`](@ref) or [`insertrightunit`](@ref).
221+
This operation undoes the work of [`insertleftunit`](@ref insertleftunit(::HomSpace, ::Val{i}) where {i})
222+
and [`insertrightunit`](@ref insertrightunit(::HomSpace, ::Val{i}) where {i}).
220223
"""
221224
function removeunit(P::HomSpace, ::Val{i}) where {i}
222225
if i numout(P)

src/spaces/productspace.jl

+4-3
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ Insert a trivial vector space, isomorphic to the underlying field, at position `
252252
which can be specified as an `Int` or as `Val(i)` for improved type stability.
253253
More specifically, adds a left monoidal unit or its dual.
254254
255-
See also [`insertrightunit`](@ref), [`removeunit`](@ref).
255+
See also [`insertrightunit`](@ref insertrightunit(::ProductSpace, ::Val{i}) where {i}), [`removeunit`](@ref removeunit(::ProductSpace, ::Val{i}) where {i}).
256256
"""
257257
function insertleftunit(P::ProductSpace, ::Val{i}=Val(length(P) + 1);
258258
conj::Bool=false, dual::Bool=false) where {i}
@@ -273,7 +273,7 @@ Insert a trivial vector space, isomorphic to the underlying field, after positio
273273
which can be specified as an `Int` or as `Val(i)` for improved type stability.
274274
More specifically, adds a right monoidal unit or its dual.
275275
276-
See also [`insertleftunit`](@ref), [`removeunit`](@ref).
276+
See also [`insertleftunit`](@ref insertleftunit(::ProductSpace, ::Val{i}) where {i}), [`removeunit`](@ref removeunit(::ProductSpace, ::Val{i}) where {i}).
277277
"""
278278
function insertrightunit(P::ProductSpace, ::Val{i}=Val(length(P));
279279
conj::Bool=false, dual::Bool=false) where {i}
@@ -294,7 +294,8 @@ This removes a trivial tensor product factor at position `1 ≤ i ≤ N`, where
294294
can be specified as an `Int` or as `Val(i)` for improved type stability.
295295
For this to work, that factor has to be isomorphic to the field of scalars.
296296
297-
This operation undoes the work of [`insertunit`](@ref).
297+
This operation undoes the work of [`insertleftunit`](@ref insertleftunit(::ProductSpace, ::Val{i}) where {i})
298+
and [`insertrightunit`](@ref insertrightunit(::ProductSpace, ::Val{i}) where {i}).
298299
"""
299300
function removeunit(P::ProductSpace, ::Val{i}) where {i}
300301
1 i length(P) || _boundserror(P, i)

src/tensors/indexmanipulations.jl

+6-3
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ More specifically, adds a left monoidal unit or its dual.
303303
304304
If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwise, a copy is always made.
305305
306-
See also [`insertrightunit`](@ref) and [`removeunit`](@ref).
306+
See also [`insertrightunit`](@ref insertrightunit(::AbstractTensorMap, ::Val{i}) where {i}),
307+
[`removeunit`](@ref removeunit(::AbstractTensorMap, ::Val{i}) where {i}).
307308
"""
308309
function insertleftunit(t::AbstractTensorMap, ::Val{i}=Val(numind(t) + 1);
309310
copy::Bool=false, conj::Bool=false, dual::Bool=false) where {i}
@@ -329,7 +330,8 @@ More specifically, adds a right monoidal unit or its dual.
329330
330331
If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwise, a copy is always made.
331332
332-
See also [`insertleftunit`](@ref) and [`removeunit`](@ref).
333+
See also [`insertleftunit`](@ref insertleftunit(::AbstractTensorMap, ::Val{i}) where {i}),
334+
[`removeunit`](@ref removeunit(::AbstractTensorMap, ::Val{i}) where {i}).
333335
"""
334336
function insertrightunit(t::AbstractTensorMap, ::Val{i}=Val(numind(t));
335337
copy::Bool=false, conj::Bool=false, dual::Bool=false) where {i}
@@ -354,7 +356,8 @@ For this to work, that factor has to be isomorphic to the field of scalars.
354356
355357
If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwise, a copy is always made.
356358
357-
This operation undoes the work of [`insertunit`](@ref).
359+
This operation undoes the work of [`insertleftunit`](@ref insertleftunit(::AbstractTensorMap, ::Val{i}) where {i})
360+
and [`insertrightunit`](@ref insertrightunit(::AbstractTensorMap, ::Val{i}) where {i}).
358361
"""
359362
function removeunit(t::AbstractTensorMap, ::Val{i}; copy::Bool=false) where {i}
360363
W = removeunit(space(t), Val(i))

src/tensors/tensor.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ for randf in (:rand, :randn, :randexp, :randisometry)
194194
195195
Generate a tensor `t` with entries generated by `$randf`.
196196
197-
See also [`($randf)!`](@ref).
197+
See also [`Random.$(randf)!`](@ref).
198198
"""
199199
_docstr! = """
200200
$(randf)!([rng=default_rng()], t::AbstractTensorMap) -> t
201201
202202
Fill the tensor `t` with entries generated by `$(randf)!`.
203203
204-
See also [`($randf)`](@ref).
204+
See also [`Random.$(randf)`](@ref).
205205
"""
206206

207207
if randf != :randisometry
@@ -467,6 +467,8 @@ Return a view into the data slice of `t` corresponding to the splitting - fusion
467467
`(dims(codomain(t), f₁.uncoupled)..., dims(domain(t), f₂.uncoupled))` is returned which
468468
represents the slice of `block(t, c)` whose row indices correspond to `f₁.uncoupled` and
469469
column indices correspond to `f₂.uncoupled`.
470+
471+
See also [`Base.setindex!(::TensorMap{T,S,N₁,N₂}, ::Any, ::FusionTree{I,N₁}, ::FusionTree{I,N₂}) where {T,S,N₁,N₂,I<:Sector}`](@ref)
470472
"""
471473
@inline function Base.getindex(t::TensorMap{T,S,N₁,N₂},
472474
f₁::FusionTree{I,N₁},
@@ -503,7 +505,7 @@ Copies `v` into the data slice of `t` corresponding to the splitting - fusion t
503505
of size `(dims(codomain(t), f₁.uncoupled)..., dims(domain(t), f₂.uncoupled))` using
504506
`Base.copy!`.
505507
506-
See also [`Base.getindex(::TensorMap{T,S,N₁,N₂,I<:Sector}, ::FusionTree{I<:Sector,N₁}, ::FusionTree{I<:Sector,N₂})`](@ref)
508+
See also [`Base.getindex(::TensorMap{T,S,N₁,N₂}, ::FusionTree{I,N₁}, ::FusionTree{I,N₂}) where {T,S,N₁,N₂,I<:Sector}`](@ref)
507509
"""
508510
@propagate_inbounds function Base.setindex!(t::TensorMap{T,S,N₁,N₂},
509511
v,

test/tensors.jl

-51
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,3 @@
1-
Vtr = (ℂ^3,
2-
(ℂ^4)',
3-
^5,
4-
^6,
5-
(ℂ^7)')
6-
Vℤ₂ = (ℂ[Z2Irrep](0 => 1, 1 => 1),
7-
ℂ[Z2Irrep](0 => 1, 1 => 2)',
8-
ℂ[Z2Irrep](0 => 3, 1 => 2)',
9-
ℂ[Z2Irrep](0 => 2, 1 => 3),
10-
ℂ[Z2Irrep](0 => 2, 1 => 5))
11-
Vfℤ₂ = (ℂ[FermionParity](0 => 1, 1 => 1),
12-
ℂ[FermionParity](0 => 1, 1 => 2)',
13-
ℂ[FermionParity](0 => 3, 1 => 2)',
14-
ℂ[FermionParity](0 => 2, 1 => 3),
15-
ℂ[FermionParity](0 => 2, 1 => 5))
16-
Vℤ₃ = (ℂ[Z3Irrep](0 => 1, 1 => 2, 2 => 2),
17-
ℂ[Z3Irrep](0 => 3, 1 => 1, 2 => 1),
18-
ℂ[Z3Irrep](0 => 2, 1 => 2, 2 => 1)',
19-
ℂ[Z3Irrep](0 => 1, 1 => 2, 2 => 3),
20-
ℂ[Z3Irrep](0 => 1, 1 => 3, 2 => 3)')
21-
VU₁ = (ℂ[U1Irrep](0 => 1, 1 => 2, -1 => 2),
22-
ℂ[U1Irrep](0 => 3, 1 => 1, -1 => 1),
23-
ℂ[U1Irrep](0 => 2, 1 => 2, -1 => 1)',
24-
ℂ[U1Irrep](0 => 1, 1 => 2, -1 => 3),
25-
ℂ[U1Irrep](0 => 1, 1 => 3, -1 => 3)')
26-
VfU₁ = (ℂ[FermionNumber](0 => 1, 1 => 2, -1 => 2),
27-
ℂ[FermionNumber](0 => 3, 1 => 1, -1 => 1),
28-
ℂ[FermionNumber](0 => 2, 1 => 2, -1 => 1)',
29-
ℂ[FermionNumber](0 => 1, 1 => 2, -1 => 3),
30-
ℂ[FermionNumber](0 => 1, 1 => 3, -1 => 3)')
31-
VCU₁ = (ℂ[CU1Irrep]((0, 0) => 1, (0, 1) => 2, 1 => 1),
32-
ℂ[CU1Irrep]((0, 0) => 3, (0, 1) => 0, 1 => 1),
33-
ℂ[CU1Irrep]((0, 0) => 1, (0, 1) => 0, 1 => 2)',
34-
ℂ[CU1Irrep]((0, 0) => 2, (0, 1) => 2, 1 => 1),
35-
ℂ[CU1Irrep]((0, 0) => 2, (0, 1) => 1, 1 => 2)')
36-
VSU₂ = (ℂ[SU2Irrep](0 => 3, 1 // 2 => 1),
37-
ℂ[SU2Irrep](0 => 2, 1 => 1),
38-
ℂ[SU2Irrep](1 // 2 => 1, 1 => 1)',
39-
ℂ[SU2Irrep](0 => 2, 1 // 2 => 2),
40-
ℂ[SU2Irrep](0 => 1, 1 // 2 => 1, 3 // 2 => 1)')
41-
VfSU₂ = (ℂ[FermionSpin](0 => 3, 1 // 2 => 1),
42-
ℂ[FermionSpin](0 => 2, 1 => 1),
43-
ℂ[FermionSpin](1 // 2 => 1, 1 => 1)',
44-
ℂ[FermionSpin](0 => 2, 1 // 2 => 2),
45-
ℂ[FermionSpin](0 => 1, 1 // 2 => 1, 3 // 2 => 1)')
46-
# VSU₃ = (ℂ[SU3Irrep]((0, 0, 0) => 3, (1, 0, 0) => 1),
47-
# ℂ[SU3Irrep]((0, 0, 0) => 3, (2, 0, 0) => 1)',
48-
# ℂ[SU3Irrep]((1, 1, 0) => 1, (2, 1, 0) => 1),
49-
# ℂ[SU3Irrep]((1, 0, 0) => 1, (2, 0, 0) => 1),
50-
# ℂ[SU3Irrep]((0, 0, 0) => 1, (1, 0, 0) => 1, (1, 1, 0) => 1)')
51-
521
for V in (Vtr, Vℤ₂, Vfℤ₂, Vℤ₃, VU₁, VfU₁, VCU₁, VSU₂, VfSU₂)#, VSU₃)
532
V1, V2, V3, V4, V5 = V
543
@assert V3 * V4 * V2 V1' * V5' # necessary for leftorth tests

0 commit comments

Comments
 (0)