Skip to content

Commit f64b5ec

Browse files
committed
eliminate turing machine from size_strides
1 parent f9fd549 commit f64b5ec

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

base/abstractarray.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,11 @@ julia> strides(A)
202202
(1, 3, 12)
203203
```
204204
"""
205-
strides(A::AbstractArray) = _strides((1,), A)
206-
_strides(out::Tuple{Int}, A::AbstractArray{<:Any,0}) = ()
207-
_strides(out::NTuple{N,Int}, A::AbstractArray{<:Any,N}) where {N} = out
208-
function _strides(out::NTuple{M,Int}, A::AbstractArray) where M
209-
@_inline_meta
210-
_strides((out..., out[M]*size(A, M)), A)
211-
end
205+
strides(A::AbstractArray) = size_to_strides(1, size(A)...)
206+
@inline size_to_strides(s, d, sz...) = (s, size_to_strides(s * d, sz...)...)
207+
size_to_strides(s, d) = (s,)
208+
size_to_strides(s) = ()
209+
212210

213211
function isassigned(a::AbstractArray, i::Int...)
214212
try

base/reshapedarray.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ _reshape(R::ReshapedArray, dims::Dims) = _reshape(R.parent, dims)
148148

149149
function __reshape(p::Tuple{AbstractArray,IndexCartesian}, dims::Dims)
150150
parent = p[1]
151-
strds = front(size_strides(parent))
151+
strds = front(size_to_strides(size(parent)..., 1))
152152
strds1 = map(s->max(1,s), strds) # for resizing empty arrays
153153
mi = map(SignedMultiplicativeInverse, strds1)
154154
ReshapedArray(parent, dims, reverse(mi))
@@ -159,10 +159,6 @@ function __reshape(p::Tuple{AbstractArray,IndexLinear}, dims::Dims)
159159
ReshapedArray(parent, dims, ())
160160
end
161161

162-
@inline size_strides(A::AbstractArray) = tail(size_strides((1,), size(A)...))
163-
size_strides(out::Tuple) = out
164-
@inline size_strides(out, s, sz...) = size_strides((out..., out[end]*s), sz...)
165-
166162
size(A::ReshapedArray) = A.dims
167163
similar(A::ReshapedArray, eltype::Type, dims::Dims) = similar(parent(A), eltype, dims)
168164
IndexStyle(::Type{<:ReshapedArrayLF}) = IndexLinear()

0 commit comments

Comments
 (0)