Skip to content

Commit

Permalink
type stability changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Dec 18, 2024
1 parent 2e4a8ce commit cb0e1f2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/auxiliary/auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ function _kron(A, B)
return C
end

@noinline _boundserror(P, i) = throw(BoundsError(P, i))
@noinline _nontrivialspaceerror(P, i) = throw(ArgumentError(lazy"Attempting to remove a non-trivial space $(P[i])"))

Check warning on line 45 in src/auxiliary/auxiliary.jl

View check run for this annotation

Codecov / codecov/patch

src/auxiliary/auxiliary.jl#L44-L45

Added lines #L44 - L45 were not covered by tests

# Compat implementation:
@static if VERSION < v"1.7"
macro constprop(setting, ex)
Expand Down
10 changes: 5 additions & 5 deletions src/spaces/homspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ More specifically, adds a left monoidal unit or its dual.
See also [`insertrightunit`](@ref), [`removeunit`](@ref).
"""
function insertleftunit(W::HomSpace, i::Int=numind(W) + 1;
conj::Bool=false, dual::Bool=false)
@constprop :aggressive function insertleftunit(W::HomSpace, i::Int=numind(W) + 1;
conj::Bool=false, dual::Bool=false)
if i numout(W)
return insertleftunit(codomain(W), i; conj, dual) domain(W)
else
Expand All @@ -199,8 +199,8 @@ More specifically, adds a right monoidal unit or its dual.
See also [`insertleftunit`](@ref), [`removeunit`](@ref).
"""
function insertrightunit(W::HomSpace, i::Int=numind(W);
conj::Bool=false, dual::Bool=false)
@constprop :aggressive function insertrightunit(W::HomSpace, i::Int=numind(W);
conj::Bool=false, dual::Bool=false)
if i numout(W)
return insertrightunit(codomain(W), i; conj, dual) domain(W)
else
Expand All @@ -216,7 +216,7 @@ For this to work, that factor has to be isomorphic to the field of scalars.
This operation undoes the work of [`insertleftunit`](@ref) or [`insertrightunit`](@ref).
"""
function removeunit(P::HomSpace, i::Int)
@constprop :aggressive function removeunit(P::HomSpace, i::Int)
if i numout(P)
return removeunit(codomain(P), i) domain(P)
else
Expand Down
5 changes: 2 additions & 3 deletions src/spaces/productspace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,8 @@ For this to work, that factor has to be isomorphic to the field of scalars.
This operation undoes the work of [`insertunit`](@ref).
"""
function removeunit(P::ProductSpace, i::Int)
1 i length(P) || throw(BoundsError(P, i))
isisomorphic(P[i], oneunit(P[i])) ||
throw(ArgumentError("Attempting to remove a non-trivial space $(P[i])"))
1 i length(P) || _boundserror(P, i)
isisomorphic(P[i], oneunit(P[i])) || _nontrivialspaceerror(P, i)
return ProductSpace{spacetype(P)}(TupleTools.deleteat(P.spaces, i))
end

Expand Down
26 changes: 13 additions & 13 deletions src/tensors/indexmanipulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,19 @@ If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwis
See also [`insertrightunit`](@ref) and [`removeunit`](@ref).
"""
Base.@constprop :aggressive function insertleftunit(t::AbstractTensorMap,
i::Int=numind(t) + 1; copy::Bool=true,
conj::Bool=false, dual::Bool=false)
@constprop :aggressive function insertleftunit(t::AbstractTensorMap,

Check warning on line 306 in src/tensors/indexmanipulations.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/indexmanipulations.jl#L306

Added line #L306 was not covered by tests
i::Int=numind(t) + 1; copy::Bool=true,
conj::Bool=false, dual::Bool=false)
W = insertleftunit(space(t), i; conj, dual)
tdst = similar(t, W)
for (c, b) in blocks(t)
copy!(block(tdst, c), b)
end
return tdst

Check warning on line 314 in src/tensors/indexmanipulations.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/indexmanipulations.jl#L309-L314

Added lines #L309 - L314 were not covered by tests
end
Base.@constprop :aggressive function insertleftunit(t::TensorMap, i::Int=numind(t) + 1;
copy::Bool=false,
conj::Bool=false, dual::Bool=false)
@constprop :aggressive function insertleftunit(t::TensorMap, i::Int=numind(t) + 1;
copy::Bool=false,
conj::Bool=false, dual::Bool=false)
W = insertleftunit(space(t), i; conj, dual)
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
end
Expand All @@ -331,17 +331,17 @@ If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwis
See also [`insertleftunit`](@ref) and [`removeunit`](@ref).
"""
Base.@constprop :aggressive function insertrightunit(t::AbstractTensorMap, i::Int=numind(t);
copy::Bool=true, kwargs...)
@constprop :aggressive function insertrightunit(t::AbstractTensorMap, i::Int=numind(t);

Check warning on line 334 in src/tensors/indexmanipulations.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/indexmanipulations.jl#L334

Added line #L334 was not covered by tests
copy::Bool=true, kwargs...)
W = insertrightunit(space(t), i; kwargs...)
tdst = similar(t, W)
for (c, b) in blocks(t)
copy!(block(tdst, c), b)
end
return tdst

Check warning on line 341 in src/tensors/indexmanipulations.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/indexmanipulations.jl#L336-L341

Added lines #L336 - L341 were not covered by tests
end
Base.@constprop :aggressive function insertrightunit(t::TensorMap, i::Int=numind(t);
copy::Bool=false, kwargs...)
@constprop :aggressive function insertrightunit(t::TensorMap, i::Int=numind(t);
copy::Bool=false, kwargs...)
W = insertrightunit(space(t), i; kwargs...)
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
end
Expand All @@ -356,12 +356,12 @@ If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwis
This operation undoes the work of [`insertunit`](@ref).
"""
Base.@constprop :aggressive function removeunit(t::TensorMap, i::Int; copy::Bool=false)
@constprop :aggressive function removeunit(t::TensorMap, i::Int; copy::Bool=false)
W = removeunit(space(t), i)
return TensorMap{scalartype(t)}(copy ? Base.copy(t.data) : t.data, W)
end
Base.@constprop :aggressive function removeunit(t::AbstractTensorMap, i::Int;
copy::Bool=true)
@constprop :aggressive function removeunit(t::AbstractTensorMap, i::Int;

Check warning on line 363 in src/tensors/indexmanipulations.jl

View check run for this annotation

Codecov / codecov/patch

src/tensors/indexmanipulations.jl#L363

Added line #L363 was not covered by tests
copy::Bool=true)
W = removeunit(space(t), i)
tdst = similar(t, W)
for (c, b) in blocks(t)
Expand Down

0 comments on commit cb0e1f2

Please sign in to comment.