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: like method for projecting vector into the coordinate space of another vector + better type errors and hints #426

Merged
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,17 @@ vector.obj(pt=1, phi=1.3, eta=2, mass=5).deltaR(
)
```

The opposite—using low-dimensional vectors in operations defined for higher numbers of dimensions—is sometimes defined. In these cases, a zero longitudinal or temporal component has to be imputed.
For a few operations - `+`, `-`, `==`, `!=`, ... - the dimension of the vectors should be equal. This can be achieved by using the `like` method, `to_{coordinate_name}` methods, `to_Vector*D` methods. The `to_Vector*D` methods provide more flexibility to the users, that is, new coordinate values can be passed into the methods as named arguments.

```python
vector.obj(x=1, y=2, z=3) - vector.obj(x=1, y=2)
vector.obj(x=1, y=2, z=0).is_parallel(vector.obj(x=1, y=2))
v1 = vector.obj(x=1, y=2, z=3)
v2 = vector.obj(x=1, y=2)

v1 - v2.like(v1), v1.like(
v2
) - v2, v1 - v2.to_xyz(), v1.to_xy() - v2, v1 - v2.to_Vector3D(
z=3
), v1.to_Vector2D() - v2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be required for black-compliant formatting, but it makes what would be easy to read into something difficult to read.

Do you need the commas?

Suggested change
v1 - v2.like(v1), v1.like(
v2
) - v2, v1 - v2.to_xyz(), v1.to_xy() - v2, v1 - v2.to_Vector3D(
z=3
), v1.to_Vector2D() - v2
v1 - v2.like(v1)
v1.like(v2) - v2
v1 - v2.to_xyz()
v1.to_xy() - v2
v1 - v2.to_Vector3D(z=3)
v1.to_Vector2D() - v2

Should there be some explanatory text between these?

```

And finally, in some cases, the function excludes a higher-dimensional component, even if the input vectors had them.
Expand Down Expand Up @@ -625,6 +631,7 @@ The (current) list of properties and methods is:
- `isclose(vector, rtol=1e-5, atol=1e-8, equal_nan=False)`: works like [np.isclose](https://numpy.org/doc/stable/reference/generated/numpy.isclose.html); arrays also have an [allclose](https://numpy.org/doc/stable/reference/generated/numpy.allclose.html) method
- `to_Vector*D(coordinates)`: replace `*` with the reuquired vector dimension
- `to_{coordinate-names}`: for example - `to_rhophietatau`
- `like(other)`: projects the vector into the dimensions of `other`, for example - `two_d_vector.like(three_d_vector)`

## Compiling your Python with Numba

Expand Down
394 changes: 195 additions & 199 deletions docs/usage/intro.ipynb

Large diffs are not rendered by default.

Loading