Skip to content

Commit 428afee

Browse files
committed
bring back insertleft/rightunit and removeunit
1 parent ae92cc1 commit 428afee

File tree

10 files changed

+96
-96
lines changed

10 files changed

+96
-96
lines changed

docs/src/lib/spaces.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@ isisomorphic
112112
Inserting trivial space factors or removing such factors for `ProductSpace` instances
113113
can be done with the following methods.
114114
```@docs
115-
insertleftunitspace(::ProductSpace, ::Val{i}) where {i}
116-
insertrightunitspace(::ProductSpace, ::Val{i}) where {i}
117-
removeunitspace(::ProductSpace, ::Val{i}) where {i}
115+
insertleftunit(::ProductSpace, ::Val{i}) where {i}
116+
insertrightunit(::ProductSpace, ::Val{i}) where {i}
117+
removeunit(::ProductSpace, ::Val{i}) where {i}
118118
```
119119

120120
There are also specific methods for `HomSpace` instances, that are used in determining
@@ -125,7 +125,7 @@ flip(W::HomSpace{S}, I) where {S}
125125
TensorKit.permute(::HomSpace{S}, ::Index2Tuple{N₁,N₂}) where {S,N₁,N₂}
126126
TensorKit.select(::HomSpace{S}, ::Index2Tuple{N₁,N₂}) where {S,N₁,N₂}
127127
TensorKit.compose(::HomSpace{S}, ::HomSpace{S}) where {S}
128-
insertleftunitspace(::HomSpace, ::Val{i}) where {i}
129-
insertrightunitspace(::HomSpace, ::Val{i}) where {i}
130-
removeunitspace(::HomSpace, ::Val{i}) where {i}
128+
insertleftunit(::HomSpace, ::Val{i}) where {i}
129+
insertrightunit(::HomSpace, ::Val{i}) where {i}
130+
removeunit(::HomSpace, ::Val{i}) where {i}
131131
```

docs/src/lib/tensors.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ transpose(::AbstractTensorMap, ::Index2Tuple)
184184
repartition(::AbstractTensorMap, ::Int, ::Int)
185185
flip(t::AbstractTensorMap, I)
186186
twist(::AbstractTensorMap, ::Int)
187-
insertleftunitspace(::AbstractTensorMap, ::Val{i}) where {i}
188-
insertrightunitspace(::AbstractTensorMap, ::Val{i}) where {i}
189-
removeunitspace(::AbstractTensorMap, ::Val{i}) where {i}
187+
insertleftunit(::AbstractTensorMap, ::Val{i}) where {i}
188+
insertrightunit(::AbstractTensorMap, ::Val{i}) where {i}
189+
removeunit(::AbstractTensorMap, ::Val{i}) where {i}
190190
```
191191

192192
```@docs

src/TensorKit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export SpaceMismatch, SectorMismatch, IndexError # error types
3737
# Export general vector space methods
3838
export space, field, dual, dim, reduceddim, dims, fuse, flip, isdual
3939
export unitspace, zerospace, oplus, ominus
40-
export insertleftunitspace, insertrightunitspace, removeunitspace
40+
export insertleftunit, insertrightunit, removeunit
4141

4242
# partial order for vector spaces
4343
export infimum, supremum, isisomorphic, ismonomorphic, isepimorphic

src/auxiliary/deprecate.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ end
3333

3434
Base.@deprecate EuclideanProduct() EuclideanInnerProduct()
3535

36-
Base.@deprecate insertunit(P::ProductSpace, args...; kwargs...) insertleftunitspace(args...; kwargs...)
36+
Base.@deprecate insertunit(P::ProductSpace, args...; kwargs...) insertleftunit(args...; kwargs...)
3737

3838
# Factorization structs
3939
@deprecate QR() MatrixAlgebraKit.LAPACK_HouseholderQR()

src/spaces/homspace.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,62 +196,62 @@ function compose(W::HomSpace{S}, V::HomSpace{S}) where {S}
196196
end
197197

198198
"""
199-
insertleftunitspace(W::HomSpace, i=numind(W) + 1; conj=false, dual=false)
199+
insertleftunit(W::HomSpace, i=numind(W) + 1; conj=false, dual=false)
200200
201201
Insert a trivial vector space, isomorphic to the underlying field, at position `i`,
202202
which can be specified as an `Int` or as `Val(i)` for improved type stability.
203203
More specifically, adds a left monoidal unit or its dual.
204204
205-
See also [`insertrightunitspace`](@ref insertrightunitspace(::HomSpace, ::Val{i}) where {i}),
206-
[`removeunitspace`](@ref removeunitspace(::HomSpace, ::Val{i}) where {i}).
205+
See also [`insertrightunit`](@ref insertrightunit(::HomSpace, ::Val{i}) where {i}),
206+
[`removeunit`](@ref removeunit(::HomSpace, ::Val{i}) where {i}).
207207
"""
208-
function insertleftunitspace(
208+
function insertleftunit(
209209
W::HomSpace, ::Val{i} = Val(numind(W) + 1);
210210
conj::Bool = false, dual::Bool = false
211211
) where {i}
212212
if i numout(W)
213-
return insertleftunitspace(codomain(W), Val(i); conj, dual) domain(W)
213+
return insertleftunit(codomain(W), Val(i); conj, dual) domain(W)
214214
else
215-
return codomain(W) insertleftunitspace(domain(W), Val(i - numout(W)); conj, dual)
215+
return codomain(W) insertleftunit(domain(W), Val(i - numout(W)); conj, dual)
216216
end
217217
end
218218

219219
"""
220-
insertrightunitspace(W::HomSpace, i=numind(W); conj=false, dual=false)
220+
insertrightunit(W::HomSpace, i=numind(W); conj=false, dual=false)
221221
222222
Insert a trivial vector space, isomorphic to the underlying field, after position `i`,
223223
which can be specified as an `Int` or as `Val(i)` for improved type stability.
224224
More specifically, adds a right monoidal unit or its dual.
225225
226-
See also [`insertleftunitspace`](@ref insertleftunitspace(::HomSpace, ::Val{i}) where {i}),
227-
[`removeunitspace`](@ref removeunitspace(::HomSpace, ::Val{i}) where {i}).
226+
See also [`insertleftunit`](@ref insertleftunit(::HomSpace, ::Val{i}) where {i}),
227+
[`removeunit`](@ref removeunit(::HomSpace, ::Val{i}) where {i}).
228228
"""
229-
function insertrightunitspace(
229+
function insertrightunit(
230230
W::HomSpace, ::Val{i} = Val(numind(W));
231231
conj::Bool = false, dual::Bool = false
232232
) where {i}
233233
if i numout(W)
234-
return insertrightunitspace(codomain(W), Val(i); conj, dual) domain(W)
234+
return insertrightunit(codomain(W), Val(i); conj, dual) domain(W)
235235
else
236-
return codomain(W) insertrightunitspace(domain(W), Val(i - numout(W)); conj, dual)
236+
return codomain(W) insertrightunit(domain(W), Val(i - numout(W)); conj, dual)
237237
end
238238
end
239239

240240
"""
241-
removeunitspace(P::HomSpace, i)
241+
removeunit(P::HomSpace, i)
242242
243243
This removes a trivial tensor product factor at position `1 ≤ i ≤ N`, where `i`
244244
can be specified as an `Int` or as `Val(i)` for improved type stability.
245245
For this to work, the space at position `i` has to be isomorphic to the field of scalars.
246246
247-
This operation undoes the work of [`insertleftunitspace`](@ref insertleftunitspace(::HomSpace, ::Val{i}) where {i})
248-
and [`insertrightunitspace`](@ref insertrightunitspace(::HomSpace, ::Val{i}) where {i}).
247+
This operation undoes the work of [`insertleftunit`](@ref insertleftunit(::HomSpace, ::Val{i}) where {i})
248+
and [`insertrightunit`](@ref insertrightunit(::HomSpace, ::Val{i}) where {i}).
249249
"""
250-
function removeunitspace(P::HomSpace, ::Val{i}) where {i}
250+
function removeunit(P::HomSpace, ::Val{i}) where {i}
251251
if i numout(P)
252-
return removeunitspace(codomain(P), Val(i)) domain(P)
252+
return removeunit(codomain(P), Val(i)) domain(P)
253253
else
254-
return codomain(P) removeunitspace(domain(P), Val(i - numout(P)))
254+
return codomain(P) removeunit(domain(P), Val(i - numout(P)))
255255
end
256256
end
257257

src/spaces/productspace.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ fuse(P::ProductSpace{S, 0}) where {S <: ElementarySpace} = unitspace(S)
249249
fuse(P::ProductSpace{S}) where {S <: ElementarySpace} = fuse(P.spaces...)
250250

251251
"""
252-
insertleftunitspace(P::ProductSpace, i::Int=length(P) + 1; conj=false, dual=false)
252+
insertleftunit(P::ProductSpace, i::Int=length(P) + 1; conj=false, dual=false)
253253
254254
Insert a trivial vector space, isomorphic to the underlying field, at position `i`,
255255
which can be specified as an `Int` or as `Val(i)` for improved type stability.
256256
More specifically, adds a left monoidal unit or its dual.
257257
258-
See also [`insertrightunitspace`](@ref insertrightunitspace(::ProductSpace, ::Val{i}) where {i}), [`removeunitspace`](@ref removeunitspace(::ProductSpace, ::Val{i}) where {i}).
258+
See also [`insertrightunit`](@ref insertrightunit(::ProductSpace, ::Val{i}) where {i}), [`removeunit`](@ref removeunit(::ProductSpace, ::Val{i}) where {i}).
259259
"""
260-
function insertleftunitspace(P::ProductSpace, ::Val{i}=Val(length(P) + 1);
260+
function insertleftunit(P::ProductSpace, ::Val{i}=Val(length(P) + 1);
261261
conj::Bool=false, dual::Bool=false) where {i}
262262
N = length(P)
263263
I = sectortype(P)
@@ -278,15 +278,15 @@ function insertleftunitspace(P::ProductSpace, ::Val{i}=Val(length(P) + 1);
278278
end
279279

280280
"""
281-
insertrightunitspace(P::ProductSpace, i=length(P); conj=false, dual=false)
281+
insertrightunit(P::ProductSpace, i=length(P); conj=false, dual=false)
282282
283283
Insert a trivial vector space, isomorphic to the underlying field, after position `i`,
284284
which can be specified as an `Int` or as `Val(i)` for improved type stability.
285285
More specifically, adds a right monoidal unit or its dual.
286286
287-
See also [`insertleftunitspace`](@ref insertleftunitspace(::ProductSpace, ::Val{i}) where {i}), [`removeunitspace`](@ref removeunitspace(::ProductSpace, ::Val{i}) where {i}).
287+
See also [`insertleftunit`](@ref insertleftunit(::ProductSpace, ::Val{i}) where {i}), [`removeunit`](@ref removeunit(::ProductSpace, ::Val{i}) where {i}).
288288
"""
289-
function insertrightunitspace(P::ProductSpace, ::Val{i}=Val(length(P));
289+
function insertrightunit(P::ProductSpace, ::Val{i}=Val(length(P));
290290
conj::Bool=false, dual::Bool=false) where {i}
291291
N = length(P)
292292
I = sectortype(P)
@@ -307,16 +307,16 @@ function insertrightunitspace(P::ProductSpace, ::Val{i}=Val(length(P));
307307
end
308308

309309
"""
310-
removeunitspace(P::ProductSpace, i::Int)
310+
removeunit(P::ProductSpace, i::Int)
311311
312312
This removes a trivial tensor product factor at position `1 ≤ i ≤ N`, where `i`
313313
can be specified as an `Int` or as `Val(i)` for improved type stability.
314314
For this to work, that factor has to be isomorphic to the field of scalars.
315315
316-
This operation undoes the work of [`insertleftunitspace`](@ref insertleftunitspace(::ProductSpace, ::Val{i}) where {i})
317-
and [`insertrightunitspace`](@ref insertrightunitspace(::ProductSpace, ::Val{i}) where {i}).
316+
This operation undoes the work of [`insertleftunit`](@ref insertleftunit(::ProductSpace, ::Val{i}) where {i})
317+
and [`insertrightunit`](@ref insertrightunit(::ProductSpace, ::Val{i}) where {i}).
318318
"""
319-
function removeunitspace(P::ProductSpace, ::Val{i}) where {i}
319+
function removeunit(P::ProductSpace, ::Val{i}) where {i}
320320
1 i length(P) || _boundserror(P, i)
321321
I = sectortype(P)
322322
if isa(UnitStyle(I), SimpleUnit)

src/spaces/vectorspaces.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ end
219219

220220
# In the following, X can be a ProductSpace, a HomSpace or an AbstractTensorMap
221221
# TODO: should we deprecate those in the future?
222-
@constprop :aggressive function insertleftunitspace(X, i::Int; kwargs...)
223-
return insertleftunitspace(X, Val(i); kwargs...)
222+
@constprop :aggressive function insertleftunit(X, i::Int; kwargs...)
223+
return insertleftunit(X, Val(i); kwargs...)
224224
end
225-
@constprop :aggressive function insertrightunitspace(X, i::Int; kwargs...)
226-
return insertrightunitspace(X, Val(i); kwargs...)
225+
@constprop :aggressive function insertrightunit(X, i::Int; kwargs...)
226+
return insertrightunit(X, Val(i); kwargs...)
227227
end
228-
@constprop :aggressive function removeunitspace(X, i::Int; kwargs...)
229-
return removeunitspace(X, Val(i); kwargs...)
228+
@constprop :aggressive function removeunit(X, i::Int; kwargs...)
229+
return removeunit(X, Val(i); kwargs...)
230230
end
231231

232232
# trait to describe the inner product type of vector spaces

src/tensors/indexmanipulations.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ twist(t::AbstractTensorMap, i; inv::Bool = false) = twist!(copy(t), i; inv)
306306

307307
# Methods which change the number of indices, implement using `Val(i)` for type inference
308308
"""
309-
insertleftunitspace(tsrc::AbstractTensorMap, i=numind(t) + 1;
309+
insertleftunit(tsrc::AbstractTensorMap, i=numind(t) + 1;
310310
conj=false, dual=false, copy=false) -> tdst
311311
312312
Insert a trivial vector space, isomorphic to the underlying field, at position `i`,
@@ -315,12 +315,12 @@ More specifically, adds a left monoidal unit or its dual.
315315
316316
If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwise, a copy is always made.
317317
318-
See also [`insertrightunitspace`](@ref insertrightunitspace(::AbstractTensorMap, ::Val{i}) where {i}),
319-
[`removeunitspace`](@ref removeunitspace(::AbstractTensorMap, ::Val{i}) where {i}).
318+
See also [`insertrightunit`](@ref insertrightunit(::AbstractTensorMap, ::Val{i}) where {i}),
319+
[`removeunit`](@ref removeunit(::AbstractTensorMap, ::Val{i}) where {i}).
320320
"""
321-
function insertleftunitspace(t::AbstractTensorMap, ::Val{i}=Val(numind(t) + 1);
321+
function insertleftunit(t::AbstractTensorMap, ::Val{i}=Val(numind(t) + 1);
322322
copy::Bool=false, conj::Bool=false, dual::Bool=false) where {i}
323-
W = insertleftunitspace(space(t), Val(i); conj, dual)
323+
W = insertleftunit(space(t), Val(i); conj, dual)
324324
if t isa TensorMap
325325
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
326326
else
@@ -333,7 +333,7 @@ function insertleftunitspace(t::AbstractTensorMap, ::Val{i}=Val(numind(t) + 1);
333333
end
334334

335335
"""
336-
insertrightunitspace(tsrc::AbstractTensorMap, i=numind(t);
336+
insertrightunit(tsrc::AbstractTensorMap, i=numind(t);
337337
conj=false, dual=false, copy=false) -> tdst
338338
339339
Insert a trivial vector space, isomorphic to the underlying field, after position `i`,
@@ -342,12 +342,12 @@ More specifically, adds a right monoidal unit or its dual.
342342
343343
If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwise, a copy is always made.
344344
345-
See also [`insertleftunitspace`](@ref insertleftunitspace(::AbstractTensorMap, ::Val{i}) where {i}),
346-
[`removeunitspace`](@ref removeunitspace(::AbstractTensorMap, ::Val{i}) where {i}).
345+
See also [`insertleftunit`](@ref insertleftunit(::AbstractTensorMap, ::Val{i}) where {i}),
346+
[`removeunit`](@ref removeunit(::AbstractTensorMap, ::Val{i}) where {i}).
347347
"""
348-
function insertrightunitspace(t::AbstractTensorMap, ::Val{i}=Val(numind(t));
348+
function insertrightunit(t::AbstractTensorMap, ::Val{i}=Val(numind(t));
349349
copy::Bool=false, conj::Bool=false, dual::Bool=false) where {i}
350-
W = insertrightunitspace(space(t), Val(i); conj, dual)
350+
W = insertrightunit(space(t), Val(i); conj, dual)
351351
if t isa TensorMap
352352
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
353353
else
@@ -360,19 +360,19 @@ function insertrightunitspace(t::AbstractTensorMap, ::Val{i}=Val(numind(t));
360360
end
361361

362362
"""
363-
removeunitspace(tsrc::AbstractTensorMap, i; copy=false) -> tdst
363+
removeunit(tsrc::AbstractTensorMap, i; copy=false) -> tdst
364364
365365
This removes a trivial tensor product factor at position `1 ≤ i ≤ N`, where `i`
366366
can be specified as an `Int` or as `Val(i)` for improved type stability.
367367
For this to work, that factor has to be isomorphic to the field of scalars.
368368
369369
If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwise, a copy is always made.
370370
371-
This operation undoes the work of [`insertleftunitspace`](@ref insertleftunitspace(::AbstractTensorMap, ::Val{i}) where {i})
372-
and [`insertrightunitspace`](@ref insertrightunitspace(::AbstractTensorMap, ::Val{i}) where {i}).
371+
This operation undoes the work of [`insertleftunit`](@ref insertleftunit(::AbstractTensorMap, ::Val{i}) where {i})
372+
and [`insertrightunit`](@ref insertrightunit(::AbstractTensorMap, ::Val{i}) where {i}).
373373
"""
374-
function removeunitspace(t::AbstractTensorMap, ::Val{i}; copy::Bool=false) where {i}
375-
W = removeunitspace(space(t), Val(i))
374+
function removeunit(t::AbstractTensorMap, ::Val{i}; copy::Bool=false) where {i}
375+
W = removeunit(space(t), Val(i))
376376
if t isa TensorMap
377377
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
378378
else

test/symmetries/spaces.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,9 @@ end
304304
@test @constinferred((V1, V2, V3 V4)) == P
305305
@test @constinferred((V1, V2 V3, V4)) == P
306306
@test V1 * V2 * unitspace(V1) * V3 * V4 ==
307-
@constinferred(insertleftunitspace(P, 3)) ==
308-
@constinferred(insertrightunitspace(P, 2))
309-
@test @constinferred(removeunitspace(V1 * V2 * unitspace(V1)' * V3 * V4, 3)) == P
307+
@constinferred(insertleftunit(P, 3)) ==
308+
@constinferred(insertrightunit(P, 2))
309+
@test @constinferred(removeunit(V1 * V2 * unitspace(V1)' * V3 * V4, 3)) == P
310310
@test fuse(V1, V2', V3) V1 V2' V3
311311
@test fuse(V1, V2', V3) V1 V2' V3
312312
@test fuse(V1, V2', V3) V1 V2' V3
@@ -365,9 +365,9 @@ end
365365
@test @constinferred((V1, V2, V3)) == P
366366
@test @constinferred(adjoint(P)) == dual(P) == V3' V2' V1'
367367
@test V1 * V2 * unitspace(V1)' * V3 ==
368-
@constinferred(insertleftunitspace(P, 3; conj = true)) ==
369-
@constinferred(insertrightunitspace(P, 2; conj = true))
370-
@test P == @constinferred(removeunitspace(insertleftunitspace(P, 3), 3))
368+
@constinferred(insertleftunit(P, 3; conj = true)) ==
369+
@constinferred(insertrightunit(P, 2; conj = true))
370+
@test P == @constinferred(removeunit(insertleftunit(P, 3), 3))
371371
@test fuse(V1, V2', V3) V1 V2' V3
372372
@test fuse(V1, V2', V3) V1 V2' V3 fuse(V1 V2' V3)
373373
@test fuse(V1, V2') V3 V1 V2' V3
@@ -446,22 +446,22 @@ end
446446
@test permute(W, ((2, 4, 5), (3, 1))) == (V2 V4' V5' V3 V1')
447447
@test (V1 V2 V1 V2) == @constinferred TensorKit.compose(W, W')
448448
@test (V1 V2 V3 V4 V5 unitspace(V5)) ==
449-
@constinferred(insertleftunitspace(W)) ==
450-
@constinferred(insertrightunitspace(W))
451-
@test @constinferred(removeunitspace(insertleftunitspace(W), $(numind(W) + 1))) == W
449+
@constinferred(insertleftunit(W)) ==
450+
@constinferred(insertrightunit(W))
451+
@test @constinferred(removeunit(insertleftunit(W), $(numind(W) + 1))) == W
452452
@test (V1 V2 V3 V4 V5 unitspace(V5)') ==
453-
@constinferred(insertleftunitspace(W; conj = true)) ==
454-
@constinferred(insertrightunitspace(W; conj = true))
453+
@constinferred(insertleftunit(W; conj = true)) ==
454+
@constinferred(insertrightunit(W; conj = true))
455455
@test (unitspace(V1) V1 V2 V3 V4 V5) ==
456-
@constinferred(insertleftunitspace(W, 1)) ==
457-
@constinferred(insertrightunitspace(W, 0))
456+
@constinferred(insertleftunit(W, 1)) ==
457+
@constinferred(insertrightunit(W, 0))
458458
@test (V1 V2 unitspace(V1) V3 V4 V5) ==
459-
@constinferred(insertrightunitspace(W, 2))
459+
@constinferred(insertrightunit(W, 2))
460460
@test (V1 V2 unitspace(V1) V3 V4 V5) ==
461-
@constinferred(insertleftunitspace(W, 3))
462-
@test @constinferred(removeunitspace(insertleftunitspace(W, 3), 3)) == W
463-
@test @constinferred(insertrightunitspace(one(V1) V1, 0)) == (unitspace(V1) V1)
464-
@test_throws BoundsError insertleftunitspace(one(V1) V1, 0)
461+
@constinferred(insertleftunit(W, 3))
462+
@test @constinferred(removeunit(insertleftunit(W, 3), 3)) == W
463+
@test @constinferred(insertrightunit(one(V1) V1, 0)) == (unitspace(V1) V1)
464+
@test_throws BoundsError insertleftunit(one(V1) V1, 0)
465465
end
466466
end
467467

0 commit comments

Comments
 (0)