|
99 | 99 | val = Array(buf)
|
100 | 100 | @test val[] ≈ x^y
|
101 | 101 | end
|
102 |
| -end |
103 | 102 |
|
104 | 103 |
|
| 104 | + @testset "angle" begin |
| 105 | + buf = CuTestArray(zeros(Float32)) |
| 106 | + cbuf = CuTestArray(zeros(Float32)) |
| 107 | + |
| 108 | + function cuda_kernel(a, x) |
| 109 | + a[] = CUDAnative.angle(x) |
| 110 | + return |
| 111 | + end |
| 112 | + |
| 113 | + #op(::Float32) |
| 114 | + x = rand(Float32) |
| 115 | + @cuda cuda_kernel(buf, x) |
| 116 | + val = Array(buf) |
| 117 | + @test val[] ≈ angle(x) |
| 118 | + @cuda cuda_kernel(buf, -x) |
| 119 | + val = Array(buf) |
| 120 | + @test val[] ≈ angle(-x) |
| 121 | + |
| 122 | + #op(::ComplexF32) |
| 123 | + x = rand(ComplexF32) |
| 124 | + @cuda cuda_kernel(cbuf, x) |
| 125 | + val = Array(cbuf) |
| 126 | + @test val[] ≈ angle(x) |
| 127 | + @cuda cuda_kernel(cbuf, -x) |
| 128 | + val = Array(cbuf) |
| 129 | + @test val[] ≈ angle(-x) |
| 130 | + |
| 131 | + #op(::Float64) |
| 132 | + x = rand(Float64) |
| 133 | + @cuda cuda_kernel(buf, x) |
| 134 | + val = Array(buf) |
| 135 | + @test val[] ≈ angle(x) |
| 136 | + @cuda cuda_kernel(buf, -x) |
| 137 | + val = Array(buf) |
| 138 | + @test val[] ≈ angle(-x) |
| 139 | + |
| 140 | + #op(::ComplexF64) |
| 141 | + x = rand(ComplexF64) |
| 142 | + @cuda cuda_kernel(cbuf, x) |
| 143 | + val = Array(cbuf) |
| 144 | + @test val[] ≈ angle(x) |
| 145 | + @cuda cuda_kernel(cbuf, -x) |
| 146 | + val = Array(cbuf) |
| 147 | + @test val[] ≈ angle(-x) |
| 148 | + end |
| 149 | + |
| 150 | + # dictionary of key=>tuple, where the tuple should |
| 151 | + # contain the cpu command and the cuda function to test. |
| 152 | + ops = Dict("exp"=>(exp, CUDAnative.exp), |
| 153 | + "angle"=>(angle, CUDAnative.angle), |
| 154 | + "exp2"=>(exp2, CUDAnative.exp2), |
| 155 | + "exp10"=>(exp10, CUDAnative.exp10), |
| 156 | + "expm1"=>(expm1, CUDAnative.expm1)) |
| 157 | + |
| 158 | + @testset "$key" for key=keys(ops) |
| 159 | + cpu_op, cuda_op = ops[key] |
| 160 | + |
| 161 | + buf = CuTestArray(zeros(Float32)) |
| 162 | + |
| 163 | + function cuda_kernel(a, x) |
| 164 | + a[] = cuda_op(x) |
| 165 | + return |
| 166 | + end |
| 167 | + |
| 168 | + #op(::Float32) |
| 169 | + x = rand(Float32) |
| 170 | + @cuda cuda_kernel(buf, x) |
| 171 | + val = Array(buf) |
| 172 | + @test val[] ≈ cpu_op(x) |
| 173 | + @cuda cuda_kernel(buf, -x) |
| 174 | + val = Array(buf) |
| 175 | + @test val[] ≈ cpu_op(-x) |
| 176 | + |
| 177 | + #op(::Float64) |
| 178 | + x = rand(Float64) |
| 179 | + @cuda cuda_kernel(buf, x) |
| 180 | + val = Array(buf) |
| 181 | + @test val[] ≈ cpu_op(x) |
| 182 | + @cuda cuda_kernel(buf, -x) |
| 183 | + val = Array(buf) |
| 184 | + @test val[] ≈ cpu_op(-x) |
| 185 | + end |
| 186 | + |
| 187 | + # dictionary of key=>tuple, where the tuple should |
| 188 | + # contain the cpu command and the cuda function to test. |
| 189 | + ops = Dict("exp"=>(exp, CUDAnative.exp), |
| 190 | + "abs"=>(abs, CUDAnative.abs), |
| 191 | + "abs2"=>(abs2, CUDAnative.abs2), |
| 192 | + "angle"=>(angle, CUDAnative.angle), |
| 193 | + "log"=>(log, CUDAnative.log)) |
| 194 | + |
| 195 | + @testset "Complex - $key" for key=keys(ops) |
| 196 | + cpu_op, cuda_op = ops[key] |
| 197 | + |
| 198 | + buf = CuTestArray(zeros(Complex{Float32})) |
| 199 | + |
| 200 | + function cuda_kernel(a, x) |
| 201 | + a[] = cuda_op(x) |
| 202 | + return |
| 203 | + end |
| 204 | + |
| 205 | + #op(::ComplexF32, ::ComplexF32) |
| 206 | + x = rand(ComplexF32) |
| 207 | + @cuda cuda_kernel(buf, x) |
| 208 | + val = Array(buf) |
| 209 | + @test val[] ≈ cpu_op(x) |
| 210 | + @cuda cuda_kernel(buf, -x) |
| 211 | + val = Array(buf) |
| 212 | + @test val[] ≈ cpu_op(-x) |
| 213 | + |
| 214 | + #op(::ComplexF64, ::ComplexF64) |
| 215 | + x = rand(ComplexF64) |
| 216 | + @cuda cuda_kernel(buf, x) |
| 217 | + val = Array(buf) |
| 218 | + @test val[] ≈ cpu_op(x) |
| 219 | + @cuda cuda_kernel(buf, -x) |
| 220 | + val = Array(buf) |
| 221 | + @test val[] ≈ cpu_op(-x) |
| 222 | + end |
| 223 | +end |
| 224 | + |
105 | 225 |
|
106 | 226 | ############################################################################################
|
107 | 227 |
|
|
0 commit comments