Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions brax/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,11 @@ def get_x(x, xs):

return x, None

# TODO(brax-team): turn this into a scan
for _ in range(num_iters):
def iterate(x, _):
x, _ = jax.lax.scan(get_x, x, (jp.arange(num_rows), a, b))
return x, None

x, _ = jax.lax.scan(iterate, x, None, length=num_iters)

return x

Expand Down
7 changes: 7 additions & 0 deletions brax/math_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def test_from_to(self):
rot = math.from_to(v1, v2)
np.testing.assert_array_almost_equal(v2, math.rotate(v1, rot))

def test_solve_pgs_diagonal(self):
a = jp.diag(jp.array([2.0, 4.0, 8.0]))
b = jp.array([-2.0, 2.0, -8.0])
expected = jp.array([1.0, 0.0, 1.0])
x = math.solve_pgs(a, b, num_iters=2)
np.testing.assert_allclose(x, expected, rtol=1e-6, atol=1e-6)


class OrthoganalsTest(parameterized.TestCase):
"""Tests the orthogonals function."""
Expand Down