Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 4 tasks
34j opened this issue Nov 27, 2024 · 0 comments
Open
1 of 4 tasks
Assignees
Labels
Bug Report Report bugs detected in Ivy.

Comments

@34j
Copy link

34j commented Nov 27, 2024

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.)

  • There are very limited situations where such behavior is needed.
  • It does not match the behavior of other functions in numpy; np.sin(1) returns 0.8414709848078965 instead of 0.
  • This behavior can be easily achieved by ivy.astype(ivy.lgamma(x), dtype=x.dtype)
  • Package maintainers using ivy need to worry about the type of input, and casts need to be made.

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

  • NumPy
  • TensorFlow
  • PyTorch
  • JAX

Device

CPU

@34j 34j added the Bug Report Report bugs detected in Ivy. label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report Report bugs detected in Ivy.
Projects
None yet
Development

No branches or pull requests

2 participants