MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / test_np_complex64_params

Function test_np_complex64_params

python/tests/kernel/test_kernel_complex.py:407–441  ·  view source on GitHub ↗

Test that we can pass complex lists to kernel functions.

()

Source from the content-addressed store, hash-verified

405
406
407def test_np_complex64_params():
408 """Test that we can pass complex lists to kernel functions."""
409
410 # Pass a list of complex as a parameter
411 c = [
412 np.complex64(.70710678 + 1j),
413 np.complex64(0. + 2j),
414 np.complex64(0.),
415 np.complex64(0.70710678)
416 ]
417
418 @cudaq.kernel
419 def complex_vec_param(vec: list[np.complex64], i: int) -> np.complex64:
420 return vec[i]
421
422 for i in range(len(c)):
423 is_close(c[i].real, complex_vec_param(c, i).real)
424 for i in range(len(c)):
425 is_close(c[i].imag, complex_vec_param(c, i).imag)
426
427 @cudaq.kernel
428 def complex_vec_param_real(vec: list[np.complex64], i: int) -> np.float32:
429 v = vec[i]
430 return v.real
431
432 for i in range(len(c)):
433 assert is_close(c[i].real, complex_vec_param_real(c, i))
434
435 @cudaq.kernel
436 def complex_vec_param_imag(vec: list[np.complex64], i: int) -> np.float32:
437 v = vec[i]
438 return v.imag
439
440 for i in range(len(c)):
441 assert is_close(c[i].imag, complex_vec_param_imag(c, i))
442
443
444def test_np_complex64_capture():

Callers

nothing calls this directly

Calls 5

complex_vec_paramFunction · 0.85
complex_vec_param_realFunction · 0.85
complex_vec_param_imagFunction · 0.85
is_closeFunction · 0.70
rangeFunction · 0.50

Tested by

no test coverage detected