Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lang] Remove Matrix.value #4300

Merged
merged 3 commits into from
Feb 16, 2022
Merged
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
7 changes: 1 addition & 6 deletions python/taichi/lang/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,6 @@ def z(self, value):
def w(self, value):
self[3] = value

@property
@python_scope
def value(self):
return Matrix(self.to_list())

def to_list(self):
return [[self(i, j) for j in range(self.m)] for i in range(self.n)]

Expand Down Expand Up @@ -670,7 +665,7 @@ def to_numpy(self, keep_dims=False):
"""
as_vector = self.m == 1 and not keep_dims
shape_ext = (self.n, ) if as_vector else (self.n, self.m)
return np.array(self.value).reshape(shape_ext)
return np.array(self.to_list()).reshape(shape_ext)

@taichi_scope
def __ti_repr__(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/python/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ def fill():
assert a[i][j] == int(i == j)

sqrt3o2 = math.sqrt(3) / 2
assert b[0].value.to_numpy() == test_utils.approx(np.eye(2))
assert b[1].value.to_numpy() == test_utils.approx(
assert b[0].to_numpy() == test_utils.approx(np.eye(2))
assert b[1].to_numpy() == test_utils.approx(
np.array([[0.5, -sqrt3o2], [sqrt3o2, 0.5]]))
assert c[0].value.to_numpy() == test_utils.approx(np.zeros((2, 3)))
assert c[1].value.to_numpy() == test_utils.approx(np.ones((2, 3)))
assert c[0].to_numpy() == test_utils.approx(np.zeros((2, 3)))
assert c[1].to_numpy() == test_utils.approx(np.ones((2, 3)))


# TODO: move codes below to test_matrix.py:
Expand Down
16 changes: 8 additions & 8 deletions tests/python/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_python_scope_vector_field(ops):
a, b = test_vector_arrays[:2]
t1[None], t2[None] = a.tolist(), b.tolist()

c = ops(t1[None].value, t2[None].value)
c = ops(t1[None], t2[None])
assert np.allclose(c.to_numpy(), ops(a, b))


Expand All @@ -68,7 +68,7 @@ def test_python_scope_matrix_field(ops):
# ndarray not supported here
t1[None], t2[None] = a.tolist(), b.tolist()

c = ops(t1[None].value, t2[None].value)
c = ops(t1[None], t2[None])
print(c)

assert np.allclose(c.to_numpy(), ops(a, b))
Expand Down Expand Up @@ -138,8 +138,8 @@ def run():

run()

assert np.allclose(r1[None].value.to_numpy(), ops(a, b))
assert np.allclose(r2[None].value.to_numpy(), ops(a, c))
assert np.allclose(r1[None].to_numpy(), ops(a, b))
assert np.allclose(r2[None].to_numpy(), ops(a, c))


@pytest.mark.parametrize('ops', vector_operation_types)
Expand All @@ -159,8 +159,8 @@ def run():

run()

assert np.allclose(r1[None].value.to_numpy(), ops(a, b))
assert np.allclose(r2[None].value.to_numpy(), ops(a, c))
assert np.allclose(r1[None].to_numpy(), ops(a, b))
assert np.allclose(r2[None].to_numpy(), ops(a, c))


@test_utils.test()
Expand Down Expand Up @@ -272,7 +272,7 @@ def test_vector_to_list():
assert len(b) == len(data)

a[None] = b
assert all(a[None].value == ti.Vector(data))
assert all(a[None] == ti.Vector(data))


@test_utils.test(arch=ti.cpu)
Expand All @@ -285,7 +285,7 @@ def test_matrix_to_list():
assert len(b) == len(data)

a[None] = b
assert all(a[None].value == ti.Matrix(data))
assert all(a[None] == ti.Matrix(data))


@test_utils.test()
Expand Down
8 changes: 4 additions & 4 deletions tests/python/test_ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def func():
b[None] = [[1, 2], [3, 4]]
c[None] = [2, 3]
func()
assert a[None].value == ti.Vector([inv_sqrt2, inv_sqrt2])
assert b[None].value == ti.Matrix([[1, 3], [2, 4]])
assert c[None].value == ti.Vector([3, 2])
assert a[None] == ti.Vector([inv_sqrt2, inv_sqrt2])
assert b[None] == ti.Matrix([[1, 3], [2, 4]])
assert c[None] == ti.Vector([3, 2])


@test_utils.test()
Expand All @@ -44,7 +44,7 @@ def func():

for i in range(4):
func()
assert a[None].value.norm_sqr() == test_utils.approx(1)
assert a[None].norm_sqr() == test_utils.approx(1)


@test_utils.test()
Expand Down