add_negative_ops
This commit is contained in:
parent
e332250070
commit
6eb55385c1
|
@ -202,6 +202,7 @@ mindspore.ops.function
|
||||||
mindspore.ops.matrix_determinant
|
mindspore.ops.matrix_determinant
|
||||||
mindspore.ops.mul
|
mindspore.ops.mul
|
||||||
mindspore.ops.neg
|
mindspore.ops.neg
|
||||||
|
mindspore.ops.negative
|
||||||
mindspore.ops.positive
|
mindspore.ops.positive
|
||||||
mindspore.ops.pow
|
mindspore.ops.pow
|
||||||
mindspore.ops.roll
|
mindspore.ops.roll
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
mindspore.ops.negative
|
||||||
|
=======================
|
||||||
|
|
||||||
|
.. py:function:: mindspore.ops.negative(x)
|
||||||
|
|
||||||
|
ops.neg()的别名。
|
||||||
|
|
||||||
|
详情请参考 :func:`mindspore.ops.neg`。
|
|
@ -13,4 +13,5 @@ mindspore.ops.permute
|
||||||
Tensor,具有和输入Tensor相同的维数,按照 `dims` 重新排列。
|
Tensor,具有和输入Tensor相同的维数,按照 `dims` 重新排列。
|
||||||
|
|
||||||
异常:
|
异常:
|
||||||
|
- **ValueError** - `dims` 为None。
|
||||||
- **ValueError** - `dims` 的元素总量不等于 `x` 的维数。
|
- **ValueError** - `dims` 的元素总量不等于 `x` 的维数。
|
||||||
|
|
|
@ -203,6 +203,7 @@ Element-by-Element Operations
|
||||||
mindspore.ops.matrix_determinant
|
mindspore.ops.matrix_determinant
|
||||||
mindspore.ops.mul
|
mindspore.ops.mul
|
||||||
mindspore.ops.neg
|
mindspore.ops.neg
|
||||||
|
mindspore.ops.negative
|
||||||
mindspore.ops.positive
|
mindspore.ops.positive
|
||||||
mindspore.ops.pow
|
mindspore.ops.pow
|
||||||
mindspore.ops.roll
|
mindspore.ops.roll
|
||||||
|
|
|
@ -141,6 +141,7 @@ from .math_func import (
|
||||||
addcmul,
|
addcmul,
|
||||||
neg_tensor,
|
neg_tensor,
|
||||||
neg,
|
neg,
|
||||||
|
negative,
|
||||||
tensor_lt,
|
tensor_lt,
|
||||||
less,
|
less,
|
||||||
tensor_le,
|
tensor_le,
|
||||||
|
|
|
@ -467,6 +467,14 @@ def neg(x):
|
||||||
return neg_tensor(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):
|
def positive(x):
|
||||||
r"""
|
r"""
|
||||||
Return self Tensor.
|
Return self Tensor.
|
||||||
|
@ -528,8 +536,8 @@ def permute(x, dims):
|
||||||
Tensor, has the same dimension as input tensor, with `dims` suitably permuted.
|
Tensor, has the same dimension as input tensor, with `dims` suitably permuted.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If `dims` is none.
|
ValueError: If `dims` is None.
|
||||||
ValueError: If the number of `dims` is not equal to Tensor's ndim.
|
ValueError: If the number of elements of `dims` is not equal to `x` ndim.
|
||||||
|
|
||||||
Supported Platforms:
|
Supported Platforms:
|
||||||
``Ascend`` ``GPU`` ``CPU``
|
``Ascend`` ``GPU`` ``CPU``
|
||||||
|
@ -7022,6 +7030,7 @@ __all__ = [
|
||||||
'arctan2',
|
'arctan2',
|
||||||
'neg_tensor',
|
'neg_tensor',
|
||||||
'neg',
|
'neg',
|
||||||
|
'negative',
|
||||||
'tensor_lt',
|
'tensor_lt',
|
||||||
'less',
|
'less',
|
||||||
'logaddexp2',
|
'logaddexp2',
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue