Skip to content

Commit 5dbfaef

Browse files
authored
define compute_itspace if it is not defined
1 parent 9aacebe commit 5dbfaef

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/algorithms/SMS_EMOA/calc-hv.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1+
#in julia 1.11 and above, compute_itspace was removed.
2+
if isdefined(Base,:compute_itspace)
3+
compute_itspace(A,v) = Base.compute_itspace(A,v)
4+
else
5+
# Works around inference's lack of ability to recognize partial constness
6+
struct DimSelector{dims, T}
7+
A::T
8+
end
9+
10+
DimSelector{dims}(x::T) where {dims, T} = DimSelector{dims, T}(x)
11+
(ds::DimSelector{dims, T})(i) where {dims, T} = i in dims ? axes(ds.A, i) : (:,)
12+
13+
function compute_itspace(A, ::Val{dims}) where {dims}
14+
negdims = filter(i->!(i in dims), 1:ndims(A))
15+
axs = Iterators.product(ntuple(DimSelector{dims}(A), ndims(A))...)
16+
vec(permutedims(collect(axs), (dims..., negdims...)))
17+
end
18+
end
19+
120
function sortslicesperm(A::AbstractArray; dims::Union{Integer, Tuple{Vararg{Integer}}}, kws...)
221
_sortslicesperm(A, Val{dims}(); kws...)
322
end
423

524
function _sortslicesperm(A::AbstractArray, d::Val{dims}; kws...) where dims
6-
itspace = Base.compute_itspace(A, d)
25+
itspace = compute_itspace(A, d)
726
vecs = map(its->view(A, its...), itspace)
827
p = sortperm(vecs; kws...)
928
if ndims(A) == 2 && isa(dims, Integer) && isa(A, Array)

0 commit comments

Comments
 (0)