Test that we can use floats inside kernel functions.
()
| 206 | |
| 207 | |
| 208 | def test_float32_use(): |
| 209 | """Test that we can use floats inside kernel functions.""" |
| 210 | |
| 211 | # Use a float inside np in a kernel (sin) |
| 212 | @cudaq.kernel |
| 213 | def float_np_use() -> np.float32: |
| 214 | return np.sin(np.float32(np.pi / 2 + 1)) |
| 215 | |
| 216 | t = np.sin(np.float32(np.pi / 2 + 1)) |
| 217 | assert is_close(t, float_np_use()) |
| 218 | |
| 219 | # Use a float inside np in a kernel (cos) |
| 220 | @cudaq.kernel |
| 221 | def float_np_use() -> np.float32: |
| 222 | return np.cos(np.float32(np.pi / 2 + 1)) |
| 223 | |
| 224 | t = np.cos(np.float32(np.pi / 2 + 1)) |
| 225 | assert is_close(t, float_np_use()) |
| 226 | |
| 227 | # Use a float inside np in a kernel (sqrt) |
| 228 | @cudaq.kernel |
| 229 | def float_np_use() -> np.float32: |
| 230 | return np.sqrt(np.float32(np.pi / 2 + 1)) |
| 231 | |
| 232 | t = np.sqrt(np.float32(np.pi / 2 + 1)) |
| 233 | assert is_close(t, float_np_use()) |
| 234 | |
| 235 | # Use a float inside np in a kernel (ceil) |
| 236 | @cudaq.kernel |
| 237 | def float_np_use() -> np.float32: |
| 238 | return np.ceil(np.float32(np.pi / 2 + 1)) |
| 239 | |
| 240 | t = np.ceil(np.float32(np.pi / 2 + 1)) |
| 241 | assert is_close(t, float_np_use()) |
| 242 | |
| 243 | # Use a float inside np in a kernel (exp) |
| 244 | @cudaq.kernel |
| 245 | def float_np_use() -> np.float32: |
| 246 | return np.exp(np.float32(np.pi / 2 + 1)) |
| 247 | |
| 248 | t = np.exp(np.float32(np.pi / 2 + 1)) |
| 249 | assert is_close(t, float_np_use()) |
| 250 | |
| 251 | |
| 252 | def test_float_list_parameter_promotion(): |
nothing calls this directly
no test coverage detected