Esempio n. 1
0
def test_match_global_no_float_error_when_axis_aligned():
    a = np.array([[1, 1.1], [-1.3, np.pi]])
    a2, _ = match_global_phase(a, a)
    a3, _ = match_global_phase(a * 1j, a * 1j)
    a4, _ = match_global_phase(-a, -a)
    a5, _ = match_global_phase(a * -1j, a * -1j)

    assert np.all(a2 == a)
    assert np.all(a3 == a)
    assert np.all(a4 == a)
    assert np.all(a5 == a)
Esempio n. 2
0
def test_match_global_phase_zeros():
    z = np.array([[0, 0], [0, 0]])
    b = np.array([[1, 1], [1, 1]])

    z1, b1 = match_global_phase(z, b)
    np.testing.assert_allclose(z, z1)
    np.testing.assert_allclose(b, b1)

    z2, b2 = match_global_phase(z, b)
    np.testing.assert_allclose(z, z2)
    np.testing.assert_allclose(b, b2)

    z3, z4 = match_global_phase(z, z)
    np.testing.assert_allclose(z, z3)
    np.testing.assert_allclose(z, z4)
Esempio n. 3
0
def allclose_up_to_global_phase(
    a: np.ndarray,
    b: np.ndarray,
    *,
    rtol: float = 1.0e-5,
    atol: float = 1.0e-8,
    equal_nan: bool = False,
) -> bool:
    """Determines if a ~= b * exp(i t) for some t.

    Args:
        a: A numpy array.
        b: Another numpy array.
        rtol: Relative error tolerance.
        atol: Absolute error tolerance.
        equal_nan: Whether or not NaN entries should be considered equal to
            other NaN entries.
    """

    if a.shape != b.shape:
        return False
    a, b = transformations.match_global_phase(a, b)

    # Should now be equivalent.
    return np.allclose(a=a, b=b, rtol=rtol, atol=atol, equal_nan=equal_nan)
Esempio n. 4
0
def test_match_global_phase():
    a = np.array([[5, 4], [3, -2]])
    b = np.array([[0.000001, 0], [0, 1j]])
    c, d = match_global_phase(a, b)
    np.testing.assert_allclose(c, -a)
    np.testing.assert_allclose(d, b * -1j)