Skip to content

Commit

Permalink
rename _ndim_ -> _ndim; delete with paddle.pir_utils.IrGuard():
Browse files Browse the repository at this point in the history
  • Loading branch information
gouzil committed Oct 16, 2023
1 parent 46bfd7c commit 4806073
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions python/paddle/base/dygraph/math_op_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -183,7 +183,7 @@ def _T_(var):
('astype', astype),
('dim', dim),
('ndimension', ndimension),
('ndim', _ndim_),
('ndim', _ndim),
('size', _size_),
('T', _T_),
# for logical compare
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/base/layers/math_op_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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_),
Expand Down
25 changes: 11 additions & 14 deletions python/paddle/pir/math_op_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def place(self):
)

@property
def _ndim_(self):
def _ndim(self):
"""
Returns the dimension of current OpResult
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -263,7 +260,7 @@ def __impl__(self, other_var):
('item', _item),
('dim', dim),
('ndimension', ndimension),
('ndim', _ndim_),
('ndim', _ndim),
(
'__div__',
_binary_creator_(
Expand Down

0 comments on commit 4806073

Please sign in to comment.