scikit-hep / scikit-hep/vector
Numpy errors are supressed by default
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 99
- Forks
- 42
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 6
Description
Some coordinate systems can not represent some vectors. For example, if adding two vectors in pt,phi,eta,E coordinates that have opposite azimuthal components that add to zero, the resulting longitudinal coordinate eta will be infinity:
import numpy as np
import vector
v1 = vector.obj(pt=1, phi=0, eta=1, E=1)
v2 = vector.obj(pt=1, phi=np.pi, eta=1, E=1)
new_vector = v1 + v2 # this vector can not be represented in the pt,phi,eta,E coordinate system
By default, such errors are suppressed in the library
https://github.com/scikit-hep/vector/blob/69d0b1d04f268540b2e553a927a8b51a7edb7633/src/vector/_compute/lorentz/add.py#L201
Without that line, the default Numpy error would be shown
/usr/lib/python3.10/site-packages/vector/_compute/spatial/eta.py:43: RuntimeWarning: divide by zero encountered in arctanh
return lib.nan_to_num(lib.arctanh(z / lib.sqrt(rho ** 2 + z ** 2)), nan=0.0)
vector.obj(pt=1.2246467991473532e-16, phi=1.5707963267948966, eta=1.7976931348623157e+308, E=2)
I think it would be better if the user is made aware of the error by default (rather than suppressing by default). Additionally, that leaves the choice of suppressing errors or not to the user, by adding numpy.errstate(all="ignore") in their code.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the coordinate-addition example in the issue, then inspect the suppression logic at src/vector/_compute/lorentz/add.py around line 201. Confirm the default behavior and decide how the existing numpy.errstate guidance should apply; done means the default operation exposes the numerical warning without suppressing it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100