Skip to content

Commit 3de6dbb

Browse files
committed
improve type stability
1 parent 75be0d7 commit 3de6dbb

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/tensors/indexmanipulations.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,11 +308,12 @@ If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwis
308308

309309
This operation undoes the work of [`insertunit`](@ref).
310310
"""
311-
function removeunit(t::TensorMap, i::Int; copy::Bool=false)
311+
Base.@constprop :aggressive function removeunit(t::TensorMap, i::Int; copy::Bool=false)
312312
W = removeunit(space(t), i)
313313
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
314314
end
315-
function removeunit(t::AbstractTensorMap, i::Int=numind(t) + 1; copy::Bool=true)
315+
Base.@constprop :aggressive function removeunit(t::AbstractTensorMap, i::Int;
316+
copy::Bool=true)
316317
W = removeunit(space(t), i)
317318
tdst = similar(t, W)
318319
for (c, b) in blocks(t)

test/spaces.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ println("------------------------------------")
422422
@test permute(W, ((2, 4, 5), (3, 1))) == (V2 ⊗ V4' V5' ← V3 ⊗ V1')
423423
@test (V1 V2 V1 V2) == @constinferred TensorKit.compose(W, W')
424424
@test @constinferred(insertunit(W)) == (V1 ⊗ V2 ← V3 ⊗ V4 ⊗ V5 ⊗ oneunit(V5))
425-
@test @constinferred(removeunit(insertunit(W), numind(W) + 1)) == W
425+
@test @constinferred(removeunit(insertunit(W), $(numind(W) + 1))) == W
426426
@test @constinferred(insertunit(W; conj=true)) == (V1 ⊗ V2 ←
427427
V3 ⊗ V4 ⊗ V5 ⊗ oneunit(V5)')
428428
@test @constinferred(insertunit(W, 1)) == (oneunit(V1) V1 V2 V3 V4 V5)

test/tensors.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ for V in spacelist
182182
@test space(t2) == insertunit(space(t))
183183
@test scalartype(t2) === T
184184
@test t.data === t2.data
185-
@test @constinferred(removeunit(t2, numind(t2))) == t
185+
@test @constinferred(removeunit(t2, $(numind(t2)))) == t
186186
t3 = @constinferred insertunit(t; copy=true)
187187
@test t.data !== t3.data
188188
for (c, b) in blocks(t)
189189
@test b == block(t3, c)
190190
end
191-
@test @constinferred(removeunit(t3, numind(t3))) == t
191+
@test @constinferred(removeunit(t3, $(numind(t3)))) == t
192192
t4 = @constinferred insertunit(t, 4; dual=true)
193193
@test numin(t4) == numin(t) && numout(t4) == numout(t) + 1
194194
for (c, b) in blocks(t)

0 commit comments

Comments
 (0)