Skip to content

Commit 925fa54

Browse files
authored
More Clean Up and Tests (#194)
* Remove old "test/ndindex.jl" (was moved to Static.jl previously and should be deleted now) * moved range tests to test/ranges.jl * runtest.jl imports libraries in same place * some issingular methods didn't use the same symbol for function body * and argument (were broken) * Tests for isstructured, issingular, can_setindex
1 parent f8b80d9 commit 925fa54

File tree

7 files changed

+148
-165
lines changed

7 files changed

+148
-165
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 = "3.1.25"
3+
version = "3.1.26"
44

55
[deps]
66
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"

src/ArrayInterface.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Converts an array of structs formulation to a struct of array.
183183
aos_to_soa(x) = x
184184

185185
"""
186-
fast_scalar_indexing(x)
186+
fast_scalar_indexing(::Type{T}) -> Bool
187187
188188
Query whether an array type has fast scalar indexing.
189189
"""
@@ -246,9 +246,9 @@ issingular(A::AbstractSparseMatrix) = !issuccess(lu(A, check = false))
246246
issingular(A::Matrix) = !issuccess(lu(A, check = false))
247247
issingular(A::UniformScaling) = A.λ == 0
248248
issingular(A::Diagonal) = any(iszero, A.diag)
249-
issingular(B::Bidiagonal) = any(iszero, A.dv)
250-
issingular(S::SymTridiagonal) = diaganyzero(iszero, ldlt(S).data)
251-
issingular(T::Tridiagonal) = !issuccess(lu(A, check = false))
249+
issingular(A::Bidiagonal) = any(iszero, A.dv)
250+
issingular(A::SymTridiagonal) = diaganyzero(ldlt(A).data)
251+
issingular(A::Tridiagonal) = !issuccess(lu(A, check = false))
252252
issingular(A::Union{Hermitian,Symmetric}) = diaganyzero(bunchkaufman(A, check = false).LD)
253253
issingular(A::Union{LowerTriangular,UpperTriangular}) = diaganyzero(A.data)
254254
issingular(A::Union{UnitLowerTriangular,UnitUpperTriangular}) = false

test/dimensions.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using ArrayInterface: dimnames
21

32
@testset "dimensions" begin
43

test/indexing.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using ArrayInterface: NDIndex
21

32
@testset "canonical" begin
43
@test @inferred(ArrayInterface.is_canonical(Int)) === static(true)

test/ndindex.jl

Lines changed: 0 additions & 42 deletions
This file was deleted.

test/ranges.jl

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
@testset "Range Interface" begin
3+
@testset "Range Constructors" begin
4+
@test @inferred(StaticInt(1):StaticInt(10)) == 1:10
5+
@test @inferred(StaticInt(1):StaticInt(2):StaticInt(10)) == 1:2:10
6+
@test @inferred(1:StaticInt(2):StaticInt(10)) == 1:2:10
7+
@test @inferred(StaticInt(1):StaticInt(2):10) == 1:2:10
8+
@test @inferred(StaticInt(1):2:StaticInt(10)) == 1:2:10
9+
@test @inferred(1:2:StaticInt(10)) == 1:2:10
10+
@test @inferred(1:StaticInt(2):10) == 1:2:10
11+
@test @inferred(StaticInt(1):2:10) == 1:2:10
12+
@test @inferred(StaticInt(1):UInt(10)) === StaticInt(1):10
13+
@test @inferred(UInt(1):StaticInt(1):StaticInt(10)) === 1:StaticInt(10)
14+
@test @inferred(ArrayInterface.OptionallyStaticUnitRange{Int,Int}(1:10)) == 1:10
15+
@test @inferred(ArrayInterface.OptionallyStaticUnitRange(1:10)) == 1:10
16+
17+
@inferred(ArrayInterface.OptionallyStaticUnitRange(1:10))
18+
19+
@test @inferred(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), static(1), static(1))) == 1:1:1
20+
@test @inferred(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), 1, UInt(10))) == StaticInt(1):1:10
21+
@test @inferred(ArrayInterface.OptionallyStaticStepRange(UInt(1), 1, StaticInt(10))) == StaticInt(1):1:10
22+
@test @inferred(ArrayInterface.OptionallyStaticStepRange(1:10)) == 1:1:10
23+
24+
@test_throws ArgumentError ArrayInterface.OptionallyStaticUnitRange(1:2:10)
25+
@test_throws ArgumentError ArrayInterface.OptionallyStaticUnitRange{Int,Int}(1:2:10)
26+
@test_throws ArgumentError ArrayInterface.OptionallyStaticStepRange(1, 0, 10)
27+
28+
@test @inferred(StaticInt(1):StaticInt(1):StaticInt(10)) === ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10))
29+
@test @inferred(StaticInt(1):StaticInt(1):10) === ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), 10)
30+
@test @inferred(1:StaticInt(1):10) === ArrayInterface.OptionallyStaticUnitRange(1, 10)
31+
@test length(StaticInt{-1}():StaticInt{-1}():StaticInt{-10}()) == 10
32+
33+
@test UnitRange(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10))) === UnitRange(1, 10)
34+
@test UnitRange{Int}(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10))) === UnitRange(1, 10)
35+
36+
@test AbstractUnitRange{Int}(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10))) isa ArrayInterface.OptionallyStaticUnitRange
37+
@test AbstractUnitRange{UInt}(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10))) isa Base.OneTo
38+
@test AbstractUnitRange{UInt}(ArrayInterface.OptionallyStaticUnitRange(StaticInt(2), StaticInt(10))) isa UnitRange
39+
40+
@test @inferred((StaticInt(1):StaticInt(10))[StaticInt(2):StaticInt(3)]) === StaticInt(2):StaticInt(3)
41+
@test @inferred((StaticInt(1):StaticInt(10))[StaticInt(2):3]) === StaticInt(2):3
42+
@test @inferred((StaticInt(1):StaticInt(10))[2:3]) === 2:3
43+
@test @inferred((1:StaticInt(10))[StaticInt(2):StaticInt(3)]) === 2:3
44+
45+
@test -(StaticInt{1}():StaticInt{10}()) === StaticInt{-1}():StaticInt{-1}():StaticInt{-10}()
46+
47+
@test reverse(StaticInt{1}():StaticInt{10}()) === StaticInt{10}():StaticInt{-1}():StaticInt{1}()
48+
@test reverse(StaticInt{1}():StaticInt{2}():StaticInt{9}()) === StaticInt{9}():StaticInt{-2}():StaticInt{1}()
49+
end
50+
51+
@test isnothing(@inferred(ArrayInterface.known_first(typeof(1:4))))
52+
@test isone(@inferred(ArrayInterface.known_first(Base.OneTo(4))))
53+
@test isone(@inferred(ArrayInterface.known_first(typeof(Base.OneTo(4)))))
54+
@test isone(@inferred(ArrayInterface.known_first(typeof(StaticInt(1):2:10))))
55+
56+
@test isnothing(@inferred(ArrayInterface.known_last(1:4)))
57+
@test isnothing(@inferred(ArrayInterface.known_last(typeof(1:4))))
58+
@test isone(@inferred(ArrayInterface.known_last(typeof(StaticInt(-1):StaticInt(2):StaticInt(1)))))
59+
60+
@test isnothing(@inferred(ArrayInterface.known_step(typeof(1:0.2:4))))
61+
@test isone(@inferred(ArrayInterface.known_step(1:4)))
62+
@test isone(@inferred(ArrayInterface.known_step(typeof(1:4))))
63+
@test isone(@inferred(ArrayInterface.known_step(typeof(Base.Slice(1:4)))))
64+
@test isone(@inferred(ArrayInterface.known_step(typeof(view(1:4, 1:2)))))
65+
66+
@testset "length" begin
67+
@test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(1, 0))) == 0
68+
@test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(1, 10))) == 10
69+
@test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), 10))) == 10
70+
@test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(StaticInt(0), 10))) == 11
71+
@test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10)))) == 10
72+
@test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(StaticInt(0), StaticInt(10)))) == 11
73+
74+
@test @inferred(length(StaticInt(1):StaticInt(2):StaticInt(0))) == 0
75+
@test @inferred(length(StaticInt(0):StaticInt(-2):StaticInt(1))) == 0
76+
77+
@test @inferred(ArrayInterface.known_length(typeof(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), 2, 10)))) === nothing
78+
@test @inferred(ArrayInterface.known_length(typeof(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), StaticInt(1), StaticInt(10))))) === 10
79+
@test @inferred(ArrayInterface.known_length(typeof(ArrayInterface.OptionallyStaticStepRange(StaticInt(2), StaticInt(1), StaticInt(10))))) === 9
80+
@test @inferred(ArrayInterface.known_length(typeof(ArrayInterface.OptionallyStaticStepRange(StaticInt(2), StaticInt(2), StaticInt(10))))) === 5
81+
@test @inferred(ArrayInterface.known_length(Int)) === 1
82+
83+
@test @inferred(length(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), 2, 10))) == 5
84+
@test @inferred(length(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), StaticInt(1), StaticInt(10)))) == 10
85+
@test @inferred(length(ArrayInterface.OptionallyStaticStepRange(StaticInt(2), StaticInt(1), StaticInt(10)))) == 9
86+
@test @inferred(length(ArrayInterface.OptionallyStaticStepRange(StaticInt(2), StaticInt(2), StaticInt(10)))) == 5
87+
end
88+
89+
@test @inferred(getindex(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), 10), 1)) == 1
90+
@test @inferred(getindex(ArrayInterface.OptionallyStaticUnitRange(StaticInt(0), 10), 1)) == 0
91+
@test_throws BoundsError getindex(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), 10), 0)
92+
@test_throws BoundsError getindex(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), 2, 10), 0)
93+
@test_throws BoundsError getindex(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), 10), 11)
94+
@test_throws BoundsError getindex(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), 2, 10), 11)
95+
end
96+

0 commit comments

Comments
 (0)