@@ -2,123 +2,121 @@ using Test
2
2
using Reactant
3
3
4
4
if ! contains (string (Reactant. devices ()[1 ]), " TPU" )
5
-
6
- @testset " conj" begin
7
- @testset " $(typeof (x)) " for x in (1.0 , 1.0 + 2.0im )
8
- x_concrete = Reactant. to_rarray (x)
9
- @test only (@jit (conj (x_concrete))) == conj (x)
10
- end
11
-
12
- @testset " $(typeof (x)) " for x in (
13
- fill (1.0 + 2.0im ),
14
- fill (1.0 ),
15
- [1.0 + 2.0im ; 3.0 + 4.0im ],
16
- [1.0 ; 3.0 ],
17
- [1.0 + 2.0im 3.0 + 4.0im ],
18
- [1.0 2.0 ],
19
- [1.0 + 2.0im 3.0 + 4.0im ; 5.0 + 6.0im 7.0 + 8.0im ],
20
- [1.0 3.0 ; 5.0 7.0 ],
21
- )
22
- x_concrete = Reactant. to_rarray (x)
23
- @test @jit (conj (x_concrete)) == conj (x)
24
- end
25
- end
26
-
27
- @testset " conj!" begin
28
- @testset " $(typeof (x)) " for x in (
29
- fill (1.0 + 2.0im ),
30
- fill (1.0 ),
31
- [1.0 + 2.0im ; 3.0 + 4.0im ],
32
- [1.0 ; 3.0 ],
33
- [1.0 + 2.0im 3.0 + 4.0im ],
34
- [1.0 2.0 ],
35
- [1.0 + 2.0im 3.0 + 4.0im ; 5.0 + 6.0im 7.0 + 8.0im ],
36
- [1.0 3.0 ; 5.0 7.0 ],
37
- )
38
- x_concrete = Reactant. to_rarray (x)
39
- @test @jit (conj! (x_concrete)) == conj (x)
40
- @test x_concrete == conj (x)
5
+ @testset " conj" begin
6
+ @testset " $(typeof (x)) " for x in (1.0 , 1.0 + 2.0im )
7
+ x_concrete = Reactant. to_rarray (x)
8
+ @test only (@jit (conj (x_concrete))) == conj (x)
9
+ end
10
+
11
+ @testset " $(typeof (x)) " for x in (
12
+ fill (1.0 + 2.0im ),
13
+ fill (1.0 ),
14
+ [1.0 + 2.0im ; 3.0 + 4.0im ],
15
+ [1.0 ; 3.0 ],
16
+ [1.0 + 2.0im 3.0 + 4.0im ],
17
+ [1.0 2.0 ],
18
+ [1.0 + 2.0im 3.0 + 4.0im ; 5.0 + 6.0im 7.0 + 8.0im ],
19
+ [1.0 3.0 ; 5.0 7.0 ],
20
+ )
21
+ x_concrete = Reactant. to_rarray (x)
22
+ @test @jit (conj (x_concrete)) == conj (x)
23
+ end
41
24
end
42
- end
43
25
44
- @testset " real" begin
45
- @testset " $(typeof (x)) " for x in (1.0 , 1.0 + 2.0im )
46
- x_concrete = Reactant. to_rarray (x)
47
- @test only (@jit (real (x_concrete))) == real (x)
26
+ @testset " conj!" begin
27
+ @testset " $(typeof (x)) " for x in (
28
+ fill (1.0 + 2.0im ),
29
+ fill (1.0 ),
30
+ [1.0 + 2.0im ; 3.0 + 4.0im ],
31
+ [1.0 ; 3.0 ],
32
+ [1.0 + 2.0im 3.0 + 4.0im ],
33
+ [1.0 2.0 ],
34
+ [1.0 + 2.0im 3.0 + 4.0im ; 5.0 + 6.0im 7.0 + 8.0im ],
35
+ [1.0 3.0 ; 5.0 7.0 ],
36
+ )
37
+ x_concrete = Reactant. to_rarray (x)
38
+ @test @jit (conj! (x_concrete)) == conj (x)
39
+ @test x_concrete == conj (x)
40
+ end
48
41
end
49
42
50
- @testset " $(typeof (x)) " for x in (
51
- fill (1.0 + 2.0im ),
52
- fill (1.0 ),
53
- [1.0 + 2.0im ; 3.0 + 4.0im ],
54
- [1.0 ; 3.0 ],
55
- [1.0 + 2.0im 3.0 + 4.0im ],
56
- [1.0 2.0 ],
57
- [1.0 + 2.0im 3.0 + 4.0im ; 5.0 + 6.0im 7.0 + 8.0im ],
58
- [1.0 3.0 ; 5.0 7.0 ],
59
- )
60
- x_concrete = Reactant. to_rarray (x)
61
- @test @jit (real (x_concrete)) == real (x)
43
+ @testset " real" begin
44
+ @testset " $(typeof (x)) " for x in (1.0 , 1.0 + 2.0im )
45
+ x_concrete = Reactant. to_rarray (x)
46
+ @test only (@jit (real (x_concrete))) == real (x)
47
+ end
48
+
49
+ @testset " $(typeof (x)) " for x in (
50
+ fill (1.0 + 2.0im ),
51
+ fill (1.0 ),
52
+ [1.0 + 2.0im ; 3.0 + 4.0im ],
53
+ [1.0 ; 3.0 ],
54
+ [1.0 + 2.0im 3.0 + 4.0im ],
55
+ [1.0 2.0 ],
56
+ [1.0 + 2.0im 3.0 + 4.0im ; 5.0 + 6.0im 7.0 + 8.0im ],
57
+ [1.0 3.0 ; 5.0 7.0 ],
58
+ )
59
+ x_concrete = Reactant. to_rarray (x)
60
+ @test @jit (real (x_concrete)) == real (x)
61
+ end
62
62
end
63
- end
64
63
65
- @testset " imag" begin
66
- @testset " $(typeof (x)) " for x in (1.0 , 1.0 + 2.0im )
67
- x_concrete = Reactant. to_rarray (x)
68
- @test only (@jit (imag (x_concrete))) == imag (x)
64
+ @testset " imag" begin
65
+ @testset " $(typeof (x)) " for x in (1.0 , 1.0 + 2.0im )
66
+ x_concrete = Reactant. to_rarray (x)
67
+ @test only (@jit (imag (x_concrete))) == imag (x)
68
+ end
69
+
70
+ @testset " $(typeof (x)) " for x in (
71
+ fill (1.0 + 2.0im ),
72
+ fill (1.0 ),
73
+ [1.0 + 2.0im ; 3.0 + 4.0im ],
74
+ [1.0 ; 3.0 ],
75
+ [1.0 + 2.0im 3.0 + 4.0im ],
76
+ [1.0 2.0 ],
77
+ [1.0 + 2.0im 3.0 + 4.0im ; 5.0 + 6.0im 7.0 + 8.0im ],
78
+ [1.0 3.0 ; 5.0 7.0 ],
79
+ )
80
+ x_concrete = Reactant. to_rarray (x)
81
+ @test @jit (imag (x_concrete)) == imag (x)
82
+ end
69
83
end
70
84
71
- @testset " $(typeof (x)) " for x in (
72
- fill (1.0 + 2.0im ),
73
- fill (1.0 ),
74
- [1.0 + 2.0im ; 3.0 + 4.0im ],
75
- [1.0 ; 3.0 ],
76
- [1.0 + 2.0im 3.0 + 4.0im ],
77
- [1.0 2.0 ],
78
- [1.0 + 2.0im 3.0 + 4.0im ; 5.0 + 6.0im 7.0 + 8.0im ],
79
- [1.0 3.0 ; 5.0 7.0 ],
80
- )
85
+ @testset " abs: $T " for T in (Float32, ComplexF32)
86
+ x = randn (T, 10 )
81
87
x_concrete = Reactant. to_rarray (x)
82
- @test @jit (imag (x_concrete)) == imag (x)
88
+ @test @jit (abs . (x_concrete)) ≈ abs . (x)
83
89
end
84
- end
85
90
86
- @testset " abs: $T " for T in (Float32, ComplexF32)
87
- x = randn (T, 10 )
88
- x_concrete = Reactant. to_rarray (x)
89
- @test @jit (abs .(x_concrete)) ≈ abs .(x)
90
- end
91
+ @testset " promote_to Complex" begin
92
+ x = 1.0 + 2.0im
93
+ y = ConcreteRNumber (x)
91
94
92
- @testset " promote_to Complex " begin
93
- x = 1.0 + 2 .0im
94
- y = ConcreteRNumber (x)
95
+ f = Reactant . compile ((y,)) do z
96
+ z + Reactant . TracedUtils . promote_to (Reactant . TracedRNumber{ComplexF64}, 1.0 - 3 .0im)
97
+ end
95
98
96
- f = Reactant. compile ((y,)) do z
97
- z + Reactant. TracedUtils. promote_to (Reactant. TracedRNumber{ComplexF64}, 1.0 - 3.0im )
99
+ @test isapprox (f (y), 2.0 - 1.0im )
98
100
end
99
101
100
- @test isapprox (f (y), 2.0 - 1.0im )
101
- end
102
-
103
- @testset " complex reduction" begin
104
- x = randn (ComplexF32, 10 , 10 )
105
- x_ra = Reactant. to_rarray (x)
106
- @test @jit (sum (abs2, x_ra)) ≈ sum (abs2, x)
107
- end
108
-
109
- @testset " create complex numbers" begin
110
- x = randn (ComplexF32)
111
- x_ra = Reactant. to_rarray (x; track_numbers= true )
112
- @test @jit (Complex (x_ra)) == x_ra
113
-
114
- x = randn (Float32)
115
- y = randn (Float64)
116
- x_ra = Reactant. to_rarray (x; track_numbers= true )
117
- y_ra = Reactant. to_rarray (y; track_numbers= true )
118
- @test @jit (Complex (x_ra, y_ra)) == Complex (x, y)
119
- @test @jit (Complex (x_ra, y)) == Complex (x, y)
120
- @test @jit (Complex (x, y_ra)) == Complex (x, y)
121
- @test @jit (Complex (x_ra)) == Complex (x) == @jit (Complex (x_ra, 0 ))
122
- end
102
+ @testset " complex reduction" begin
103
+ x = randn (ComplexF32, 10 , 10 )
104
+ x_ra = Reactant. to_rarray (x)
105
+ @test @jit (sum (abs2, x_ra)) ≈ sum (abs2, x)
106
+ end
123
107
108
+ @testset " create complex numbers" begin
109
+ x = randn (ComplexF32)
110
+ x_ra = Reactant. to_rarray (x; track_numbers= true )
111
+ @test @jit (Complex (x_ra)) == x_ra
112
+
113
+ x = randn (Float32)
114
+ y = randn (Float64)
115
+ x_ra = Reactant. to_rarray (x; track_numbers= true )
116
+ y_ra = Reactant. to_rarray (y; track_numbers= true )
117
+ @test @jit (Complex (x_ra, y_ra)) == Complex (x, y)
118
+ @test @jit (Complex (x_ra, y)) == Complex (x, y)
119
+ @test @jit (Complex (x, y_ra)) == Complex (x, y)
120
+ @test @jit (Complex (x_ra)) == Complex (x) == @jit (Complex (x_ra, 0 ))
121
+ end
124
122
end
0 commit comments