Beispiel #1
0
def test_drc3jj_vec(half_integer):
    n = 1000
    l2 = rng.randint(0, 10, size=n) * 2 + half_integer
    l3 = rng.randint(0, 10, size=n) * 2 + half_integer
    m2 = np.zeros(n, dtype=int)
    m3 = np.zeros(n, dtype=int)
    for i in range(n):
        if l2[i] > 0:
            m2[i] = rng.randint(-l2[i], l2[i]+1)
        if l3[i] > 0:
            m3[i] = rng.randint(-l3[i], l3[i]+1)

    l, actual = wigner.drc3jj(l2, l3, m2, m3)
    for _ in range(2):
        l, actual = wigner.drc3jj(l2, l3, m2, m3)

    for i in range(n):
        if (actual[i] != 0).any():
            l, expected = wigner._drc3jj(l2[i], l3[i], m2[i], m3[i])
            assert np.allclose(actual[i, l], expected)
        else:
            with pytest.raises(ValueError):
                # all zeros or invalid argument
                l, expected = wigner._drc3jj(l2[i], l3[i], m2[i], m3[i])
                if (expected == 0).all():
                    raise ValueError
Beispiel #2
0
def test2d():
    n = (10, 11)
    l2 = rng.randint(0, 10, size=n) * 2
    l3 = rng.randint(0, 10, size=n) * 2
    m2 = np.zeros(n, dtype=int)
    m3 = np.zeros(n, dtype=int)
    for i0 in range(n[0]):
        for i1 in range(n[1]):
            i = (i0, i1)
            if l2[i] > 0:
                m2[i] = rng.randint(-l2[i], l2[i]+1)
            if l3[i] > 0:
                m3[i] = rng.randint(-l3[i], l3[i]+1)

    l, actual = wigner.drc3jj(l2, l3, m2, m3)
    for i0 in range(n[0]):
        for i1 in range(n[1]):
            i = (i0, i1)
            if (actual[i] != 0).any():
                l, expected = wigner._drc3jj(l2[i], l3[i], m2[i], m3[i])
                assert np.allclose(actual[i][l], expected)
            else:
                with pytest.raises(ValueError):
                    # all zeros or invalid argument
                    l, expected = wigner._drc3jj(l2[i], l3[i], m2[i], m3[i])
                    if (expected == 0).all():
                        raise ValueError
Beispiel #3
0
def test_drc3jj():
    for three_j, result in THREE_J:
        three_j = (np.array(three_j) * 2).astype(int)
        l, thrcof = wigner._drc3jj(three_j[1], three_j[2], three_j[4],
                                   three_j[5])
        assert three_j[0] in l
        assert np.allclose(thrcof[l == three_j[0]], result)
Beispiel #4
0
def test0d():
    for _ in range(100):
        l2 = rng.randint(0, 40) * 2
        l3 = rng.randint(0, 40) * 2
        m2 = 0
        if l2 > 0:
            m2 = rng.randint(-l2, l2+1)
        m3 = 0
        if l3 > 0:
            m3 = rng.randint(-l3, l3+1)
        l, actual = wigner.drc3jj(l2, l3, m2, m3)
        assert actual.ndim == 1

        if (actual != 0).any():
            l, expected = wigner._drc3jj(l2, l3, m2, m3)
            assert np.allclose(actual[l], expected)
        else:
            with pytest.raises(ValueError):
                # all zeros or invalid argument
                l, expected = wigner._drc3jj(l2, l3, m2, m3)
                if (expected == 0).all():
                    raise ValueError
Beispiel #5
0
def test_invalid():
    with pytest.raises(ValueError):
        l, thrcof = wigner._drc3jj(1, 3, 0, 0)

    with pytest.raises(ValueError):
        l, thrcof = wigner._drc3jj(1, 3, 4, 0)