Skip to content

Commit

Permalink
Add test for proj with low-rank Z.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlondschien committed Jul 22, 2024
1 parent 94b8f8d commit fbdbe63
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
def test_proj():
rng = np.random.RandomState(0)
X = rng.normal(0, 1, (100, 2))
Z = rng.normal(0, 1, (100, 5))
Z = rng.normal(0, 1, (100, 4)) @ rng.normal(0, 1, (4, 6))

assert np.allclose(proj(Z, X), Z @ np.linalg.inv(Z.T @ Z) @ Z.T @ X)
assert np.allclose(proj(Z, X), Z @ np.linalg.pinv(Z.T @ Z) @ Z.T @ X)
assert np.allclose(proj(Z, X), proj(Z, proj(Z, X)))
assert np.allclose(proj(proj(Z, X), X), proj(Z, X))


def test_oproj():
rng = np.random.RandomState(0)
X = rng.normal(0, 1, (100, 2))
Z = rng.normal(0, 1, (100, 5))
Z = rng.normal(0, 1, (100, 4)) @ rng.normal(0, 1, (4, 6))

assert np.allclose(X - proj(Z, X), oproj(Z, X))
assert np.allclose(oproj(Z, X), oproj(Z, oproj(Z, X)))


def test_proj_multiple_args():
Expand Down

0 comments on commit fbdbe63

Please sign in to comment.