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 deprecated usage of ti.Matrix.__init__ #2950

Merged
merged 6 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
60 changes: 5 additions & 55 deletions python/taichi/lang/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,59 +30,23 @@ class Matrix(TaichiOperations):
dt (DataType): the elmement data type.
shape ( Union[int, tuple of int], optional): the shape of a matrix field.
offset (Union[int, tuple of int], optional): The coordinate offset of all elements in a field.
empty (Bool, deprecated): True if the matrix is empty, False otherwise.
layout (Layout, optional): The filed layout (Layout.AOS or Layout.SOA).
needs_grad (Bool, optional): True if used in auto diff, False otherwise.
keep_raw (Bool, optional): Keep the contents in `n` as is.
rows (List, deprecated): construct matrix rows.
cols (List, deprecated): construct matrix columns.
"""
is_taichi_class = True

# TODO(archibate): move the last two line to **kwargs,
# since they're not commonly used as positional args.
def __init__(self,
n=1,
m=1,
dt=None,
shape=None,
offset=None,
strongoier marked this conversation as resolved.
Show resolved Hide resolved
empty=False,
layout=Layout.AOS,
needs_grad=False,
keep_raw=False,
disable_local_tensor=False,
rows=None,
cols=None):
disable_local_tensor=False):
self.local_tensor_proxy = None
self.any_array_access = None
self.grad = None

# construct from rows or cols (deprecated)
if rows is not None or cols is not None:
warning(
f"ti.Matrix(rows=[...]) or ti.Matrix(cols=[...]) is deprecated, use ti.Matrix.rows([...]) or ti.Matrix.cols([...]) instead.",
DeprecationWarning,
stacklevel=2)
if rows is not None and cols is not None:
raise Exception("cannot specify both rows and columns")
self.dt = dt
mat = Matrix.cols(cols) if cols is not None else Matrix.rows(rows)
self.n = mat.n
self.m = mat.m
self.entries = mat.entries
return

elif empty == True:
warning(
f"ti.Matrix(n, m, empty=True) is deprecated, use ti.Matrix.empty(n, m) instead",
DeprecationWarning,
stacklevel=2)
self.dt = dt
self.entries = [[None] * m for _ in range(n)]
return

elif isinstance(n, (list, tuple, np.ndarray)):
if isinstance(n, (list, tuple, np.ndarray)):
if len(n) == 0:
mat = []
elif isinstance(n[0], Matrix):
Expand Down Expand Up @@ -172,23 +136,9 @@ def __init__(self,
self.n = n
self.m = m
else:
# construct global matrix (deprecated)
warning(
"Declaring global matrices using `ti.Matrix(n, m, dt, shape)` is deprecated, "
"use `ti.Matrix.field(n, m, dtype, shape)` instead",
DeprecationWarning,
stacklevel=2)
mat = Matrix.field(n=n,
m=m,
dtype=dt,
shape=shape,
offset=offset,
needs_grad=needs_grad,
layout=layout)
self.n = mat.n
self.m = mat.m
self.entries = mat.entries
self.grad = mat.grad
raise ValueError(
"Declaring matrix fields using `ti.Matrix(n, m, dt, shape)` is no longer supported. Use `ti.Matrix.field(n, m, dtype, shape)` instead."
)

if self.n * self.m > 32:
warning(
Expand Down
12 changes: 6 additions & 6 deletions tests/python/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,12 @@ def fill():
a = ti.Vector([1.0, 4.0, 7.0])
b = ti.Vector([2.0, 5.0, 8.0])
c = ti.Vector([3.0, 6.0, 9.0])
m1[i] = ti.Matrix(rows=[a, b, c])
m2[i] = ti.Matrix(cols=[a, b, c])
m3[i] = ti.Matrix(
rows=[[1.0, 4.0, 7.0], [2.0, 5.0, 8.0], [3.0, 6.0, 9.0]])
m4[i] = ti.Matrix(
cols=[[1.0, 4.0, 7.0], [2.0, 5.0, 8.0], [3.0, 6.0, 9.0]])
m1[i] = ti.Matrix.rows([a, b, c])
m2[i] = ti.Matrix.cols([a, b, c])
m3[i] = ti.Matrix.rows([[1.0, 4.0, 7.0], [2.0, 5.0, 8.0],
[3.0, 6.0, 9.0]])
m4[i] = ti.Matrix.cols([[1.0, 4.0, 7.0], [2.0, 5.0, 8.0],
[3.0, 6.0, 9.0]])

fill()

Expand Down