Skip to content

Commit 67c737c

Browse files
committed
Use sized based mi to speedup sequential access of ReshapedArray
Update reshapedarray.jl
1 parent 7cd1da3 commit 67c737c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

base/reshapedarray.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ _reshape(R::ReshapedArray, dims::Dims) = _reshape(R.parent, dims)
188188

189189
function __reshape(p::Tuple{AbstractArray,IndexStyle}, dims::Dims)
190190
parent = p[1]
191-
strds = front(size_to_strides(map(length, axes(parent))..., 1))
192-
strds1 = map(s->max(1,Int(s)), strds) # for resizing empty arrays
193-
mi = map(SignedMultiplicativeInverse, strds1)
194-
ReshapedArray(parent, dims, reverse(mi))
191+
szs = front(size(parent))
192+
szs1 = map(s->max(1,Int(s)), szs) # for resizing empty arrays
193+
mi = map(SignedMultiplicativeInverse, szs1)
194+
ReshapedArray(parent, dims, mi)
195195
end
196196

197197
function __reshape(p::Tuple{AbstractArray{<:Any,0},IndexCartesian}, dims::Dims)
@@ -216,11 +216,11 @@ unaliascopy(A::ReshapedArray) = typeof(A)(unaliascopy(A.parent), A.dims, A.mi)
216216
dataids(A::ReshapedArray) = dataids(A.parent)
217217

218218
@inline ind2sub_rs(ax, ::Tuple{}, i::Int) = (i,)
219-
@inline ind2sub_rs(ax, strds, i) = _ind2sub_rs(ax, strds, i - 1)
219+
@inline ind2sub_rs(ax, szs, i) = _ind2sub_rs(ax, szs, i - 1)
220220
@inline _ind2sub_rs(ax, ::Tuple{}, ind) = (ind + first(ax[end]),)
221-
@inline function _ind2sub_rs(ax, strds, ind)
222-
d, r = divrem(ind, strds[1])
223-
(_ind2sub_rs(front(ax), tail(strds), r)..., d + first(ax[end]))
221+
@inline function _ind2sub_rs(ax, szs, ind)
222+
d, r = divrem(ind, szs[1])
223+
(r + first(ax[1]), _ind2sub_rs(tail(ax), tail(szs), d)...)
224224
end
225225
offset_if_vec(i::Integer, axs::Tuple{<:AbstractUnitRange}) = i + first(axs[1]) - 1
226226
offset_if_vec(i::Integer, axs::Tuple) = i

0 commit comments

Comments
 (0)