From 4806073f29f9f6130a85d21817fdf90e068bce57 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Mon, 16 Oct 2023 16:14:53 +0800 Subject: [PATCH] rename `_ndim_` -> `_ndim`; delete `with paddle.pir_utils.IrGuard():` --- python/paddle/base/dygraph/math_op_patch.py | 4 ++-- python/paddle/base/layers/math_op_patch.py | 4 ++-- python/paddle/pir/math_op_patch.py | 25 +++++++++------------ 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/python/paddle/base/dygraph/math_op_patch.py b/python/paddle/base/dygraph/math_op_patch.py index 5972b545f93e2..172f73bf7f531 100644 --- a/python/paddle/base/dygraph/math_op_patch.py +++ b/python/paddle/base/dygraph/math_op_patch.py @@ -150,7 +150,7 @@ def _index_(var): return int(np.array(var)) @property - def _ndim_(var): + def _ndim(var): return len(var.shape) def ndimension(var): @@ -183,7 +183,7 @@ def _T_(var): ('astype', astype), ('dim', dim), ('ndimension', ndimension), - ('ndim', _ndim_), + ('ndim', _ndim), ('size', _size_), ('T', _T_), # for logical compare diff --git a/python/paddle/base/layers/math_op_patch.py b/python/paddle/base/layers/math_op_patch.py index d47184f78a87c..1f070882758b9 100644 --- a/python/paddle/base/layers/math_op_patch.py +++ b/python/paddle/base/layers/math_op_patch.py @@ -376,7 +376,7 @@ def _neg_(var): return _scalar_op_(var, -1.0, 0.0) @property - def _ndim_(self): + def _ndim(self): """ Returns the dimension of current Variable @@ -627,7 +627,7 @@ def to_dense(var): ('pop', pop), ('dim', dim), ('ndimension', ndimension), - ('ndim', _ndim_), + ('ndim', _ndim), ( '__add__', _binary_creator_('__add__', 'elementwise_add', False, _scalar_add_), diff --git a/python/paddle/pir/math_op_patch.py b/python/paddle/pir/math_op_patch.py index 76c6f7389e831..fdb72691e4e6d 100644 --- a/python/paddle/pir/math_op_patch.py +++ b/python/paddle/pir/math_op_patch.py @@ -76,7 +76,7 @@ def place(self): ) @property - def _ndim_(self): + def _ndim(self): """ Returns the dimension of current OpResult @@ -91,10 +91,9 @@ def _ndim_(self): >>> paddle.enable_static() >>> # create a static OpResult - >>> with paddle.pir_utils.IrGuard(): - >>> x = paddle.static.data(name='x', shape=[3, 2, 1]) - >>> # print the dimension of the OpResult - >>> print(x.ndim) + >>> x = paddle.static.data(name='x', shape=[3, 2, 1]) + >>> # print the dimension of the OpResult + >>> print(x.ndim) 3 """ return len(self.shape) @@ -114,10 +113,9 @@ def ndimension(self): >>> paddle.enable_static() >>> # create a static OpResult - >>> with paddle.pir_utils.IrGuard(): - >>> x = paddle.static.data(name='x', shape=[3, 2, 1]) - >>> # print the dimension of the OpResult - >>> print(x.ndimension()) + >>> x = paddle.static.data(name='x', shape=[3, 2, 1]) + >>> # print the dimension of the OpResult + >>> print(x.ndimension()) 3 """ return len(self.shape) @@ -137,10 +135,9 @@ def dim(self): >>> paddle.enable_static() >>> # create a static OpResult - >>> with paddle.pir_utils.IrGuard(): - >>> x = paddle.static.data(name='x', shape=[3, 2, 1]) - >>> # print the dimension of the OpResult - >>> print(x.dim()) + >>> x = paddle.static.data(name='x', shape=[3, 2, 1]) + >>> # print the dimension of the OpResult + >>> print(x.dim()) 3 """ return len(self.shape) @@ -263,7 +260,7 @@ def __impl__(self, other_var): ('item', _item), ('dim', dim), ('ndimension', ndimension), - ('ndim', _ndim_), + ('ndim', _ndim), ( '__div__', _binary_creator_(