Skip to content

Commit d68b119

Browse files
committed
Make static_length support StaticArrays
1 parent d780060 commit d68b119

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterface"
22
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
3-
version = "2.14.11"
3+
version = "2.14.12"
44

55
[deps]
66
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/ArrayInterface.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ function __init__()
790790
known_first(::Type{<:StaticArrays.SOneTo}) = 1
791791
known_last(::Type{StaticArrays.SOneTo{N}}) where {N} = N
792792
known_length(::Type{StaticArrays.SOneTo{N}}) where {N} = N
793+
known_length(::Type{StaticArrays.Length{L}}) where {L} = L
794+
known_length(::Type{A}) where {A <: StaticArrays.StaticArray} = known_length(StaticArrays.Length(A))
793795

794796
device(::Type{<:StaticArrays.MArray}) = CPUPointer()
795797
contiguous_axis(::Type{<:StaticArrays.StaticArray}) = Contiguous{1}()

test/runtests.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,13 +508,20 @@ end
508508
@test ArrayInterface.known_length((1,)) == 1
509509
@test ArrayInterface.known_length((a=1,b=2)) == 2
510510
@test ArrayInterface.known_length([]) == nothing
511-
511+
512512
x = view(SArray{Tuple{3,3,3}}(ones(3,3,3)), :, SOneTo(2), 2)
513513
@test @inferred(ArrayInterface.known_length(x)) == 6
514514
@test @inferred(ArrayInterface.known_length(x')) == 6
515515

516516
itr = StaticInt(1):StaticInt(10)
517517
@inferred(ArrayInterface.known_length((i for i in itr))) == 10
518+
519+
v = @SVector rand(8);
520+
A = @MMatrix rand(7,6);
521+
T = SizedArray{Tuple{5,4,3}}(zeros(5,4,3));
522+
@test @inferred(ArrayInterface.static_length(v)) === StaticInt(8)
523+
@test @inferred(ArrayInterface.static_length(A)) === StaticInt(42)
524+
@test @inferred(ArrayInterface.static_length(T)) === StaticInt(60)
518525
end
519526

520527
@testset "indices" begin

0 commit comments

Comments
 (0)