Skip to content

Commit efe40e1

Browse files
committed
add where and tests.
1 parent 33b8433 commit efe40e1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/stridelayout.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,12 @@ end
268268

269269
@inline size(B::Union{Transpose{T,A},Adjoint{T,A}}) where {T,A<:AbstractMatrix{T}} = permute(size(parent(B)), Val{(2,1)}())
270270
@inline size(B::PermutedDimsArray{T,N,I1,I2,A}) where {T,N,I1,I2,A<:AbstractArray{T,N}} = permute(size(parent(B)), Val{I1}())
271-
@inline size(A::AbstractArray, ::Static{N}) = size(A)[N]
272-
@inline size(A::AbstractArray, ::Val{N}) = size(A)[N]
271+
@inline size(A::AbstractArray, ::Static{N}) where {N} = size(A)[N]
272+
@inline size(A::AbstractArray, ::Val{N}) where {N} = size(A)[N]
273273
@inline strides(B::Union{Transpose{T,A},Adjoint{T,A}}) where {T,A<:AbstractMatrix{T}} = permute(strides(parent(B)), Val{(2,1)}())
274274
@inline strides(B::PermutedDimsArray{T,N,I1,I2,A}) where {T,N,I1,I2,A<:AbstractArray{T,N}} = permute(strides(parent(B)), Val{I1}())
275-
@inline stride(A::AbstractArray, ::Static{N}) = stride(A)[N]
276-
@inline stride(A::AbstractArray, ::Val{N}) = stride(A)[N]
275+
@inline stride(A::AbstractArray, ::Static{N}) where {N} = strides(A)[N]
276+
@inline stride(A::AbstractArray, ::Val{N}) where {N} = strides(A)[N]
277277

278278
size(B::S) where {N,NP,T,A<:AbstractArray{T,NP},I,S <: SubArray{T,N,A,I}} = _size(size(parent(B)), B.indices, map(static_length, B.indices))
279279
strides(B::S) where {N,NP,T,A<:AbstractArray{T,NP},I,S <: SubArray{T,N,A,I}} = _strides(strides(parent(B)), B.indices)

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ using OffsetArrays
290290
@test @inferred(ArrayInterface.size(S)) == size(S)
291291
@test @inferred(ArrayInterface.size(Sp)) == size(Sp)
292292
@test @inferred(ArrayInterface.size(Sp2)) == size(Sp2)
293+
@test @inferred(ArrayInterface.size(Sp2, Static(1))) === 2
294+
@test @inferred(ArrayInterface.size(Sp2, Static(2))) === Static(3)
295+
@test @inferred(ArrayInterface.size(Sp2, Static(3))) === Static(2)
293296

294297
@test @inferred(ArrayInterface.size(M)) === (Static(2), Static(3), Static(4))
295298
@test @inferred(ArrayInterface.size(Mp)) === (Static(3), Static(4))
@@ -306,6 +309,9 @@ using OffsetArrays
306309
@test @inferred(ArrayInterface.strides(S)) === (Static(1), Static(2), Static(6))
307310
@test @inferred(ArrayInterface.strides(Sp)) === (Static(6), Static(1), Static(2))
308311
@test @inferred(ArrayInterface.strides(Sp2)) === (Static(6), Static(2), Static(1))
312+
@test @inferred(ArrayInterface.stride(Sp2, Static(1))) === Static(6)
313+
@test @inferred(ArrayInterface.stride(Sp2, Static(2))) === Static(2)
314+
@test @inferred(ArrayInterface.stride(Sp2, Static(3))) === Static(1)
309315

310316
@test @inferred(ArrayInterface.strides(M)) === (Static(1), Static(2), Static(6))
311317
@test @inferred(ArrayInterface.strides(Mp)) === (Static(2), Static(6))

0 commit comments

Comments
 (0)