-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: update to_Vector3D
to pass new coordinate values
#278
Conversation
Making changes to test_conversions.py now |
Codecov ReportBase: 82.75% // Head: 82.72% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #278 +/- ##
==========================================
- Coverage 82.75% 82.72% -0.04%
==========================================
Files 96 96
Lines 11354 11366 +12
==========================================
+ Hits 9396 9402 +6
- Misses 1958 1964 +6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
53cd159
to
0b15a2d
Compare
This is how it works right now - In [1]: import vector
In [2]: v = vector.obj(x=1, y=2)
In [3]: v.to_Vector3D(z=1)
Out[3]: VectorObject3D(x=1, y=2, z=1)
In [4]: v = vector.obj(px=1, y=2)
In [5]: v.to_Vector3D(z=1)
Out[5]: vector.MomentumObject3D(px=1, py=2, pz=1) Should we also have the option to enter the momentum counterparts of coordinates? Or should we leave it as it is? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a good thing to add, except that if it's on Vector2D.to_Vector3D
, users will expect it to be on 2D → 4D and 3D → 4D as well. @Saransh-cpp, how much effort do you think it would be to add them?
Also, a new feature like this should have tests. Like, one example for each of z
, theta
, and eta
.
src/vector/_methods.py
Outdated
@@ -2969,16 +2969,16 @@ def to_Vector3D( | |||
if sum(x is not None for x in (z, theta, eta)) > 1: | |||
raise TypeError("Only one non-None parameter allowed") | |||
|
|||
z = 0 | |||
coord_value = 0.0 | |||
l_type = LongitudinalZ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can set this to something like l_type: type[Longitudinal] = LongitudinalZ
or something like that, IIRC, to avoid the type ignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did try this (in fact, IIRC, this was added by you in one of the commits above, and I removed it to make the CI pass), but mypy
still required the type ignore statements :(
Oh wait, that worked, maybe I was trying something else previously.
I was thinking that as well. Though maybe asking people to do 2D -> 3D -> 4D would be easier than adding it to the 2D -> 4D one. But 3D -> 4D does clearly make sense. |
2D → 4D could be implemented in terms of 2D → 3D → 4D. Also, does this only apply to the single-object backend ( Also, the distinction between |
Thanks for the review, @jpivarski and @henryiii! Could you also please take a look at #317 and let me know if this should go in
Should be simple to add. I can maybe merge this PR and add the tests + make it available for 2D → 4D (2D → 3D → 4D) and 3D → 4D in another PR.
Generalizes to all the backends! In [1]: import vector
In [2]: v = vector.array(
...: [(1.1, 2.1), (1.2, 2.2), (1.3, 2.3), (1.4, 2.4), (1.5, 2.5)],
...: dtype=[("x", float), ("y", float)],
...: )
In [3]: v.to_Vector3D(z=1)
Out[3]:
VectorNumpy3D([(1.1, 2.1, 1.), (1.2, 2.2, 1.), (1.3, 2.3, 1.), (1.4, 2.4, 1.),
(1.5, 2.5, 1.)], dtype=[('x', '<f8'), ('y', '<f8'), ('z', '<f8')])
In [4]: v = vector.Array(
...: [
...: [{"x": 1, "y": 1.1}, {"x": 2, "y": 2.2}],
...: [],
...: [{"x": 3, "y": 3.3}]
...: ]
...: )
In [5]: v.to_Vector3D(z=1)
Out[5]: <VectorArray3D [[{x: 1, y: 1.1, z: 1, ... z: 1}]] type='3 * var * Vector3D["x": ...'> |
I think this would be nice for a v1. Merge then add things is fine. How much work is it to keep Awkward v1? If not much, then I'd say we don't need to rush to drop it, it will make adoption of Vector v1 easier. But fine to drop if it is. |
Thanks! Will merge this, create a new PR, and set up stuff for v1! |
Thanks for taking this up, @Naman-Priyadarshi! |
to_Vector3D
to pass new coordinate valuesto_Vector3D
to pass new coordinate values
Description
Kindly take a look at CONTRIBUTING.md.
Please describe the purpose of this pull request. Reference and link to any relevant issues or pull requests.
Checklist
$ pre-commit run --all-files
or$ nox -s lint
)$ pytest
or$ nox -s tests
)$ cd docs; make clean; make html
or$ nox -s docs
)$ xdoctest ./src/vector
or$ nox -s doctests
)Before Merging