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

Function test_complex_definition

python/tests/kernel/test_kernel_complex.py:76–96  ·  view source on GitHub ↗

Test that we can define complex lists inside kernel functions.

()

Source from the content-addressed store, hash-verified

74
75
76def test_complex_definition():
77 """Test that we can define complex lists inside kernel functions."""
78
79 # Define a list of complex inside a kernel
80 c = [.70710678 + 1j, 2j, 0., 0.70710678]
81
82 @cudaq.kernel
83 def complex_vec_definition_real(i: int) -> float:
84 v = [.70710678 + 1j, 2j, 0., 0.70710678][i]
85 return v.real
86
87 for i in range(len(c)):
88 assert is_close(c[i].real, complex_vec_definition_real(i))
89
90 @cudaq.kernel
91 def complex_vec_definition_imag(i: int) -> float:
92 v = [.70710678 + 1j, 2j, 0., 0.70710678][i]
93 return v.imag
94
95 for i in range(len(c)):
96 assert is_close(c[i].imag, complex_vec_definition_imag(i))
97
98
99def test_complex_definition_with_constructor():

Callers

nothing calls this directly

Calls 4

is_closeFunction · 0.70
rangeFunction · 0.50

Tested by

no test coverage detected