!45215 Add ops.absolute and tensor.absolute

Merge pull request !45215 from DavidFFFan/api
This commit is contained in:
i-robot 2022-11-08 02:53:33 +00:00 committed by Gitee
commit db9a328c6d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 38 additions and 3 deletions

View File

@ -143,6 +143,7 @@ mindspore.ops.function
:template: classtemplate.rst
mindspore.ops.abs
mindspore.ops.absolute
mindspore.ops.accumulate_n
mindspore.ops.acos
mindspore.ops.acosh

View File

@ -0,0 +1,8 @@
mindspore.Tensor.absolute
=========================
.. py:method:: mindspore.Tensor.absolute()
Tensor.abs()的别名。
详情请参考 :func:`mindspore.ops.abs`

View File

@ -21,6 +21,7 @@ mindspore.Tensor
:nosignatures:
mindspore.Tensor.abs
mindspore.Tensor.absolute
mindspore.Tensor.add
mindspore.Tensor.addcdiv
mindspore.Tensor.addcmul

View File

@ -0,0 +1,8 @@
mindspore.ops.absolute
======================
.. py:function:: mindspore.ops.absolute(x)
ops.abs()的别名。
详情请查看 :func:`mindspore.ops.abs`

View File

@ -27,6 +27,7 @@
:nosignatures:
mindspore.Tensor.abs
mindspore.Tensor.absolute
mindspore.Tensor.add
mindspore.Tensor.addcdiv
mindspore.Tensor.addcmul

View File

@ -173,6 +173,7 @@ BuiltInTypeMap &GetMethodMap() {
{"__matmul__", std::string("matmul")}, // F.matmul
{"xdivy", std::string("xdivy")}, // P.Xdivy
{"abs", std::string("abs_")}, // C.abs_
{"absolute", std::string("abs_")}, // C.abs_
{"mean", std::string("mean")}, // C.mean
{"prod", std::string("prod")}, // C.reduce_prod
{"__truediv__", std::string("truediv")}, // C.truediv

View File

@ -1400,6 +1400,13 @@ class Tensor(Tensor_):
self._init_check()
return tensor_operator_registry.get('abs')()(self)
def absolute(self):
"""
Alias for Tensor.abs().
For details, please refer to :func:`mindspore.ops.abs`.
"""
return self.abs()
def ceil(self):
"""
For details, please refer to :func:`mindspore.ops.ceil`.

View File

@ -63,7 +63,7 @@ from mindspore.ops.operations.math_ops import (
from mindspore.common.tensor import Tensor
from mindspore._checkparam import Validator as validator
from mindspore.ops._primitive_cache import _get_cache_prim
from ..._c_expression import Tensor as Tensor_
from mindspore._c_expression import Tensor as Tensor_
@constexpr
@ -83,7 +83,7 @@ def get_x_shape(x_shape):
#####################################
# Public Operation Functions.
#####################################
absolute = P.Abs()
absolute_ = P.Abs()
tensor_ceil = P.Ceil()
tensor_add = P.Add()
neg_tensor = P.Neg()
@ -228,7 +228,15 @@ def abs(x):
>>> print(output)
[1. 1. 0.]
"""
return absolute(x)
return absolute_(x)
def absolute(x):
"""
Alias for ops.abs().
For details, please refer to :func:`mindspore.ops.abs`.
"""
return abs(x)
def add(x, y):