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.numpy.nancumsum appears to handle NaN/Inf values incorrectly for float32 tensors.
For the input:
[[nan, inf, -inf],
[-4.2111430168151855, -12.858903884887695, 4.690601348876953]]
calling:
returns:
[0.0, inf, nan, nan, nan, nan]
After the +Inf and -Inf values are accumulated together, the result becomes NaN, and the following cumulative values also remain NaN.
Describe the expected behavior
mnp.nancumsum should ignore NaN values and produce the expected accumulated float32 result.
Expected result:
[0.0, 3.4028234663852886e+38, 0.0, -4.2111430168151855, -17.07004737854004, -12.379446029663086]
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.numpy as mnp
x = ms.Tensor(
np.array(
[
[np.nan, np.inf, -np.inf],
[-4.2111430168151855, -12.858903884887695, 4.690601348876953],
],
dtype=np.float32,
)
)
wrong = mnp.nancumsum(x).asnumpy()
correct = np.array(
[
0.0,
3.4028234663852886e38,
0.0,
-4.2111430168151855,
-17.07004737854004,
-12.379446029663086,
],
dtype=np.float32,
)
print("wrong:", wrong.tolist())
print("correct:", correct.tolist())
Related log / screenshot
Running the script produces:
wrong: [0.0, inf, nan, nan, nan, nan]
correct: [0.0, 3.4028234663852886e+38, 0.0, -4.2111430168151855, -17.07004737854004, -12.379446029663086]
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 mnp.nancumsum.
In this example, NaN is correctly treated as 0.0 at the first position, but the accumulated result becomes NaN after the +Inf and -Inf values are processed. The expected behavior is to keep producing finite accumulated float32 values instead of propagating NaN through the rest of the result.
Environment
Hardware Environment(
Ascend/GPU/CPU):/device cpu
Software Environment:
Describe the current behavior
mindspore.numpy.nancumsumappears to handleNaN/Infvalues incorrectly forfloat32tensors.For the input:
calling:
returns:
After the
+Infand-Infvalues are accumulated together, the result becomesNaN, and the following cumulative values also remainNaN.Describe the expected behavior
mnp.nancumsumshould ignoreNaNvalues and produce the expected accumulatedfloat32result.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
mnp.nancumsum.In this example,
NaNis correctly treated as0.0at the first position, but the accumulated result becomesNaNafter the+Infand-Infvalues are processed. The expected behavior is to keep producing finite accumulatedfloat32values instead of propagatingNaNthrough the rest of the result.