locnd182644 opened a new pull request, #18646:
URL: https://github.com/apache/tvm/pull/18646
### Summary
Cast NAN to bool gives true to ensure consistency with the existing
framework (C, C++, Python, Torch, NumPy, OnnxRuntime, ...).
### Steps to Reproduce
- Python:
```
bool(float('nan'))
```
> True
- Torch:
```
torch.tensor(float("nan"), dtype=torch.float32).to(torch.bool)
```
> tensor(True)
- Numpy:
```
import numpy as np
bool(np.nan)
```
> True
- TVM:
```
class Module:
def main(x: R.Tensor((), dtype="float32")) -> R.Tensor((), dtype="bool"):
with R.dataflow():
gv: R.Tensor((), dtype="bool") = R.astype(x, dtype="bool")
R.output(gv)
return gv
x = np.array(float("nan"), dtype="float32")
```
> False
### Expected
- TVM:
```
class Module:
def main(x: R.Tensor((), dtype="float32")) -> R.Tensor((), dtype="bool"):
with R.dataflow():
gv: R.Tensor((), dtype="bool") = R.astype(x, dtype="bool")
R.output(gv)
return gv
x = np.array(float("nan"), dtype="float32")
```
> True
### Resolved
- Replace the instruction `fcmp one` with `fcmp une` in LLVM.
- Citation:
https://releases.llvm.org/20.1.0/docs/LangRef.html#fcmp-instruction
<img width="400" height="200" alt="PR1-18605"
src="https://github.com/user-attachments/assets/cffeebd8-dfe6-436e-9c4c-61e1e84d5439"
/>
- Fixed: #18605
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]