-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished the (public) reference documentation
- Loading branch information
Showing
10 changed files
with
296 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Making Awkward Arrays of vectors | ||
|
||
An Awkward Array of vectors is an Awkward Array containing appropriately named records, appropriately named fields, and the Vector behaviors registered in the array. Here's a complete example for illustration: | ||
|
||
```python | ||
>>> import awkward as ak | ||
>>> import vector | ||
>>> vector.register_awkward() | ||
>>> | ||
>>> vec = ak.Array([ | ||
... [{"x": 1.1, "y": 2.2}, {"x": 3.3, "y": 4.4}], | ||
... [], | ||
... [{"x": 5.5, "y": 6.6}], | ||
... ], with_name="Vector2D") | ||
>>> | ||
>>> abs(vec) | ||
<Array [[2.46, 5.5], [], [8.59]] type='3 * var * float64'> | ||
``` | ||
|
||
In the above, | ||
|
||
1. `vector.register_awkward()` loads Vector's `vector.backends.awkward.behavior` dict of functionality into the global `ak.behavior` | ||
2. the Awkward Array contains records (inside variable-length lists) with field names `"x"` and `"y"` | ||
3. those records are labeled with type name `"Vector2D"` | ||
|
||
and thus the `abs` function computes the magnitude of each record as `sqrt(x**2 + y**2)`, through the variable-length lists. | ||
|
||
It is not necessary to install Vector's behaviors globally. They could be installed in the `vec` array only by passing `behavior=vector.backends.awkward.behavior` to the [ak.Array](https://awkward-array.org/doc/main/reference/generated/ak.Array.html) constructor. | ||
|
||
The records can contain more fields than those that specify coordinates, which can be useful for specifying properties of a particle other than its momentum. Only the coordinate names are considered when performing vector calculations. Coordinates must be numbers (not, for instance, lists of numbers). Be careful about field names that coincide with coordinates, such as `rho` (azimuthal magnitude) and `tau` (proper time). | ||
|
||
The `vector.Array` function (`vector.awk` is a synonym) is an alternative to the [ak.Array](https://awkward-array.org/doc/main/reference/generated/ak.Array.html) constructor, which installs Vector's behavior in the new array (not globally in `ak.behavior`). | ||
|
||
The `vector.zip` function is an alternative to the [ak.zip](https://awkward-array.org/doc/main/reference/generated/ak.zip.html) function, which installs Vector's behavior in the new array (not globally in `ak.behavior`). | ||
|
||
Awkward Arrays can be used in [Numba-compiled functions](https://numba.pydata.org/), including those that contain vectors. | ||
|
||
```{eval-rst} | ||
.. autofunction:: vector.register_awkward | ||
``` | ||
|
||
```{eval-rst} | ||
.. autofunction:: vector.Array | ||
``` | ||
|
||
```{eval-rst} | ||
.. autofunction:: vector.zip | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Making NumPy arrays of vectors | ||
|
||
A NumPy array of vectors is a subclass of [np.ndarray](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html) with vector properties and methods. The [dtype](https://numpy.org/doc/stable/reference/arrays.dtypes.html) of this array is [structured](https://numpy.org/doc/stable/user/basics.rec.html) to specify the coordinate names; an array with fields `x` and `y` (Cartesian) performs computations differently from an array with fields `rho` and `phi` (polar). | ||
|
||
To create a NumPy array of vectors, | ||
|
||
1. use the `vector.array` function (`vector.arr` is a synonym) | ||
2. use the `vector.VectorNumpy` class constructor | ||
3. or cast a structured NumPy array as the appropriate class. | ||
|
||
## General constructor | ||
|
||
```{eval-rst} | ||
.. autofunction:: vector.array | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.VectorNumpy | ||
``` | ||
|
||
## Casting structured arrays | ||
|
||
[NumPy structured arrays](https://numpy.org/doc/stable/user/basics.rec.html) with appropriately named fields (see above) can be _cast_ as arrays of vectors using [np.ndarray.view](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.view.html). Use the NumPy array subclass with the appropriate dimension below. | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.VectorNumpy2D | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.MomentumNumpy2D | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.VectorNumpy3D | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.MomentumNumpy3D | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.VectorNumpy4D | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.MomentumNumpy4D | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Making vector objects | ||
|
||
A vector object represents a single vector, rather than an array of vectors. Lists of vector objects are slower to compute and have more memory overhead than arrays of vectors, _unless_ those computations are performed in [Numba-compiled functions](https://numba.pydata.org/). | ||
|
||
To create a vector object, use the `vector.obj` function with appropriate arguments for 2D/3D/4D and geometric versus momentum. | ||
|
||
## General constructor | ||
|
||
```{eval-rst} | ||
.. autofunction:: vector.obj | ||
``` | ||
|
||
## 2D constructors | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.VectorObject2D | ||
:members: from_rhophi,from_xy | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.MomentumObject2D | ||
:members: from_rhophi,from_xy | ||
``` | ||
|
||
## 3D constructors | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.VectorObject3D | ||
:members: from_rhophieta,from_rhophitheta,from_rhophiz,from_xyeta,from_xytheta,from_xyz | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.MomentumObject3D | ||
:members: from_rhophieta,from_rhophitheta,from_rhophiz,from_xyeta,from_xytheta,from_xyz | ||
``` | ||
|
||
## 4D constructors | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.VectorObject4D | ||
:members: from_rhophietat,from_rhophietatau,from_rhophithetat,from_rhophithetatau,from_rhophizt,from_rhophiztau,from_xyetat,from_xyetatau,from_xythetat,from_xythetatau,from_xyzt,from_xyztau | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.MomentumObject4D | ||
:members: from_rhophietat,from_rhophietatau,from_rhophithetat,from_rhophithetatau,from_rhophizt,from_rhophiztau,from_xyetat,from_xyetatau,from_xythetat,from_xythetatau,from_xyzt,from_xyztau | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Making SymPy vector expressions | ||
|
||
SymPy expressions are not numerical, they're purely algebraic. However, the same Vector computations can be performed on them. | ||
|
||
To construct a symbolic vector, first create symbols for its components and ensure that they are real-valued (not complex), | ||
|
||
```python | ||
>>> import sympy | ||
>>> x, y, z, t, px, py, pz, eta, tau = sympy.symbols( | ||
... "x y z t px py pz eta tau", real=True | ||
... ) | ||
``` | ||
|
||
then use one of Vector's SymPy constructors (geometric or momentum), | ||
|
||
```python | ||
>>> vector.VectorSympy2D(x=x, y=y) | ||
VectorSympy2D(x=x, y=y) | ||
>>> | ||
>>> vector.MomentumSympy3D(px=px, py=py, pz=pz) | ||
MomentumSympy3D(px=px, py=py, pz=pz) | ||
>>> | ||
>>> vector.VectorSympy4D(x=x, y=y, eta=eta, tau=tau) | ||
vector.VectorSympy4D(x=x, y=y, eta=eta, tau=tau) | ||
``` | ||
|
||
which are documented below. | ||
|
||
## 2D constructors | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.VectorSympy2D | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.MomentumSympy2D | ||
``` | ||
|
||
## 3D constructors | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.VectorSympy3D | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.MomentumSympy3D | ||
``` | ||
|
||
## 4D constructors | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.VectorSympy4D | ||
``` | ||
|
||
```{eval-rst} | ||
.. autoclass:: vector.MomentumSympy4D | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.