Replies: 1 comment
-
Considering that these are being applied to arrays of vectors, rather than an individual vector, raising exceptions is more problematic than setting NaN. (What if a huge dataset has just one such value, due to accumulated round-off?) That's why NumPy sets NaN—but with warnings (by default). Vector suppresses these warnings because some of them are intermediate to the calculation: vector/src/vector/_compute/lorentz/beta.py Lines 122 to 133 in 0b9bf7e But perhaps there should be a |
Beta Was this translation helpful? Give feedback.
-
I reconstruct a virtual W four-vector from the difference of reconstructed Bsig and D* four-vectors and was surprised that sometimes, the result of the
mass2
method is negative.which prints
Well, the reconstructed vector is obviously unphysical and when I looked at the code I saw that
mass2
is an alias fortau2
and it just returns justE**2 - mag**2
, so this makes sense when the vector is unphysical and thus the magnitude is higher than the energy. I just wrongly assumed it would return the same asmass**2
and at first I thought this breaks the principle of least surprise.I looked at ROOT
GenVector
, which you try to be convention-compatible with, and it seems it does the same forM2()
, so it seems this is not a bug but a feature and for ROOT users it keeps in line with expectations.. ButGenVector
seems to throw an exception when e.g. calculatingBeta()
with a negativeM2()
, whilevector
just quietly returnsNaN
's.Suggestion:
I think it would be nice to throw some exception when trying to boost with a time-like vector or at least print some warnings like numpy does when dividing by zero. And maybe have an optional keyword argument to disable exceptions. Then, the user would need to be more explicit to ignore these cases. Though I'm not sure if that's feasible from a design-perspective, maybe just returning NaN's is enough 🤷
Beta Was this translation helpful? Give feedback.
All reactions