From ef1cdf729d610abaa3c8dd7742e38c55627001b3 Mon Sep 17 00:00:00 2001 From: Yi Xu Date: Thu, 16 Sep 2021 14:20:16 +0800 Subject: [PATCH 1/6] Remove empty --- python/taichi/lang/matrix.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/python/taichi/lang/matrix.py b/python/taichi/lang/matrix.py index d1f780716b5af..a8c1de576f487 100644 --- a/python/taichi/lang/matrix.py +++ b/python/taichi/lang/matrix.py @@ -47,7 +47,6 @@ def __init__(self, dt=None, shape=None, offset=None, - empty=False, layout=Layout.AOS, needs_grad=False, keep_raw=False, @@ -73,14 +72,6 @@ def __init__(self, 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 len(n) == 0: From a8663f53d14b3dc640915bcb75fc8869f26bfcc6 Mon Sep 17 00:00:00 2001 From: Yi Xu Date: Thu, 16 Sep 2021 14:29:43 +0800 Subject: [PATCH 2/6] Remove rows and cols --- python/taichi/lang/matrix.py | 27 ++------------------------- tests/python/test_linalg.py | 10 ++++------ 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/python/taichi/lang/matrix.py b/python/taichi/lang/matrix.py index a8c1de576f487..3f51e44ba35e4 100644 --- a/python/taichi/lang/matrix.py +++ b/python/taichi/lang/matrix.py @@ -30,17 +30,12 @@ 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, @@ -50,30 +45,12 @@ def __init__(self, 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 isinstance(n, (list, tuple, np.ndarray)): + if isinstance(n, (list, tuple, np.ndarray)): if len(n) == 0: mat = [] elif isinstance(n[0], Matrix): diff --git a/tests/python/test_linalg.py b/tests/python/test_linalg.py index d76b7c3dc91c1..98a1f19ee5c66 100644 --- a/tests/python/test_linalg.py +++ b/tests/python/test_linalg.py @@ -322,12 +322,10 @@ 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() From 719d7ae93fabbfdc21b0da7253d2101b328a155a Mon Sep 17 00:00:00 2001 From: Yi Xu Date: Thu, 16 Sep 2021 14:36:16 +0800 Subject: [PATCH 3/6] Remove matrix field in matrix --- python/taichi/lang/matrix.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/python/taichi/lang/matrix.py b/python/taichi/lang/matrix.py index 3f51e44ba35e4..007d3d578e941 100644 --- a/python/taichi/lang/matrix.py +++ b/python/taichi/lang/matrix.py @@ -140,23 +140,7 @@ 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( From 32431e5fee4ac77c2c2785b63d35c0f17bff4ee4 Mon Sep 17 00:00:00 2001 From: Yi Xu Date: Thu, 16 Sep 2021 15:24:14 +0800 Subject: [PATCH 4/6] Remove unused arguments --- python/taichi/lang/matrix.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/python/taichi/lang/matrix.py b/python/taichi/lang/matrix.py index 007d3d578e941..19c7ccdfd9bd1 100644 --- a/python/taichi/lang/matrix.py +++ b/python/taichi/lang/matrix.py @@ -40,10 +40,6 @@ def __init__(self, n=1, m=1, dt=None, - shape=None, - offset=None, - layout=Layout.AOS, - needs_grad=False, keep_raw=False, disable_local_tensor=False): self.local_tensor_proxy = None From 0bf47da08b140db5808228f846a1fb07c63e6008 Mon Sep 17 00:00:00 2001 From: Taichi Gardener Date: Thu, 16 Sep 2021 07:26:08 +0000 Subject: [PATCH 5/6] Auto Format --- python/taichi/lang/matrix.py | 4 +++- tests/python/test_linalg.py | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/python/taichi/lang/matrix.py b/python/taichi/lang/matrix.py index 19c7ccdfd9bd1..8521c5a2e5f8f 100644 --- a/python/taichi/lang/matrix.py +++ b/python/taichi/lang/matrix.py @@ -136,7 +136,9 @@ def __init__(self, self.n = n self.m = m else: - 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.") + 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( diff --git a/tests/python/test_linalg.py b/tests/python/test_linalg.py index 98a1f19ee5c66..947d1964b1d9f 100644 --- a/tests/python/test_linalg.py +++ b/tests/python/test_linalg.py @@ -324,8 +324,10 @@ def fill(): 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]]) + 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() From 38e869a0e644d11f82a4fb58ee2cd70cbaaa0795 Mon Sep 17 00:00:00 2001 From: Yi Xu Date: Thu, 16 Sep 2021 15:32:05 +0800 Subject: [PATCH 6/6] Remove unused arguments --- python/taichi/lang/matrix.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/python/taichi/lang/matrix.py b/python/taichi/lang/matrix.py index 8521c5a2e5f8f..2a0e96042b0c5 100644 --- a/python/taichi/lang/matrix.py +++ b/python/taichi/lang/matrix.py @@ -28,10 +28,6 @@ class Matrix(TaichiOperations): n (int): the first dimension of a matrix. m (int): the second dimension of a matrix. 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. - 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. """ is_taichi_class = True @@ -1197,21 +1193,18 @@ def outer_product(self, other): return ret -# TODO: deprecate ad-hoc use ti.Matrix() as global (#1500:2.2/2) -def Vector(n, dt=None, shape=None, offset=None, **kwargs): +def Vector(n, dt=None, **kwargs): """Construct a `Vector` instance i.e. 1-D Matrix. Args: n (int): The desired number of entries of the Vector. dt (DataType, optional): The desired data type of the Vector. - shape ( Union[int, tuple of int], optional): The shape of the Vector. - offset (Union[int, tuple of int], optional): The coordinate offset of all elements in a field. Returns: :class:`~taichi.lang.matrix.Matrix`: A Vector instance (1-D :class:`~taichi.lang.matrix.Matrix`). """ - return Matrix(n, 1, dt=dt, shape=shape, offset=offset, **kwargs) + return Matrix(n, 1, dt=dt, **kwargs) Vector.var = Matrix._Vector_var