def test_polar(): z = 1 + 1j mag, arg = _u.complex_to_polar(z) assert is_zero(mag - sqrt(2), tolerance=1e-10) assert is_zero(arg - pi / 4, tolerance=1e-10) # # Then arrays # z = array([[1, 2], [3, 4]]) + array([[4, 3], [2, 1]]) * 1j mag, arg = _u.complex_to_polar(z) assert arrays_equal(mag - abs(z), 0, tolerance=1e-10) assert arrays_equal(arg - log(z).imag, 0, tolerance=1e-10) # # Then do the opposite # assert is_zero(1 + 1j - _u.polar_to_complex(sqrt(2), pi / 4), tolerance=1e-10) # # Make phase "continuous": # x = _u.linspace(0, 10, 20) * pi y = array(x, copy=True) y[3] -= 1 * 2 * pi y[9] -= 6 * 2 * pi y[12] += 1 * 2 * pi z = _u.continuous_phase(y) assert arrays_equal(x, z, tolerance=1e-10) # # Also, "center" the phase: # z = _u.continuous_phase(y, center=True) assert max(abs(z)) <= 6.000001 * pi assert arrays_equal(exp(1j * z), exp(1j * x), tolerance=1e-10) assert arrays_equal(exp(1j * y), exp(1j * x), tolerance=1e-10) # # Then the same, but along a different axis # x = _u.stretch_shape(_u.linspace(0, 10, 20) * pi, (5, 6, -1)) y = array(x, copy=True) y[:, :, 3] -= 2 * 2 * pi y[:, :, 2] -= 1 * 2 * pi y[:, :, 5] += 3 * 2 * pi z = _u.continuous_phase(y, axis=2) assert arrays_equal(x, z, tolerance=1e-10)
def test_stretch_shape(): x = array([1, 2, 3]) y = array([[1, 2, 3], [1, 2, 3], [1, 2, 3], [1, 2, 3]]) z = _u.stretch_shape(x, (4, -1)) assert arrays_equal(x, z)