mindspore.ops.nextafter

查看源文件
mindspore.ops.nextafter(input, other)[源代码]

逐元素计算 input 指向 other 的下一个可表示浮点值。

\[\begin{split}out_i = \begin{cases} & input_i + eps, & \text{if } input_i < other_i \\ & input_i - eps, & \text{if } input_i > other_i \\ & input_i, & \text{if } input_i = other_i \end{cases}\end{split}\]

其中eps为输入tensor数据类型最小可表示增量值。

更多详细信息请参见 A Self Regularized Non-Monotonic Neural Activation Function

参数:
  • input (Tensor) - 第一个输入tensor

  • other (Tensor) - 第二个输入tensor。

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> import numpy as np
>>> eps = np.finfo(np.float32).eps
>>> input = mindspore.tensor([1.0], mindspore.float32)
>>> other = mindspore.tensor([2.0], mindspore.float32)
>>> output = mindspore.ops.nextafter(input, other)
>>> print(output == eps + 1)
[ True]
>>> input = mindspore.tensor([1.0, 2.0], mindspore.float32)
>>> other = mindspore.tensor([2.0, 1.0], mindspore.float32)
>>> output = mindspore.ops.nextafter(input, other)
>>> print(output == mindspore.tensor([eps + 1, 2 - eps], mindspore.float32))
[ True True]