From cf84147331612b90adff640c6650959c4efdccb6 Mon Sep 17 00:00:00 2001 From: lin-hitonami Date: Fri, 5 May 2023 15:54:56 +0800 Subject: [PATCH 1/3] [Lang] Remove a.atomic(b) --- python/taichi/lang/common_ops.py | 20 -------------------- tests/python/test_deprecation.py | 15 --------------- 2 files changed, 35 deletions(-) diff --git a/python/taichi/lang/common_ops.py b/python/taichi/lang/common_ops.py index 630d853d858f4..478d0805d8988 100644 --- a/python/taichi/lang/common_ops.py +++ b/python/taichi/lang/common_ops.py @@ -1,5 +1,3 @@ -import warnings - from taichi.lang import ops from taichi.lang.util import in_python_scope from taichi.types import primitive_types @@ -8,24 +6,6 @@ class TaichiOperations: """The base class of taichi operations of expressions. Subclasses: :class:`~taichi.lang.expr.Expr`, :class:`~taichi.lang.matrix.Matrix`""" - __deprecated_atomic_ops__ = { - "atomic_add": "_atomic_add", - "atomic_mul": "_atomic_mul", - "atomic_and": "_atomic_and", - "atomic_or": "_atomic_or", - "atomic_sub": "_atomic_sub", - "atomic_xor": "_atomic_xor", - } - - def __getattr__(self, item): - if item in TaichiOperations.__deprecated_atomic_ops__: - warnings.warn( - f"a.{item}(b) is deprecated, and it will be removed in Taichi v1.6.0. Please use ti.{item}(a, b) instead.", - DeprecationWarning, - ) - return getattr(self, TaichiOperations.__deprecated_atomic_ops__[item]) - raise AttributeError(f"'{type(self).__name__}' object has no attribute '{item}'") - def __neg__(self): return ops.neg(self) diff --git a/tests/python/test_deprecation.py b/tests/python/test_deprecation.py index 83b8d8b9a507f..af2ccf94df6d0 100644 --- a/tests/python/test_deprecation.py +++ b/tests/python/test_deprecation.py @@ -8,21 +8,6 @@ from tests import test_utils -@test_utils.test() -def test_deprecate_a_atomic_b(): - with pytest.warns( - DeprecationWarning, - match=r"a\.atomic_add\(b\) is deprecated, and it will be removed in Taichi v1.6.0.", - ): - - @ti.kernel - def func(): - a = 1 - a.atomic_add(2) - - func() - - @test_utils.test() def test_deprecate_element_shape_scalar(): with pytest.warns( From 7735030f78a6025d3dbd9f5fe64742462ed92bb3 Mon Sep 17 00:00:00 2001 From: lin-hitonami Date: Fri, 5 May 2023 15:54:56 +0800 Subject: [PATCH 2/3] [Lang] Remove a.atomic(b) --- python/taichi/lang/common_ops.py | 20 -------------------- tests/python/test_deprecation.py | 15 --------------- 2 files changed, 35 deletions(-) diff --git a/python/taichi/lang/common_ops.py b/python/taichi/lang/common_ops.py index 630d853d858f4..478d0805d8988 100644 --- a/python/taichi/lang/common_ops.py +++ b/python/taichi/lang/common_ops.py @@ -1,5 +1,3 @@ -import warnings - from taichi.lang import ops from taichi.lang.util import in_python_scope from taichi.types import primitive_types @@ -8,24 +6,6 @@ class TaichiOperations: """The base class of taichi operations of expressions. Subclasses: :class:`~taichi.lang.expr.Expr`, :class:`~taichi.lang.matrix.Matrix`""" - __deprecated_atomic_ops__ = { - "atomic_add": "_atomic_add", - "atomic_mul": "_atomic_mul", - "atomic_and": "_atomic_and", - "atomic_or": "_atomic_or", - "atomic_sub": "_atomic_sub", - "atomic_xor": "_atomic_xor", - } - - def __getattr__(self, item): - if item in TaichiOperations.__deprecated_atomic_ops__: - warnings.warn( - f"a.{item}(b) is deprecated, and it will be removed in Taichi v1.6.0. Please use ti.{item}(a, b) instead.", - DeprecationWarning, - ) - return getattr(self, TaichiOperations.__deprecated_atomic_ops__[item]) - raise AttributeError(f"'{type(self).__name__}' object has no attribute '{item}'") - def __neg__(self): return ops.neg(self) diff --git a/tests/python/test_deprecation.py b/tests/python/test_deprecation.py index 83b8d8b9a507f..af2ccf94df6d0 100644 --- a/tests/python/test_deprecation.py +++ b/tests/python/test_deprecation.py @@ -8,21 +8,6 @@ from tests import test_utils -@test_utils.test() -def test_deprecate_a_atomic_b(): - with pytest.warns( - DeprecationWarning, - match=r"a\.atomic_add\(b\) is deprecated, and it will be removed in Taichi v1.6.0.", - ): - - @ti.kernel - def func(): - a = 1 - a.atomic_add(2) - - func() - - @test_utils.test() def test_deprecate_element_shape_scalar(): with pytest.warns( From d1692f77962e5224a98272b97918c0dfe6a9c5ac Mon Sep 17 00:00:00 2001 From: lin-hitonami Date: Sat, 6 May 2023 14:04:31 +0800 Subject: [PATCH 3/3] make pylint happy --- python/taichi/lang/common_ops.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/taichi/lang/common_ops.py b/python/taichi/lang/common_ops.py index 478d0805d8988..e5ef364cb8795 100644 --- a/python/taichi/lang/common_ops.py +++ b/python/taichi/lang/common_ops.py @@ -1,11 +1,17 @@ from taichi.lang import ops from taichi.lang.util import in_python_scope from taichi.types import primitive_types +from typing import TYPE_CHECKING class TaichiOperations: """The base class of taichi operations of expressions. Subclasses: :class:`~taichi.lang.expr.Expr`, :class:`~taichi.lang.matrix.Matrix`""" + if TYPE_CHECKING: + # Make pylint happy + def __getattr__(self, item): + pass + def __neg__(self): return ops.neg(self)