tensor_isneginf_isposinf_isreal_master
This commit is contained in:
parent
95c2260754
commit
6c8ffd93f9
|
@ -0,0 +1,6 @@
|
|||
mindspore.Tensor.isneginf
|
||||
=========================
|
||||
|
||||
.. py:method:: mindspore.Tensor.isneginf()
|
||||
|
||||
详情请参考 :func:`mindspore.ops.isneginf`。
|
|
@ -0,0 +1,6 @@
|
|||
mindspore.Tensor.isposinf
|
||||
=========================
|
||||
|
||||
.. py:method:: mindspore.Tensor.isposinf()
|
||||
|
||||
详情请参考 :func:`mindspore.ops.isposinf`。
|
|
@ -0,0 +1,6 @@
|
|||
mindspore.Tensor.isreal
|
||||
=======================
|
||||
|
||||
.. py:method:: mindspore.Tensor.isreal()
|
||||
|
||||
详情请参考 :func:`mindspore.ops.isreal`。
|
|
@ -134,6 +134,9 @@ mindspore.Tensor
|
|||
mindspore.Tensor.is_floating_point
|
||||
mindspore.Tensor.isinf
|
||||
mindspore.Tensor.isnan
|
||||
mindspore.Tensor.isneginf
|
||||
mindspore.Tensor.isposinf
|
||||
mindspore.Tensor.isreal
|
||||
mindspore.Tensor.is_signed
|
||||
mindspore.Tensor.item
|
||||
mindspore.Tensor.itemset
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
mindspore.ops.isneginf
|
||||
======================
|
||||
|
||||
.. py:function:: mindspore.ops.isneginf(x)
|
||||
|
||||
逐元素判断是否是负inf。
|
||||
|
||||
参数:
|
||||
- **x** (Tensor) - 输入Tensor。
|
||||
|
||||
返回:
|
||||
Tensor,对应 `x` 元素为负inf的位置是true,反之为false。
|
||||
|
||||
异常:
|
||||
- **TypeError** - `x` 不是Tensor。
|
|
@ -0,0 +1,15 @@
|
|||
mindspore.ops.isposinf
|
||||
======================
|
||||
|
||||
.. py:function:: mindspore.ops.isposinf(x)
|
||||
|
||||
逐元素判断是否是正inf。
|
||||
|
||||
参数:
|
||||
- **x** (Tensor) - 输入Tensor。
|
||||
|
||||
返回:
|
||||
Tensor,对应 `x` 元素为正inf的位置是true,反之为false。
|
||||
|
||||
异常:
|
||||
- **TypeError** - `x` 不是Tensor。
|
|
@ -0,0 +1,16 @@
|
|||
mindspore.ops.isreal
|
||||
====================
|
||||
|
||||
.. py:function:: mindspore.ops.isreal(x)
|
||||
|
||||
逐元素判断是否为实数。
|
||||
一个复数的虚部是0时也被看作是实数。
|
||||
|
||||
参数:
|
||||
- **x** (Tensor) - 输入Tensor。
|
||||
|
||||
返回:
|
||||
Tensor,对应 `x` 元素为负inf的位置是true,反之为false。
|
||||
|
||||
异常:
|
||||
- **TypeError** - `x` 不是Tensor。
|
|
@ -140,6 +140,9 @@
|
|||
mindspore.Tensor.is_floating_point
|
||||
mindspore.Tensor.isinf
|
||||
mindspore.Tensor.isnan
|
||||
mindspore.Tensor.isneginf
|
||||
mindspore.Tensor.isposinf
|
||||
mindspore.Tensor.isreal
|
||||
mindspore.Tensor.is_signed
|
||||
mindspore.Tensor.item
|
||||
mindspore.Tensor.itemset
|
||||
|
|
|
@ -261,6 +261,9 @@ BuiltInTypeMap &GetMethodMap() {
|
|||
{"logaddexp", std::string("logaddexp")}, // logaddexp()
|
||||
{"logaddexp2", std::string("logaddexp2")}, // logaddexp2()
|
||||
{"logsumexp", std::string("logsumexp")}, // logsumexp()
|
||||
{"isneginf", std::string("isneginf")}, // isneginf()
|
||||
{"isposinf", std::string("isposinf")}, // isposinf()
|
||||
{"isreal", std::string("isreal")}, // isreal()
|
||||
{"minimum", std::string("minimum")}, // P.Minimum()
|
||||
{"cosh", std::string("cosh")}, // P.Cosh()
|
||||
{"tanh", std::string("tanh")}, // P.Tanh()
|
||||
|
|
|
@ -1374,6 +1374,27 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
|
|||
return F.isclose(x1, x2, rtol, atol, equal_nan)
|
||||
|
||||
|
||||
def isneginf(x):
|
||||
"""
|
||||
Tests element-wise for negative infinity, returns result as bool array.
|
||||
"""
|
||||
return F.isneginf(x)
|
||||
|
||||
|
||||
def isposinf(x):
|
||||
"""
|
||||
Tests element-wise for positive infinity, returns result as bool array.
|
||||
"""
|
||||
return F.isposinf(x)
|
||||
|
||||
|
||||
def isreal(x):
|
||||
"""
|
||||
Tests element-wise for real number.
|
||||
"""
|
||||
return F.isreal(x)
|
||||
|
||||
|
||||
def flip(x, dims):
|
||||
"""
|
||||
For details, please refer to :func:`mindspore.ops.flip`.
|
||||
|
|
|
@ -1464,6 +1464,24 @@ class Tensor(Tensor_):
|
|||
self._init_check()
|
||||
return tensor_operator_registry.get('isclose')(self, x2, rtol, atol, equal_nan)
|
||||
|
||||
def isneginf(self):
|
||||
r"""
|
||||
For details, please refer to :func:`mindspore.ops.isneginf`.
|
||||
"""
|
||||
return tensor_operator_registry.get('isneginf')(self)
|
||||
|
||||
def isposinf(self):
|
||||
r"""
|
||||
For details, please refer to :func:`mindspore.ops.isposinf`.
|
||||
"""
|
||||
return tensor_operator_registry.get('isposinf')(self)
|
||||
|
||||
def isreal(self):
|
||||
r"""
|
||||
For details, please refer to :func:`mindspore.ops.isreal`.
|
||||
"""
|
||||
return tensor_operator_registry.get('isreal')(self)
|
||||
|
||||
def isfinite(self):
|
||||
r"""
|
||||
For details, please refer to :func:`mindspore.ops.isfinite`.
|
||||
|
|
|
@ -186,6 +186,8 @@ from .math_func import (
|
|||
equal,
|
||||
not_equal,
|
||||
ne,
|
||||
isneginf,
|
||||
isposinf,
|
||||
isfinite,
|
||||
isnan,
|
||||
isclose,
|
||||
|
|
|
@ -3265,15 +3265,14 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
|
|||
|
||||
def isreal(x):
|
||||
"""
|
||||
Returns a new tensor with boolean elements representing whether each element of `x` is real-valued.
|
||||
All real value types are considered real numbers.
|
||||
Tests element-wise for real number.
|
||||
A complex value is considered real when its imaginary part is 0.
|
||||
|
||||
Inputs:
|
||||
- **x** (Tensor) - The input tensor.
|
||||
|
||||
Outputs:
|
||||
Tensor, has the same shape of input, and the dtype is bool.
|
||||
Returns:
|
||||
Tensor, true where `x` is real number, false otherwise.
|
||||
|
||||
Raises:
|
||||
TypeError: If `x` is not a Tensor.
|
||||
|
@ -7312,6 +7311,66 @@ def isinf(input):
|
|||
return isinf_op(input)
|
||||
|
||||
|
||||
def _is_sign_inf(x, fn):
|
||||
"""Tests element-wise for inifinity with sign."""
|
||||
shape = x.shape
|
||||
zeros_tensor = _get_cache_prim(P.Zeros)()(shape, mstype.float32)
|
||||
ones_tensor = _get_cache_prim(P.Ones)()(shape, mstype.float32)
|
||||
is_inf = _get_cache_prim(P.IsInf)()(x)
|
||||
is_sign = fn(x, zeros_tensor)
|
||||
res = ops.select(is_inf, ones_tensor, zeros_tensor)
|
||||
res = ops.select(is_sign, res, zeros_tensor)
|
||||
return _get_cache_prim(P.Cast)()(res, mstype.bool_)
|
||||
|
||||
|
||||
def isposinf(x):
|
||||
"""
|
||||
Tests element-wise for positive infinity.
|
||||
|
||||
Args:
|
||||
x (Tensor): Input values.
|
||||
|
||||
Returns:
|
||||
Tensor, true where `x` is positive infinity, false otherwise.
|
||||
|
||||
Raises:
|
||||
TypeError: If the input is not a tensor.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``GPU`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> output = ops.isposinf(Tensor([-float("inf"), float("inf"), 1.2], ms.float32))
|
||||
>>> print(output)
|
||||
[False True False]
|
||||
"""
|
||||
return _is_sign_inf(x, tensor_gt)
|
||||
|
||||
|
||||
def isneginf(x):
|
||||
"""
|
||||
Tests element-wise for negative infinity.
|
||||
|
||||
Args:
|
||||
x (Tensor): Input Tensor.
|
||||
|
||||
Returns:
|
||||
Tensor, true where `x` is negative infinity, false otherwise.
|
||||
|
||||
Raises:
|
||||
TypeError: If the input is not a tensor.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``GPU`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> output = ops.isneginf(Tensor([-float("inf"), float("inf"), 1.2], ms.float32))
|
||||
>>> print(output)
|
||||
[ True False False]
|
||||
"""
|
||||
return _is_sign_inf(x, tensor_lt)
|
||||
|
||||
|
||||
def logical_xor(input, other):
|
||||
r"""
|
||||
Computes the "logical XOR" of two tensors element-wise.
|
||||
|
@ -7447,6 +7506,8 @@ __all__ = [
|
|||
'isnan',
|
||||
'isclose',
|
||||
'isreal',
|
||||
'isneginf',
|
||||
'isposinf',
|
||||
'log',
|
||||
'log_matrix_determinant',
|
||||
'matrix_determinant',
|
||||
|
|
|
@ -200,6 +200,9 @@ tensor_operator_registry.register('masked_select', masked_select)
|
|||
tensor_operator_registry.register('nonzero', nonzero)
|
||||
tensor_operator_registry.register('i0', i0)
|
||||
tensor_operator_registry.register('isclose', isclose)
|
||||
tensor_operator_registry.register('isneginf', isneginf)
|
||||
tensor_operator_registry.register('isposinf', isposinf)
|
||||
tensor_operator_registry.register('isreal', isreal)
|
||||
tensor_operator_registry.register('inv', inv)
|
||||
tensor_operator_registry.register('logaddexp', logaddexp)
|
||||
tensor_operator_registry.register('logaddexp2', logaddexp2)
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
# 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 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.isneginf(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_isneginf(mode):
|
||||
"""
|
||||
Feature: ops.isneginf
|
||||
Description: Verify the result of isneginf
|
||||
Expectation: success
|
||||
"""
|
||||
ms.set_context(mode=mode)
|
||||
x = Tensor([-float("inf"), float("inf"), 1.2], ms.float32)
|
||||
net = Net()
|
||||
output = net(x)
|
||||
expect_output = Tensor([True, False, False])
|
||||
assert all(output == expect_output)
|
|
@ -0,0 +1,46 @@
|
|||
# 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 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.isposinf(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_isposinf(mode):
|
||||
"""
|
||||
Feature: ops.isposinf
|
||||
Description: Verify the result of isposinf
|
||||
Expectation: success
|
||||
"""
|
||||
ms.set_context(mode=mode)
|
||||
x = Tensor([-float("inf"), float("inf"), 1.2], ms.float32)
|
||||
net = Net()
|
||||
output = net(x)
|
||||
expect_output = Tensor([False, True, False])
|
||||
assert all(output == expect_output)
|
|
@ -0,0 +1,44 @@
|
|||
# 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 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.isreal(x)
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.platform_arm_cpu
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
|
||||
def test_ops_isreal(mode):
|
||||
"""
|
||||
Feature: ops.isreal
|
||||
Description: Verify the result of isreal
|
||||
Expectation: success
|
||||
"""
|
||||
ms.set_context(mode=mode)
|
||||
x = Tensor([1, 1+1j, 2+0j])
|
||||
net = Net()
|
||||
output = net(x)
|
||||
expect_output = Tensor([True, False, True])
|
||||
assert all(output == expect_output)
|
|
@ -0,0 +1,46 @@
|
|||
# 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 pytest
|
||||
|
||||
import mindspore as ms
|
||||
import mindspore.nn as nn
|
||||
from mindspore import Tensor
|
||||
|
||||
|
||||
class Net(nn.Cell):
|
||||
def construct(self, x):
|
||||
return x.isneginf()
|
||||
|
||||
|
||||
@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_tensor_isneginf(mode):
|
||||
"""
|
||||
Feature: tensor.isneginf
|
||||
Description: Verify the result of isneginf
|
||||
Expectation: success
|
||||
"""
|
||||
ms.set_context(mode=mode)
|
||||
x = Tensor([-float("inf"), float("inf"), 1.2], ms.float32)
|
||||
net = Net()
|
||||
output = net(x)
|
||||
expect_output = Tensor([True, False, False])
|
||||
assert all(output == expect_output)
|
|
@ -0,0 +1,46 @@
|
|||
# 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 pytest
|
||||
|
||||
import mindspore as ms
|
||||
import mindspore.nn as nn
|
||||
from mindspore import Tensor
|
||||
|
||||
|
||||
class Net(nn.Cell):
|
||||
def construct(self, x):
|
||||
return x.isposinf()
|
||||
|
||||
|
||||
@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_tensor_isposinf(mode):
|
||||
"""
|
||||
Feature: tensor.isposinf
|
||||
Description: Verify the result of isposinf
|
||||
Expectation: success
|
||||
"""
|
||||
ms.set_context(mode=mode)
|
||||
x = Tensor([-float("inf"), float("inf"), 1.2], ms.float32)
|
||||
net = Net()
|
||||
output = net(x)
|
||||
expect_output = Tensor([False, True, False])
|
||||
assert all(output == expect_output)
|
|
@ -0,0 +1,44 @@
|
|||
# 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 pytest
|
||||
|
||||
import mindspore as ms
|
||||
import mindspore.nn as nn
|
||||
from mindspore import Tensor
|
||||
|
||||
|
||||
class Net(nn.Cell):
|
||||
def construct(self, x):
|
||||
return x.isreal()
|
||||
|
||||
|
||||
@pytest.mark.level0
|
||||
@pytest.mark.platform_x86_cpu
|
||||
@pytest.mark.platform_arm_cpu
|
||||
@pytest.mark.platform_x86_gpu_training
|
||||
@pytest.mark.env_onecard
|
||||
@pytest.mark.parametrize('mode', [ms.GRAPH_MODE, ms.PYNATIVE_MODE])
|
||||
def test_tensor_isreal(mode):
|
||||
"""
|
||||
Feature: tensor.isreal
|
||||
Description: Verify the result of isreal
|
||||
Expectation: success
|
||||
"""
|
||||
ms.set_context(mode=mode)
|
||||
x = Tensor([1, 1+1j, 2+0j])
|
||||
net = Net()
|
||||
output = net(x)
|
||||
expect_output = Tensor([True, False, True])
|
||||
assert all(output == expect_output)
|
Loading…
Reference in New Issue