Skip to content

Commit

Permalink
More tests for CG, but no changes in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiisoup committed Sep 5, 2023
1 parent fbd80d4 commit bfcd5f4
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tests/test_cg.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
# j1 = 1, j2 = 1/2
((2, 2, 4, 2, 0, 2), np.sqrt(1.0 / 2)),
)


def test_wigner3j_value():
def test_clebsch_gordan_value():
# scalar test
for three_j, expected in CG:
print(three_j)
Expand All @@ -34,3 +32,23 @@ def test_wigner3j_value():
expected = np.array([value for _, value in CG]).T
actual = clebsch_gordan(*three_j)
assert np.allclose(actual, expected)


# reference from https://en.wikipedia.org/wiki/Clebsch%E2%80%93Gordan_coefficients#Special%20cases
def test_clebsch_gordan_value_more():
# if J3 = M3 = 0
for offset in [0, 0.5]:
for j1 in np.arange(offset, 4 + offset):
for j2 in np.arange(offset, 3 + offset):
m1 = np.arange(-j1, j1 + 1)[:, np.newaxis]
m2 = np.arange(-j2, j2 + 1)
expected = np.where(
(j1 == j2) * (m1 == -m2),
(-1) ** (j1 - m1) / np.sqrt(2 * j1 + 1),
0.0
)
actual = clebsch_gordan(
int(2 * j1), int(2 * j2), 0, (2 * m1).astype(int), (2 * m2).astype(int), 0
)
assert np.allclose(expected, actual)

0 comments on commit bfcd5f4

Please sign in to comment.