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

Function test_float64_use

python/tests/kernel/test_kernel_float.py:119–160  ·  view source on GitHub ↗

Test that we can use floats inside kernel functions.

()

Source from the content-addressed store, hash-verified

117
118
119def test_float64_use():
120 """Test that we can use floats inside kernel functions."""
121
122 # Use a float inside np in a kernel (sin)
123 @cudaq.kernel
124 def float_np_use() -> np.float64:
125 return np.sin(np.float64(np.pi / 2 + 1))
126
127 t = np.sin(np.float64(np.pi / 2 + 1))
128 assert is_close(t, float_np_use())
129
130 # Use a float inside np in a kernel (cos)
131 @cudaq.kernel
132 def float_np_use() -> np.float64:
133 return np.cos(np.float64(np.pi / 2 + 1))
134
135 t = np.cos(np.float64(np.pi / 2 + 1))
136 assert is_close(t, float_np_use())
137
138 # Use a float inside np in a kernel (sqrt)
139 @cudaq.kernel
140 def float_np_use() -> np.float64:
141 return np.sqrt(np.float64(np.pi / 2 + 1))
142
143 t = np.sqrt(np.float64(np.pi / 2 + 1))
144 assert is_close(t, float_np_use())
145
146 # Use a float inside np in a kernel (ceil)
147 @cudaq.kernel
148 def float_np_use() -> np.float64:
149 return np.ceil(np.float64(np.pi / 2 + 1))
150
151 t = np.ceil(np.float64(np.pi / 2 + 1))
152 assert is_close(t, float_np_use())
153
154 # Use a float inside np in a kernel (exp)
155 @cudaq.kernel
156 def float_np_use() -> np.float64:
157 return np.exp(np.float64(np.pi / 2 + 1))
158
159 t = np.exp(np.float64(np.pi / 2 + 1))
160 assert is_close(t, float_np_use())
161
162
163# np.float32

Callers

nothing calls this directly

Calls 2

float_np_useFunction · 0.85
is_closeFunction · 0.70

Tested by

no test coverage detected