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

feat: update to_Vector3D to pass new coordinate values #278

Merged
merged 9 commits into from
Feb 22, 2023

Conversation

Naman-Priyadarshi
Copy link
Contributor

@Naman-Priyadarshi Naman-Priyadarshi commented Oct 19, 2022

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

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't any other open Pull Request for the required change ?
  • Does your submission pass pre-commit? ($ pre-commit run --all-files or $ nox -s lint)
  • Does your submission pass tests? ($ pytest or $ nox -s tests)
  • Does the documentation build with your changes? ($ cd docs; make clean; make html or $ nox -s docs)
  • Does your submission pass doctests? ($ xdoctest ./src/vector or $ nox -s doctests)

Before Merging

  • Summarize commit messages into a brief review of the Pull request.

@Naman-Priyadarshi
Copy link
Contributor Author

Making changes to test_conversions.py now

@codecov-commenter
Copy link

codecov-commenter commented Feb 17, 2023

Codecov Report

Base: 82.75% // Head: 82.72% // Decreases project coverage by -0.04% ⚠️

Coverage data is based on head (cf850b1) compared to base (8f25cbc).
Patch coverage: 53.84% of modified lines in pull request are covered.

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     
Impacted Files Coverage Δ
src/vector/_methods.py 74.15% <53.84%> (-0.17%) ⬇️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Saransh-cpp Saransh-cpp added the feature New feature or request label Feb 17, 2023
@Saransh-cpp
Copy link
Member

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?

@Saransh-cpp Saransh-cpp marked this pull request as ready for review February 20, 2023 20:14
Copy link
Member

@jpivarski jpivarski left a 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.

@@ -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
Copy link
Member

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.

Copy link
Member

@Saransh-cpp Saransh-cpp Feb 22, 2023

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.

@henryiii
Copy link
Member

users will expect it to be on 2D → 4D and 3D → 4D as well

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.

@jpivarski
Copy link
Member

2D → 4D could be implemented in terms of 2D → 3D → 4D.

Also, does this only apply to the single-object backend (vector.obj), or does it generalize to all backends? Setting coord_value to a scalar 0 might work on array-based backends if it gets broadcasted.

Also, the distinction between 0 and 0.0 is relevant: coordinates are allowed to be any numeric type, including integers (though that's less often desired).

@Saransh-cpp
Copy link
Member

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 v1.0.0?


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.

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.

Also, does this only apply to the single-object backend (vector.obj), or does it generalize to all backends? Setting coord_value to a scalar 0 might work on array-based backends if it gets broadcasted.

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": ...'>

@henryiii
Copy link
Member

henryiii commented Feb 22, 2023

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.

@Saransh-cpp
Copy link
Member

Thanks! Will merge this, create a new PR, and set up stuff for v1!

@Saransh-cpp Saransh-cpp added this to the v1.0.0 milestone Feb 22, 2023
@Saransh-cpp
Copy link
Member

Thanks for taking this up, @Naman-Priyadarshi!

@Saransh-cpp Saransh-cpp changed the title Update to_Vector3D to pass new coordinate values feat: update to_Vector3D to pass new coordinate values Feb 22, 2023
@Saransh-cpp Saransh-cpp merged commit a616cdc into scikit-hep:main Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow users to pass new coordinate values in to_Vector{X}D and to_{new coordinate names}
5 participants