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

Deprecate generic stride implementation (#17812), allow AbstractArrays to use BLAS/LAPACK routines (#25247) #25321

Merged
merged 16 commits into from
Jan 5, 2018
Merged
Show file tree
Hide file tree
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
36 changes: 14 additions & 22 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,46 +219,38 @@ julia> last([1; 2; 3; 4])
last(a) = a[end]

"""
stride(A, k::Integer)
strides(A)

Return the distance in memory (in number of elements) between adjacent elements in dimension `k`.
Return a tuple of the memory strides in each dimension.

# Examples
```jldoctest
julia> A = ones(3,4,5);

julia> stride(A,2)
3

julia> stride(A,3)
12
julia> strides(A)
(1, 3, 12)
```
"""
function stride(a::AbstractArray, i::Integer)
if i > ndims(a)
return length(a)
end
s = 1
for n = 1:(i-1)
s *= size(a, n)
end
return s
end
function strides end

"""
strides(A)
stride(A, k::Integer)

Return a tuple of the memory strides in each dimension.
Return the distance in memory (in number of elements) between adjacent elements in dimension `k`.

# Examples
```jldoctest
julia> A = ones(3,4,5);

julia> strides(A)
(1, 3, 12)
julia> stride(A,2)
3

julia> stride(A,3)
12
```
"""
strides(A::AbstractArray) = size_to_strides(1, size(A)...)
stride(A::AbstractArray, k::Integer) = strides(A)[k]

@inline size_to_strides(s, d, sz...) = (s, size_to_strides(s * d, sz...)...)
size_to_strides(s, d) = (s,)
size_to_strides(s) = ()
Expand Down
16 changes: 16 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3813,6 +3813,21 @@ end
@deprecate getq(F::Factorization) F.Q
end

# Issues #17812 Remove default stride implementation
function strides(a::AbstractArray)
depwarn("""
`strides(a::AbstractArray)` is deprecated for general arrays.
Specialize `strides` for custom array types that have the appropriate representation in memory.
Warning: inappropriately implementing this method for an array type that does not use strided
storage may lead to incorrect results or segfaults.
""", :strides)
size_to_strides(1, size(a)...)
end

@deprecate substrides(s, parent, dim, I::Tuple) substrides(parent, strides(parent), I)

# END 0.7 deprecations

@deprecate lexcmp(x::AbstractArray, y::AbstractArray) cmp(x, y)
@deprecate lexcmp(x::Real, y::Real) cmp(isless, x, y)
@deprecate lexcmp(x::Complex, y::Complex) cmp((real(x),imag(x)), (real(y),imag(y)))
Expand Down Expand Up @@ -3871,6 +3886,7 @@ end

@deprecate findin(a, b) find(occursin(b), a)


# END 0.7 deprecations
# BEGIN 1.0 deprecations

Expand Down
181 changes: 105 additions & 76 deletions base/linalg/blas.jl

Large diffs are not rendered by default.

44 changes: 15 additions & 29 deletions base/linalg/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,21 @@ true
isposdef(A::AbstractMatrix) = ishermitian(A) && isposdef(cholfact(Hermitian(A)))
isposdef(x::Number) = imag(x)==0 && real(x) > 0

"""
stride1(A) -> Int

Return the distance between successive array elements
in dimension 1 in units of element size.

# Examples
```jldoctest
julia> A = [1,2,3,4]
4-element Array{Int64,1}:
1
2
3
4

julia> Base.LinAlg.stride1(A)
1

julia> B = view(A, 2:2:4)
2-element view(::Array{Int64,1}, 2:2:4) with eltype Int64:
2
4

julia> Base.LinAlg.stride1(B)
2
```
"""
stride1(x::Array) = 1
stride1(x::StridedVector) = stride(x, 1)::Int
# the definition of strides for Array{T,N} is tuple() if N = 0, otherwise it is
# a tuple containing 1 and a cumulative product of the first N-1 sizes
# this definition is also used for StridedReshapedArray and StridedReinterpretedArray
# which have the same memory storage as Array
function stride(a::Union{DenseArray,StridedReshapedArray,StridedReinterpretArray}, i::Int)
if i > ndims(a)
return length(a)
end
s = 1
for n = 1:(i-1)
s *= size(a, n)
end
return s
end
strides(a::Union{DenseArray,StridedReshapedArray,StridedReinterpretArray}) = size_to_strides(1, size(a)...)

function norm(x::StridedVector{T}, rx::Union{UnitRange{TI},AbstractRange{TI}}) where {T<:BlasFloat,TI<:Integer}
if minimum(rx) < 1 || maximum(rx) > length(x)
Expand Down
Loading