From 56d9bf143286ab5c6561d4035cd5658ce00701a8 Mon Sep 17 00:00:00 2001 From: lkdvos Date: Wed, 10 Apr 2024 10:31:16 +0200 Subject: [PATCH] Circumvent `@constprop` in Julia 1.6 --- src/auxiliary/auxiliary.jl | 9 +++++++++ src/tensors/indexmanipulations.jl | 6 +++--- test/tensors.jl | 3 ++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/auxiliary/auxiliary.jl b/src/auxiliary/auxiliary.jl index f407f968..e8c9445b 100644 --- a/src/auxiliary/auxiliary.jl +++ b/src/auxiliary/auxiliary.jl @@ -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 diff --git a/src/tensors/indexmanipulations.jl b/src/tensors/indexmanipulations.jl index 05f1831b..dccb38a2 100644 --- a/src/tensors/indexmanipulations.jl +++ b/src/tensors/indexmanipulations.jl @@ -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))...) diff --git a/test/tensors.jl b/test/tensors.jl index b6269e35..19a6916a 100644 --- a/test/tensors.jl +++ b/test/tensors.jl @@ -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′)