Skip to content

Commit

Permalink
Circumvent @constprop in Julia 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Apr 10, 2024
1 parent 307a89d commit 56d9bf1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/auxiliary/auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ function _kron(A, B)
end
return C
end

# Compat implementation:
@static if VERSION < v"1.7"
macro constprop(setting, ex)
return esc(ex)
end
else
using Base: @constprop
end
6 changes: 3 additions & 3 deletions src/tensors/indexmanipulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ If `copy=false`, `tdst` might share data with `tsrc` whenever possible. Otherwis
To repartition into an existing destination, see [repartition!](@ref).
"""
Base.@constprop :aggressive function repartition(t::AbstractTensorMap, N₁::Int,
N₂::Int=numind(t) - N₁;
copy::Bool=false)
@constprop :aggressive function repartition(t::AbstractTensorMap, N₁::Int,
N₂::Int=numind(t) - N₁;
copy::Bool=false)
N₁ + N₂ == numind(t) ||
throw(ArgumentError("Invalid repartition: $(numind(t)) to ($N₁, $N₂)"))
all_inds = (codomainind(t)..., reverse(domainind(t))...)
Expand Down
3 changes: 2 additions & 1 deletion test/tensors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ for V in spacelist
@test dot(t2′, t2) dot(t′, t) dot(transpose(t2′), transpose(t2))
end

t3 = @constinferred repartition(t, $k)
t3 = VERSION < v"1.7" ? repartition(t, k) :
@constinferred repartition(t, $k)
@test norm(t3) norm(t)
t3′ = @constinferred repartition!(similar(t3), t′)
@test norm(t3′) norm(t′)
Expand Down

0 comments on commit 56d9bf1

Please sign in to comment.