MCPcopy Create free account
hub / github.com/numpy/numpy / test_complex

Method test_complex

numpy/core/tests/test_function_base.py:178–216  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

176 assert_(isnan(y[1:]).all())
177
178 def test_complex(self):
179 # Purely imaginary
180 y = geomspace(1j, 16j, num=5)
181 assert_allclose(y, [1j, 2j, 4j, 8j, 16j])
182 assert_array_equal(y.real, 0)
183
184 y = geomspace(-4j, -324j, num=5)
185 assert_allclose(y, [-4j, -12j, -36j, -108j, -324j])
186 assert_array_equal(y.real, 0)
187
188 y = geomspace(1+1j, 1000+1000j, num=4)
189 assert_allclose(y, [1+1j, 10+10j, 100+100j, 1000+1000j])
190
191 y = geomspace(-1+1j, -1000+1000j, num=4)
192 assert_allclose(y, [-1+1j, -10+10j, -100+100j, -1000+1000j])
193
194 # Logarithmic spirals
195 y = geomspace(-1, 1, num=3, dtype=complex)
196 assert_allclose(y, [-1, 1j, +1])
197
198 y = geomspace(0+3j, -3+0j, 3)
199 assert_allclose(y, [0+3j, -3/sqrt(2)+3j/sqrt(2), -3+0j])
200 y = geomspace(0+3j, 3+0j, 3)
201 assert_allclose(y, [0+3j, 3/sqrt(2)+3j/sqrt(2), 3+0j])
202 y = geomspace(-3+0j, 0-3j, 3)
203 assert_allclose(y, [-3+0j, -3/sqrt(2)-3j/sqrt(2), 0-3j])
204 y = geomspace(0+3j, -3+0j, 3)
205 assert_allclose(y, [0+3j, -3/sqrt(2)+3j/sqrt(2), -3+0j])
206 y = geomspace(-2-3j, 5+7j, 7)
207 assert_allclose(y, [-2-3j, -0.29058977-4.15771027j,
208 2.08885354-4.34146838j, 4.58345529-3.16355218j,
209 6.41401745-0.55233457j, 6.75707386+3.11795092j,
210 5+7j])
211
212 # Type promotion should prevent the -5 from becoming a NaN
213 y = geomspace(3j, -5, 2)
214 assert_allclose(y, [3j, -5])
215 y = geomspace(-5, 3j, 2)
216 assert_allclose(y, [-5, 3j])
217
218 def test_dtype(self):
219 y = geomspace(1, 1e6, dtype='float32')

Callers

nothing calls this directly

Calls 4

geomspaceFunction · 0.90
assert_allcloseFunction · 0.90
assert_array_equalFunction · 0.90
sqrtFunction · 0.90

Tested by

no test coverage detected