From a3ef01e8dc2f6e35a749b04cd80a8f0900b005f0 Mon Sep 17 00:00:00 2001 From: Yi Xu Date: Thu, 18 Nov 2021 15:21:14 +0800 Subject: [PATCH 1/3] Remove disable_local_tensor and empty() from Matrix --- python/taichi/lang/matrix.py | 23 +++-------------------- python/taichi/lang/struct.py | 12 ------------ 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/python/taichi/lang/matrix.py b/python/taichi/lang/matrix.py index 51399376a408d..762a4218dfbfb 100644 --- a/python/taichi/lang/matrix.py +++ b/python/taichi/lang/matrix.py @@ -24,7 +24,7 @@ class Matrix(TaichiOperations): """The matrix class. Args: - n (Union[int, list, tuple], np.ndarray): the first dimension of a matrix. + n (Union[int, list, tuple, np.ndarray]): the first dimension of a matrix. m (int): the second dimension of a matrix. dt (DataType): the element data type. """ @@ -34,7 +34,6 @@ def __init__(self, n=1, m=1, dt=None, - disable_local_tensor=False, suppress_warning=False): self.local_tensor_proxy = None self.any_array_access = None @@ -49,8 +48,7 @@ def __init__(self, elif not isinstance(n[0], Iterable): # now init a Vector if in_python_scope(): mat = [[x] for x in n] - elif disable_local_tensor or not ti.current_cfg( - ).dynamic_index: + elif not ti.current_cfg().dynamic_index: mat = [[impl.expr_init(x)] for x in n] else: if not ti.is_extension_supported( @@ -88,8 +86,7 @@ def __init__(self, else: # now init a Matrix if in_python_scope(): mat = [list(row) for row in n] - elif disable_local_tensor or not ti.current_cfg( - ).dynamic_index: + elif not ti.current_cfg().dynamic_index: mat = [[impl.expr_init(x) for x in row] for row in n] else: if not ti.is_extension_supported( @@ -1012,20 +1009,6 @@ def cols(cols): """ return Matrix.rows(cols).transpose() - @classmethod - def empty(cls, n, m): - """Clear the matrix and fill None. - - Args: - n (int): The number of the row of the matrix. - m (int): The number of the column of the matrix. - - Returns: - :class:`~taichi.lang.matrix.Matrix`: A :class:`~taichi.lang.matrix.Matrix` instance filled with None. - - """ - return cls([[None] * m for _ in range(n)], disable_local_tensor=True) - def __hash__(self): # TODO: refactor KernelTemplateMapper # If not, we get `unhashable type: Matrix` when diff --git a/python/taichi/lang/struct.py b/python/taichi/lang/struct.py index 4b336db477d1c..d0d0ee9a4290f 100644 --- a/python/taichi/lang/struct.py +++ b/python/taichi/lang/struct.py @@ -214,18 +214,6 @@ def to_dict(self): """ return self.entries - @classmethod - def empty(cls, entries): - """Clear the struct and fill None. - - Args: - members (Dict[str, DataType]): the names and data types for struct members. - Returns: - :class:`~taichi.lang.struct.Struct`: A :class:`~taichi.lang.struct.Struct` instance filled with None. - - """ - return cls({k: None for k in entries}) - @classmethod @python_scope def field(cls, From 0996cf7ed7a73e92f75acc65feed8e1c6afabea1 Mon Sep 17 00:00:00 2001 From: Taichi Gardener Date: Thu, 18 Nov 2021 07:26:45 +0000 Subject: [PATCH 2/3] Auto Format --- python/taichi/lang/matrix.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/python/taichi/lang/matrix.py b/python/taichi/lang/matrix.py index 762a4218dfbfb..91fbc748fac95 100644 --- a/python/taichi/lang/matrix.py +++ b/python/taichi/lang/matrix.py @@ -30,11 +30,7 @@ class Matrix(TaichiOperations): """ is_taichi_class = True - def __init__(self, - n=1, - m=1, - dt=None, - suppress_warning=False): + def __init__(self, n=1, m=1, dt=None, suppress_warning=False): self.local_tensor_proxy = None self.any_array_access = None self.grad = None From a05f04df30bed0bfe0f5d9c681a593b48ccd0db1 Mon Sep 17 00:00:00 2001 From: Yi Xu Date: Thu, 18 Nov 2021 15:34:18 +0800 Subject: [PATCH 3/3] Fix --- tests/python/test_ast_refactor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/python/test_ast_refactor.py b/tests/python/test_ast_refactor.py index 6d12cd61846b6..c3d8f54d07779 100644 --- a/tests/python/test_ast_refactor.py +++ b/tests/python/test_ast_refactor.py @@ -849,8 +849,7 @@ def test_listcomp(): @ti.func def identity(dt, n: ti.template()): return ti.Matrix([[ti.cast(int(i == j), dt) for j in range(n)] - for i in range(n)], - disable_local_tensor=1) + for i in range(n)]) @ti.kernel def foo(n: ti.template()) -> ti.i32: