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.signbit appears to handle negative zero incorrectly for float32 tensors.
For an input containing -0.0, calling:
returns False for the -0.0 element.
Actual result:
[[False, False, False],
[True, False, False]]
The first element should be True because -0.0 has the sign bit set.
Describe the expected behavior
ops.signbit should return True for negative zero and negative finite values, and False for positive zero and positive finite values.
Expected result:
[[True, False, False],
[True, False, False]]
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(
[
[-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.signbit(x).asnumpy()
correct = np.array(
[
[True, False, False],
[True, False, False],
],
dtype=bool,
)
print("wrong:", wrong.tolist())
print("correct:", correct.tolist())
Related log / screenshot
Running the script produces:
wrong: [[False, False, False], [True, False, False]]
correct: [[True, False, False], [True, False, False]]
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 signed-zero handling issue in ops.signbit.
For the first element, the input is:
The current result is:
The expected result is:
Other values in this example, such as 0.0, positive subnormal values, -1.0, and positive finite values, appear to be handled as expected.
Environment
Hardware Environment(
Ascend/GPU/CPU):/device cpu
Software Environment:
Describe the current behavior
mindspore.ops.signbitappears to handle negative zero incorrectly forfloat32tensors.For an input containing
-0.0, calling:returns
Falsefor the-0.0element.Actual result:
The first element should be
Truebecause-0.0has the sign bit set.Describe the expected behavior
ops.signbitshould returnTruefor negative zero and negative finite values, andFalsefor positive zero and positive finite values.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 signed-zero handling issue in
ops.signbit.For the first element, the input is:
The current result is:
The expected result is:
Other values in this example, such as
0.0, positive subnormal values,-1.0, and positive finite values, appear to be handled as expected.