1
1
function test_indexing (AT)
2
- # TODO : more fine-grained allowscalar within test_indexing
3
- GPUArrays. @allowscalar @testset " indexing" begin
4
- for T in (Float32, Int32)
2
+ @testset " indexing" begin
3
+ @allowscalar @testset " errors and warnings" begin
4
+ x = AT ([0 ])
5
+
6
+ allowscalar (true , false )
7
+ x[1 ] = 1
8
+ @test x[1 ] == 1
9
+
10
+ @disallowscalar begin
11
+ @test_throws ErrorException x[1 ]
12
+ @test_throws ErrorException x[1 ] = 1
13
+ end
14
+
15
+ x[1 ] = 2
16
+ @test x[1 ] == 2
17
+
18
+ allowscalar (false )
19
+ @test_throws ErrorException x[1 ]
20
+ @test_throws ErrorException x[1 ] = 1
21
+
22
+ @allowscalar begin
23
+ x[1 ] = 3
24
+ @test x[1 ] == 3
25
+ end
26
+
27
+ @test_throws ErrorException x[1 ]
28
+ @test_throws ErrorException x[1 ] = 1
29
+
30
+ allowscalar (true , false )
31
+ x[1 ]
32
+
33
+ allowscalar (true , true )
34
+ @test_logs (:warn , r" Performing scalar operations on GPU arrays: .*" ) x[1 ]
35
+ @test_logs x[1 ]
36
+
37
+ # NOTE: this inner testset _needs_ to be wrapped with allowscalar
38
+ # to make sure its original value is restored.
39
+ end
40
+
41
+ @allowscalar for T in (Float32, Int32)
5
42
@testset " Indexing with $T " begin
6
43
x = rand (T, 32 )
7
44
src = AT (x)
@@ -27,7 +64,7 @@ function test_indexing(AT)
27
64
end
28
65
end
29
66
30
- for T in (Float32, Int32)
67
+ @allowscalar for T in (Float32, Int32)
31
68
@testset " Indexing with $T " begin
32
69
x = fill (zero (T), 7 )
33
70
src = AT (x)
@@ -43,7 +80,7 @@ function test_indexing(AT)
43
80
end
44
81
end
45
82
46
- for T in (Float32, Int32)
83
+ @allowscalar for T in (Float32, Int32)
47
84
@testset " issue #42 with $T " begin
48
85
Ac = rand (Float32, 2 , 2 )
49
86
A = AT (Ac)
@@ -52,7 +89,7 @@ function test_indexing(AT)
52
89
@test A[1 , 1 ] == Ac[1 , 1 ]
53
90
end
54
91
end
55
- for T in (Float32, Int32)
92
+ @allowscalar for T in (Float32, Int32)
56
93
@testset " Colon() $T " begin
57
94
Ac = rand (T, 10 )
58
95
A = AT (Ac)
@@ -63,8 +100,8 @@ function test_indexing(AT)
63
100
end
64
101
end
65
102
66
- @testset " get/setindex!" begin
67
- # literal calls to get/setindex! have differen return types
103
+ @allowscalar @ testset " get/setindex!" begin
104
+ # literal calls to get/setindex! have different return types
68
105
@test compare (x-> getindex (x,1 ), AT, zeros (Int, 2 ))
69
106
@test compare (x-> setindex! (x,1 ,1 ), AT, zeros (Int, 2 ))
70
107
end
0 commit comments