Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define compute_itspace if it is not defined #106

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/algorithms/SMS_EMOA/calc-hv.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Loading