ivy-llc / ivy

Convert Machine Learning Code Between Frameworks
https://ivy.dev
Other
14.02k stars 5.74k forks source link

[Bug]: `ivy.vector_norm` and `ivy.lgamma` when backend=numpy return rounded values #28844

Open 34j opened 3 days ago

34j commented 3 days ago

Bug Explanation

> python -c "import ivy; ivy.set_backend('numpy'); print(ivy.lgamma(5)); print(ivy.lgamma(5.))"
ivy.array(3)
ivy.array(3.1780539)
> python -c "import ivy; ivy.set_backend('numpy'); print(ivy.vector_norm([1, 1])); print(ivy.vector_norm([1., 1.]))"
ivy.array(1)
ivy.array(1.4142135)

https://data-apis.org/array-api/latest/extensions/generated/array_api.linalg.vector_norm.html

According to array-api, there is no specified behavior when a non-floating point type is given for vector_norm, but I would like to suggest, with all due respect, to stop this casting or to output an error, for the following reasons. (For lgamma, not even defined in array-api.)

Thanks for this great project anyway.

Steps to Reproduce Bug

python -c "import ivy; ivy.set_backend('numpy'); print(ivy.lgamma(5)); print(ivy.lgamma(5.))"
python -c "import ivy; ivy.set_backend('numpy'); print(ivy.vector_norm([1, 1])); print(ivy.vector_norm([1., 1.]))"

Environment

NixOS 24.05, Python 3.11

Ivy Version

1.0.0.1

Backend

Device

CPU

34j commented 2 days ago

(Temporary workaround would be to add + 0. to the argument)