@@ -14,44 +14,62 @@ using StaticArrays
14
14
using Test
15
15
16
16
@testset " StaticArrays" begin
17
- @test isone (ArrayInterface. known_first (typeof (StaticArrays. SOneTo (7 ))))
18
- @test ArrayInterface. known_last (typeof (StaticArrays. SOneTo (7 ))) == 7
19
- @test ArrayInterface. known_length (typeof (StaticArrays. SOneTo (7 ))) == 7
17
+ x = @SVector [1 ,2 ,3 ]
18
+ @test ArrayInterfaceCore. ismutable (x) == false
19
+ @test ArrayInterfaceCore. ismutable (view (x, 1 : 2 )) == false
20
+ @test ArrayInterfaceCore. can_setindex (typeof (x)) == false
21
+ @test ArrayInterfaceCore. buffer (x) == x. data
22
+ @test @inferred (ArrayInterfaceCore. device (typeof (x))) === ArrayInterfaceCore. CPUTuple ()
23
+
24
+ x = @MVector [1 ,2 ,3 ]
25
+ @test ArrayInterfaceCore. ismutable (x) == true
26
+ @test ArrayInterfaceCore. ismutable (view (x, 1 : 2 )) == true
27
+ @test @inferred (ArrayInterfaceCore. device (typeof (x))) === ArrayInterfaceCore. CPUPointer ()
28
+
29
+ A = @SMatrix (randn (5 , 5 ))
30
+ @test lu_instance (A) isa typeof (lu (A))
31
+ A = @MMatrix (randn (5 , 5 ))
32
+ @test lu_instance (A) isa typeof (lu (A))
33
+
34
+ @test isone (ArrayInterfaceCore. known_first (typeof (StaticArrays. SOneTo (7 ))))
35
+ @test ArrayInterfaceCore. known_last (typeof (StaticArrays. SOneTo (7 ))) == 7
36
+ @test ArrayInterfaceCore. known_length (typeof (StaticArrays. SOneTo (7 ))) == 7
20
37
21
38
@test parent_type (SizedVector{1 , Int, Vector{Int}}) <: Vector{Int}
22
- @test ArrayInterface . known_length (@inferred (ArrayInterface . indices (SOneTo (7 )))) == 7
39
+ @test ArrayInterfaceCore . known_length (@inferred (ArrayInterfaceCore . indices (SOneTo (7 )))) == 7
23
40
24
41
x = view (SArray {Tuple{3,3,3}} (ones (3 ,3 ,3 )), :, SOneTo (2 ), 2 )
25
- @test @inferred (ArrayInterface . known_length (x)) == 6
26
- @test @inferred (ArrayInterface . known_length (x' )) == 6
42
+ @test @inferred (ArrayInterfaceCore . known_length (x)) == 6
43
+ @test @inferred (ArrayInterfaceCore . known_length (x' )) == 6
27
44
28
45
v = @SVector rand (8 );
29
46
A = @MMatrix rand (7 , 6 );
30
47
T = SizedArray {Tuple{5,4,3}} (zeros (5 ,4 ,3 ));
31
- @test @inferred (ArrayInterface. length (v)) === StaticInt (8 )
32
- @test @inferred (ArrayInterface. length (A)) === StaticInt (42 )
33
- @test @inferred (ArrayInterface. length (T)) === StaticInt (60 )
48
+ @test @inferred (ArrayInterfaceCore. length (v)) === StaticInt (8 )
49
+ @test @inferred (ArrayInterfaceCore. length (A)) === StaticInt (42 )
50
+ @test @inferred (ArrayInterfaceCore. length (T)) === StaticInt (60 )
51
+
52
+ x = @SMatrix rand (Float32, 2 , 2 )
53
+ y = @SVector rand (4 )
54
+ yr = ArrayInterfaceCore. restructure (x, y)
55
+ @test yr isa SMatrix{2 , 2 }
56
+ @test Base. size (yr) == (2 ,2 )
57
+ @test vec (yr) == vec (y)
58
+ z = rand (4 )
59
+ zr = ArrayInterfaceCore. restructure (x, z)
60
+ @test zr isa SMatrix{2 , 2 }
61
+ @test Base. size (zr) == (2 ,2 )
62
+ @test vec (zr) == vec (z)
34
63
35
- A = @SMatrix (randn (5 , 5 ))
36
- @test lu_instance (A) isa typeof (lu (A))
37
- A = @MMatrix (randn (5 , 5 ))
38
- @test lu_instance (A) isa typeof (lu (A))
39
64
Am = @MMatrix rand (2 ,10 );
40
- @test @inferred (ArrayInterface . strides (view (Am,1 ,:))) === (StaticInt (2 ),)
65
+ @test @inferred (ArrayInterfaceCore . strides (view (Am,1 ,:))) === (StaticInt (2 ),)
41
66
42
- @test @inferred (contiguous_axis (@SArray (zeros (2 ,2 ,2 )))) === ArrayInterface . StaticInt (1 )
43
- @test @inferred (ArrayInterface . contiguous_axis_indicator (@SArray (zeros (2 ,2 ,2 )))) == (true ,false ,false )
44
- @test @inferred (contiguous_batch_size (@SArray (zeros (2 ,2 ,2 )))) === ArrayInterface . StaticInt (0 )
67
+ @test @inferred (contiguous_axis (@SArray (zeros (2 ,2 ,2 )))) === ArrayInterfaceCore . StaticInt (1 )
68
+ @test @inferred (ArrayInterfaceCore . contiguous_axis_indicator (@SArray (zeros (2 ,2 ,2 )))) == (true ,false ,false )
69
+ @test @inferred (contiguous_batch_size (@SArray (zeros (2 ,2 ,2 )))) === ArrayInterfaceCore . StaticInt (0 )
45
70
@test @inferred (stride_rank (@SArray (zeros (2 ,2 ,2 )))) == (1 , 2 , 3 )
46
- @test @inferred (ArrayInterface . is_column_major (@SArray (zeros (2 ,2 ,2 )))) === True ()
71
+ @test @inferred (ArrayInterfaceCore . is_column_major (@SArray (zeros (2 ,2 ,2 )))) === True ()
47
72
@test @inferred (dense_dims (@SArray (zeros (2 ,2 ,2 )))) == (true ,true ,true )
48
-
49
- x = @SVector [1 ,2 ,3 ]
50
- @test ArrayInterfaceCore. ismutable (x) == false
51
- @test ArrayInterfaceCore. ismutable (view (x, 1 : 2 )) == false
52
- x = @MVector [1 ,2 ,3 ]
53
- @test ArrayInterfaceCore. ismutable (x) == true
54
- @test ArrayInterfaceCore. ismutable (view (x, 1 : 2 )) == true
55
73
end
56
74
57
75
@testset " BandedMatrices" begin
66
84
B[band (2 )]. = [5 ,6 ,7 ,8 ]
67
85
rowind,colind= findstructralnz (B)
68
86
@test [B[rowind[i],colind[i]] for i in 1 : length (rowind)]== [5 ,6 ,7 ,8 ,1 ,2 ,3 ,4 ]
87
+ @test ArrayInterfaceCore. isstructured (typeof (B))
88
+ @test ArrayInterfaceCore. fast_matrix_colors (typeof (B))
69
89
end
70
90
71
91
@testset " BlockBandedMatrices" begin
78
98
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
79
99
1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,1 ,
80
100
1 ,1 ,1 ,1 ,1 ]
101
+ @test ArrayInterfaceCore. isstructured (typeof (BB))
102
+ @test has_sparsestruct (typeof (BB))
103
+ @test ArrayInterfaceCore. fast_matrix_colors (typeof (BB))
81
104
82
105
dense= collect (Ones (8 ,8 ))
83
106
for i in 1 : 8
88
111
@test [BBB[rowind[i],colind[i]] for i in 1 : length (rowind)]==
89
112
[1 ,2 ,3 ,1 ,2 ,3 ,4 ,2 ,3 ,4 ,5 ,6 ,7 ,5 ,6 ,7 ,8 ,6 ,7 ,8 ,
90
113
1 ,2 ,3 ,1 ,2 ,3 ,4 ,2 ,3 ,4 ,5 ,6 ,7 ,5 ,6 ,7 ,8 ,6 ,7 ,8 ]
114
+ @test ArrayInterfaceCore. isstructured (typeof (BBB))
115
+ @test has_sparsestruct (typeof (BBB))
116
+ @test ArrayInterfaceCore. fast_matrix_colors (typeof (BBB))
91
117
end
92
118
93
119
@testset " OffsetArrays" begin
120
+ A = zeros (3 , 4 , 5 );
94
121
O = OffsetArray (A, 3 , 7 , 10 );
95
122
Op = PermutedDimsArray (O,(3 ,1 ,2 ));
96
- @test @inferred (ArrayInterface . offsets (O)) === (4 , 8 , 11 )
97
- @test @inferred (ArrayInterface . offsets (Op)) === (11 , 4 , 8 )
123
+ @test @inferred (ArrayInterfaceCore . offsets (O)) === (4 , 8 , 11 )
124
+ @test @inferred (ArrayInterfaceCore . offsets (Op)) === (11 , 4 , 8 )
98
125
99
- @test @inferred (ArrayInterface . offsets ((1 ,2 ,3 ))) === (StaticInt (1 ),)
126
+ @test @inferred (ArrayInterfaceCore . offsets ((1 ,2 ,3 ))) === (StaticInt (1 ),)
100
127
o = OffsetArray (vec (A), 8 );
101
- @test @inferred (ArrayInterface . offset1 (o)) === 9
128
+ @test @inferred (ArrayInterfaceCore . offset1 (o)) === 9
102
129
103
- @test @inferred (device (OffsetArray (view (PermutedDimsArray (A, (3 ,1 ,2 )), 1 , :, 2 : 4 )' , 3 , - 173 ))) === ArrayInterface . CPUPointer ()
104
- @test @inferred (device (view (OffsetArray (A,2 ,3 ,- 12 ), 4 , :, - 11 : - 9 ))) === ArrayInterface . CPUPointer ()
105
- @test @inferred (device (view (OffsetArray (A,2 ,3 ,- 12 ), 3 , :, [- 11 ,- 10 ,- 9 ])' )) === ArrayInterface . CPUIndex ()
130
+ @test @inferred (device (OffsetArray (view (PermutedDimsArray (A, (3 ,1 ,2 )), 1 , :, 2 : 4 )' , 3 , - 173 ))) === ArrayInterfaceCore . CPUPointer ()
131
+ @test @inferred (device (view (OffsetArray (A,2 ,3 ,- 12 ), 4 , :, - 11 : - 9 ))) === ArrayInterfaceCore . CPUPointer ()
132
+ @test @inferred (device (view (OffsetArray (A,2 ,3 ,- 12 ), 3 , :, [- 11 ,- 10 ,- 9 ])' )) === ArrayInterfaceCore . CPUIndex ()
106
133
107
- @test @inferred (ArrayInterface . indices (OffsetArray (view (PermutedDimsArray (A, (3 ,1 ,2 )), 1 , :, 2 : 4 )' , 3 , - 173 ),1 )) === Base. Slice (ArrayInterface . OptionallyStaticUnitRange (4 ,6 ))
108
- @test @inferred (ArrayInterface . indices (OffsetArray (view (PermutedDimsArray (A, (3 ,1 ,2 )), 1 , :, 2 : 4 )' , 3 , - 173 ),2 )) === Base. Slice (ArrayInterface . OptionallyStaticUnitRange (- 172 ,- 170 ))
134
+ @test @inferred (ArrayInterfaceCore . indices (OffsetArray (view (PermutedDimsArray (A, (3 ,1 ,2 )), 1 , :, 2 : 4 )' , 3 , - 173 ),1 )) === Base. Slice (ArrayInterfaceCore . OptionallyStaticUnitRange (4 ,6 ))
135
+ @test @inferred (ArrayInterfaceCore . indices (OffsetArray (view (PermutedDimsArray (A, (3 ,1 ,2 )), 1 , :, 2 : 4 )' , 3 , - 173 ),2 )) === Base. Slice (ArrayInterfaceCore . OptionallyStaticUnitRange (- 172 ,- 170 ))
109
136
110
- @test @inferred (device (OffsetArray (@SArray (zeros (2 ,2 ,2 )),- 123 ,29 ,3231 ))) === ArrayInterface . CPUTuple ()
111
- @test @inferred (device (OffsetArray (@view (@SArray (zeros (2 ,2 ,2 ))[1 ,1 : 2 ,:]),- 3 ,4 ))) === ArrayInterface . CPUTuple ()
112
- @test @inferred (device (OffsetArray (@MArray (zeros (2 ,2 ,2 )),8 ,- 2 ,- 5 ))) === ArrayInterface . CPUPointer ()
137
+ @test @inferred (device (OffsetArray (@SArray (zeros (2 ,2 ,2 )),- 123 ,29 ,3231 ))) === ArrayInterfaceCore . CPUTuple ()
138
+ @test @inferred (device (OffsetArray (@view (@SArray (zeros (2 ,2 ,2 ))[1 ,1 : 2 ,:]),- 3 ,4 ))) === ArrayInterfaceCore . CPUTuple ()
139
+ @test @inferred (device (OffsetArray (@MArray (zeros (2 ,2 ,2 )),8 ,- 2 ,- 5 ))) === ArrayInterfaceCore . CPUPointer ()
113
140
end
114
141
0 commit comments