Environment
Hardware Environment(Ascend/GPU/CPU):
/device cpu
Software Environment:
- MindSpore version (source or binary): MindSpore 2.9.0
- Python version (e.g., Python 3.7.5): Python 3.11.15
- OS platform and distribution (e.g., Linux Ubuntu 16.04): Ubuntu 24.04.1, Linux 6.17.0-29-generic, x86_64
- GCC/Compiler version (if compiled from source): gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Describe the current behavior
mindspore.ops.minimum appears to handle NaN incorrectly for float32 tensors.
When one operand contains NaN, calling ops.minimum(x, y) returns the numeric value from the other operand instead of preserving NaN.
Actual result:
[[-0.0, 0.0, -inf],
[-1.1046050786972046, -0.6005114316940308, -0.3333442807197571]]
The first element should remain NaN, but it is returned as -0.0.
Describe the expected behavior
NaN should be propagated by ops.minimum.
Expected result:
[[nan, 0.0, -inf],
[-1.1046050786972046, -0.6005114316940308, -0.3333442807197571]]
Steps to reproduce the issue
- Install MindSpore 2.9.0 and NumPy 1.26.4.
- Save the following script as
reproduce.py.
- Run
python reproduce.py.
import numpy as np
import mindspore as ms
import mindspore.ops.function as ops
x = ms.Tensor(
np.array(
[
[np.nan, np.inf, -np.inf],
[-1.1046050786972046, -0.6005114316940308, -0.3333442807197571],
],
dtype=np.float32,
)
)
y = ms.Tensor(
np.array(
[
[-0.0, 0.0, np.nextafter(np.float32(0.0), np.float32(1.0))],
[-1.0, 1.0, 9.999999974752427e-07],
],
dtype=np.float32,
)
)
wrong = ops.minimum(x, y).asnumpy()
correct = np.array(
[
[np.nan, 0.0, -np.inf],
[-1.1046050786972046, -0.6005114316940308, -0.3333442807197571],
],
dtype=np.float32,
)
print("wrong:", wrong.tolist())
print("correct:", correct.tolist())
Related log / screenshot
Running the script produces:
wrong: [[-0.0, 0.0, -inf], [-1.1046050786972046, -0.6005114316940308, -0.3333442807197571]]
correct: [[nan, 0.0, -inf], [-1.1046050786972046, -0.6005114316940308, -0.3333442807197571]]
Environment output:
Python version: 3.11.15
OS platform: Linux-6.17.0-29-generic-x86_64-with-glibc2.39
Machine: x86_64
MindSpore version: 2.9.0
NumPy version: 1.26.4
GCC version: gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Special notes for this issue
This looks like a NaN/Inf handling issue in ops.minimum.
For the first element, the operation is equivalent to:
The current result is:
The expected result is:
Other elements involving +Inf, -Inf, and finite values appear to be handled as expected in this example.
Environment
Hardware Environment(
Ascend/GPU/CPU):/device cpu
Software Environment:
Describe the current behavior
mindspore.ops.minimumappears to handleNaNincorrectly forfloat32tensors.When one operand contains
NaN, callingops.minimum(x, y)returns the numeric value from the other operand instead of preservingNaN.Actual result:
The first element should remain
NaN, but it is returned as-0.0.Describe the expected behavior
NaNshould be propagated byops.minimum.Expected result:
Steps to reproduce the issue
reproduce.py.python reproduce.py.Related log / screenshot
Running the script produces:
Environment output:
Special notes for this issue
This looks like a NaN/Inf handling issue in
ops.minimum.For the first element, the operation is equivalent to:
The current result is:
The expected result is:
Other elements involving
+Inf,-Inf, and finite values appear to be handled as expected in this example.