From 5dbfaef485cbaf90219a00da10c3909fbd9db48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Riedemann?= <38795484+longemen3000@users.noreply.github.com> Date: Sat, 2 Mar 2024 21:01:45 -0300 Subject: [PATCH] define `compute_itspace` if it is not defined --- src/algorithms/SMS_EMOA/calc-hv.jl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/algorithms/SMS_EMOA/calc-hv.jl b/src/algorithms/SMS_EMOA/calc-hv.jl index cd7c723b..1a1aef50 100644 --- a/src/algorithms/SMS_EMOA/calc-hv.jl +++ b/src/algorithms/SMS_EMOA/calc-hv.jl @@ -1,9 +1,28 @@ +#in julia 1.11 and above, compute_itspace was removed. +if isdefined(Base,:compute_itspace) + compute_itspace(A,v) = Base.compute_itspace(A,v) +else + # Works around inference's lack of ability to recognize partial constness + struct DimSelector{dims, T} + A::T + end + + DimSelector{dims}(x::T) where {dims, T} = DimSelector{dims, T}(x) + (ds::DimSelector{dims, T})(i) where {dims, T} = i in dims ? axes(ds.A, i) : (:,) + + function compute_itspace(A, ::Val{dims}) where {dims} + negdims = filter(i->!(i in dims), 1:ndims(A)) + axs = Iterators.product(ntuple(DimSelector{dims}(A), ndims(A))...) + vec(permutedims(collect(axs), (dims..., negdims...))) + end +end + function sortslicesperm(A::AbstractArray; dims::Union{Integer, Tuple{Vararg{Integer}}}, kws...) _sortslicesperm(A, Val{dims}(); kws...) end function _sortslicesperm(A::AbstractArray, d::Val{dims}; kws...) where dims - itspace = Base.compute_itspace(A, d) + itspace = compute_itspace(A, d) vecs = map(its->view(A, its...), itspace) p = sortperm(vecs; kws...) if ndims(A) == 2 && isa(dims, Integer) && isa(A, Array)