|
| 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 | + |
1 | 20 | function sortslicesperm(A::AbstractArray; dims::Union{Integer, Tuple{Vararg{Integer}}}, kws...)
|
2 | 21 | _sortslicesperm(A, Val{dims}(); kws...)
|
3 | 22 | end
|
4 | 23 |
|
5 | 24 | function _sortslicesperm(A::AbstractArray, d::Val{dims}; kws...) where dims
|
6 |
| - itspace = Base.compute_itspace(A, d) |
| 25 | + itspace = compute_itspace(A, d) |
7 | 26 | vecs = map(its->view(A, its...), itspace)
|
8 | 27 | p = sortperm(vecs; kws...)
|
9 | 28 | if ndims(A) == 2 && isa(dims, Integer) && isa(A, Array)
|
|
0 commit comments