Skip to content

Commit c6be240

Browse files
committed
eliminate turing machines from more array functions
1 parent f64b5ec commit c6be240

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

base/abstractarray.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1668,15 +1668,15 @@ end
16681668
function _sub2ind!(Iout, inds, Iinds, I)
16691669
@_noinline_meta
16701670
for i in Iinds
1671-
# Iout[i] = sub2ind(inds, map(Ij->Ij[i], I)...)
1671+
# Iout[i] = sub2ind(inds, map(Ij -> Ij[i], I)...)
16721672
Iout[i] = sub2ind_vec(inds, i, I)
16731673
end
16741674
Iout
16751675
end
16761676

1677-
sub2ind_vec(inds, i, I) = (@_inline_meta; _sub2ind_vec(inds, (), i, I...))
1678-
_sub2ind_vec(inds, out, i, I1, I...) = (@_inline_meta; _sub2ind_vec(inds, (out..., I1[i]), i, I...))
1679-
_sub2ind_vec(inds, out, i) = (@_inline_meta; sub2ind(inds, out...))
1677+
sub2ind_vec(inds, i, I) = (@_inline_meta; sub2ind(inds, _sub2ind_vec(i, I...)...))
1678+
_sub2ind_vec(i, I1, I...) = (@_inline_meta; (I1[i], _sub2ind_vec(i, I...)...))
1679+
_sub2ind_vec(i) = ()
16801680

16811681
function ind2sub(inds::Union{DimsInteger{N},Indices{N}}, ind::AbstractVector{<:Integer}) where N
16821682
M = length(ind)

base/permuteddimsarray.jl

+1-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ end
7474
val
7575
end
7676

77-
# For some reason this is faster than ntuple(d->I[perm[d]], Val{N}) (#15276?)
78-
@inline genperm(I::NTuple{N,Any}, perm::Dims{N}) where {N} = _genperm((), I, perm...)
79-
_genperm(out, I) = out
80-
@inline _genperm(out, I, p, perm...) = _genperm((out..., I[p]), I, perm...)
77+
@inline genperm(I::NTuple{N,Any}, perm::Dims{N}) where {N} = ntuple(d -> I[perm[d]], Val{N})
8178
@inline genperm(I, perm::AbstractVector{Int}) = genperm(I, (perm...,))
8279

8380
"""

base/reshapedarray.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ parentindexes(A::ReshapedArray) = map(s->1:s, size(parent(A)))
167167
reinterpret(::Type{T}, A::ReshapedArray, dims::Dims) where {T} = reinterpret(T, parent(A), dims)
168168

169169
@inline ind2sub_rs(::Tuple{}, i::Int) = i
170-
@inline ind2sub_rs(strds, i) = ind2sub_rs((), strds, i-1)
171-
@inline ind2sub_rs(out, ::Tuple{}, ind) = (ind+1, out...)
172-
@inline function ind2sub_rs(out, strds, ind)
170+
@inline ind2sub_rs(strds, i) = _ind2sub_rs(strds, i - 1)
171+
@inline _ind2sub_rs(::Tuple{}, ind) = (ind + 1,)
172+
@inline function _ind2sub_rs(strds, ind)
173173
d, r = divrem(ind, strds[1])
174-
ind2sub_rs((d+1, out...), tail(strds), r)
174+
(_ind2sub_rs(tail(strds), r)..., d + 1)
175175
end
176176

177177
@inline function getindex(A::ReshapedArrayLF, index::Int)

0 commit comments

Comments
 (0)