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
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,19 +531,26 @@ 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) # transforms v2 to v1's coordinate system (imputes z=0)
v1.like(v2) - v2 # transforms v1 to v2's coordinate system (removes z)
v1 - v2.to_xyz() # transforms v2 to xyz coordinates (imputes z=0)
v1.to_xy() - v2 # transforms v1 to xy coordinates (removes z)
v1 - v2.to_Vector3D(z=3) # transforms v2 to 3D (imputes z=3)
v1.to_Vector2D() - v2 # transforms v1 to 2D (removes z)
```

And finally, in some cases, the function excludes a higher-dimensional component, even if the input vectors had them.
Similarly, for a few vector methods, the dimension of the input vectors are type checked strictly.

It would be confusing if the 3D cross-product returned a fourth component.
For instance, a cross-product is only defined for 3D and 7D vectors; hence, running the method on a 4D vector will error out.

```python
vector.obj(x=0.1, y=0.2, z=0.3, t=10).cross(vector.obj(x=0.4, y=0.5, z=0.6, t=20))
vector.obj(x=0.1, y=0.2, z=0.3).cross(vector.obj(x=0.4, y=0.5, z=0.6))
```

The (current) list of properties and methods is:
Expand Down Expand Up @@ -625,6 +632,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
Loading