add_negative_ops

This commit is contained in:
yide12 2022-11-09 10:21:40 +08:00 committed by yide12
parent e332250070
commit 6eb55385c1
7 changed files with 70 additions and 2 deletions

View File

@ -202,6 +202,7 @@ mindspore.ops.function
mindspore.ops.matrix_determinant
mindspore.ops.mul
mindspore.ops.neg
mindspore.ops.negative
mindspore.ops.positive
mindspore.ops.pow
mindspore.ops.roll

View File

@ -0,0 +1,8 @@
mindspore.ops.negative
=======================
.. py:function:: mindspore.ops.negative(x)
ops.neg()的别名。
详情请参考 :func:`mindspore.ops.neg`

View File

@ -13,4 +13,5 @@ mindspore.ops.permute
Tensor具有和输入Tensor相同的维数按照 `dims` 重新排列。
异常:
- **ValueError** - `dims` 为None。
- **ValueError** - `dims` 的元素总量不等于 `x` 的维数。

View File

@ -203,6 +203,7 @@ Element-by-Element Operations
mindspore.ops.matrix_determinant
mindspore.ops.mul
mindspore.ops.neg
mindspore.ops.negative
mindspore.ops.positive
mindspore.ops.pow
mindspore.ops.roll

View File

@ -141,6 +141,7 @@ from .math_func import (
addcmul,
neg_tensor,
neg,
negative,
tensor_lt,
less,
tensor_le,

View File

@ -467,6 +467,14 @@ def neg(x):
return neg_tensor(x)
def negative(x):
r"""
Alias for ops.neg().
For details, please refer to :func:`mindspore.ops.neg`.
"""
return neg_tensor(x)
def positive(x):
r"""
Return self Tensor.
@ -528,8 +536,8 @@ def permute(x, dims):
Tensor, has the same dimension as input tensor, with `dims` suitably permuted.
Raises:
ValueError: If `dims` is none.
ValueError: If the number of `dims` is not equal to Tensor's ndim.
ValueError: If `dims` is None.
ValueError: If the number of elements of `dims` is not equal to `x` ndim.
Supported Platforms:
``Ascend`` ``GPU`` ``CPU``
@ -7022,6 +7030,7 @@ __all__ = [
'arctan2',
'neg_tensor',
'neg',
'negative',
'tensor_lt',
'less',
'logaddexp2',

View File

@ -0,0 +1,47 @@
# Copyright 2022 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
import numpy as np
import pytest
import mindspore as ms
import mindspore.nn as nn
from mindspore import Tensor, ops
class Net(nn.Cell):
def construct(self, x):
return ops.negative(x)
@pytest.mark.level0
@pytest.mark.platform_x86_cpu
@pytest.mark.platform_arm_cpu
@pytest.mark.platform_x86_gpu_training
@pytest.mark.platform_arm_ascend_training
@pytest.mark.platform_x86_ascend_training
@pytest.mark.env_onecard
@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
def test_ops_negative(mode):
"""
Feature: ops.negative
Description: Verify the result of negative
Expectation: success
"""
ms.set_context(mode=mode)
x = Tensor(np.array([-5.0, 1.5, 3.0, 100.0]), ms.float32)
net = Net()
output = net(x)
expect_output = [5.0, -1.5, -3.0, -100.0]
assert np.allclose(output.asnumpy(), expect_output)