coordinax.distances

Contents

coordinax.distances#

coordinax.distances module.

class coordinax.distances.AbstractDistance#

Bases: AbstractQuantity

Distance quantities.

property distance: AbstractDistance#

The distance.

Examples

>>> import coordinax.distances as cxd
>>> d = cxd.Distance(10, "km")
>>> d.distance is d
True
>>> import coordinax.astro as cxastro
>>> cxastro.DistanceModulus(10, "mag").distance
Distance(1000., 'pc')
>>> p = cxastro.Parallax(1, "mas")
>>> p.distance.to("kpc")
Distance(1., 'kpc')
property T: AbstractQuantity#

Transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([[0, 1], [1, 2]], "m")
>>> q.T
Quantity(Array([[0, 1],
                          [1, 2]], dtype=int32), unit='m')
argmax(*args: Any, **kwargs: Any)#

Return the indices of the maximum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.argmax()
Array(2, dtype=int32)
Parameters:
Return type:

Array

argmin(*args: Any, **kwargs: Any)#

Return the indices of the minimum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.argmin()
Array(0, dtype=int32)
Parameters:
Return type:

Array

astype(*args: Any, **kwargs: Any)#

Copy the array and cast to a specified dtype.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.dtype
dtype('int32')
>>> q.astype(float)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property at: _QuantityIndexUpdateHelper#

Helper property for index update functionality.

The at property provides a functionally pure equivalent of in-place array modifications.

In particular:

Alternate syntax

Equivalent In-place expression

x = x.at[idx].set(y)

x[idx] = y

x = x.at[idx].add(y)

x[idx] += y

x = x.at[idx].subtract(y)

x[idx] -= y

x = x.at[idx].multiply(y)

x[idx] *= y

x = x.at[idx].divide(y)

x[idx] /= y

x = x.at[idx].power(y)

x[idx] **= y

x = x.at[idx].min(y)

x[idx] = minimum(x[idx], y)

x = x.at[idx].max(y)

x[idx] = maximum(x[idx], y)

x = x.at[idx].apply(ufunc)

ufunc.at(x, idx)

x = x.at[idx].get()

x = x[idx]

None of the x.at expressions modify the original x; instead they return a modified copy of x. However, inside a jit() compiled function, expressions like x = x.at[idx].set(y) are guaranteed to be applied in-place.

Unlike NumPy in-place operations such as x[idx] += y, if multiple indices refer to the same location, all updates will be applied (NumPy would only apply the last update, rather than applying all updates.) The order in which conflicting updates are applied is implementation-defined and may be nondeterministic (e.g., due to concurrency on some hardware platforms).

By default, JAX assumes that all indices are in-bounds. Alternative out-of-bound index semantics can be specified via the mode parameter (see below).

Parameters:
  • mode

    string specifying out-of-bound indexing mode. Options are:

    • "promise_in_bounds": (default) The user promises that indices are in bounds. No additional checking will be performed. In practice, this means that out-of-bounds indices in get() will be clipped, and out-of-bounds indices in set(), add(), etc. will be dropped.

    • "clip": clamp out of bounds indices into valid range.

    • "drop": ignore out-of-bound indices.

    • "fill": alias for "drop". For get(), the optional fill_value argument specifies the value that will be returned.

    See jax.lax.GatherScatterMode for more details.

  • wrap_negative_indices – If True (default) then negative indices indicate position from the end of the array, similar to Python and NumPy indexing. If False, then negative indices are considered out-of-bounds and behave according to the mode parameter.

  • fill_value – Only applies to the get() method: the fill value to return for out-of-bounds slices when mode is 'fill'. Ignored otherwise. Defaults to NaN for inexact types, the largest negative value for signed types, the largest positive value for unsigned types, and True for booleans.

  • indices_are_sorted – If True, the implementation will assume that the (normalized) indices passed to at[] are sorted in ascending order, which can lead to more efficient execution on some backends. If True but the indices are not actually sorted, the output is undefined.

  • unique_indices – If True, the implementation will assume that the (normalized) indices passed to at[] are unique, which can result in more efficient execution on some backends. If True but the indices are not actually unique, the output is undefined.

Examples

>>> x = jnp.arange(5.0)
>>> x
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[2].get()
Array(2., dtype=float32)
>>> x.at[2].add(10)
Array([ 0.,  1., 12.,  3.,  4.], dtype=float32)

By default, out-of-bound indices are ignored in updates, but this behavior can be controlled with the mode parameter:

>>> x.at[10].add(10)  # dropped
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[20].add(10, mode='clip')  # clipped
Array([ 0.,  1.,  2.,  3., 14.], dtype=float32)

For get(), out-of-bound indices are clipped by default:

>>> x.at[20].get()  # out-of-bounds indices clipped
Array(4., dtype=float32)
>>> x.at[20].get(mode='fill')  # out-of-bounds indices filled with NaN
Array(nan, dtype=float32)
>>> x.at[20].get(mode='fill', fill_value=-1)  # custom fill value
Array(-1., dtype=float32)

Negative indices count from the end of the array, but this behavior can be disabled by setting wrap_negative_indices = False:

>>> x.at[-1].set(99)
Array([ 0.,  1.,  2.,  3., 99.], dtype=float32)
>>> x.at[-1].set(99, wrap_negative_indices=False, mode='drop')  # dropped!
Array([0., 1., 2., 3., 4.], dtype=float32)
block_until_ready()#

Block until the array is ready.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.block_until_ready() is q
True
decompose(bases: Sequence[Unit | UnitBase | CompositeUnit | str], /)#

Decompose the quantity into the given bases.

Examples

>>> from unxt import Quantity
>>> q = Quantity(1, "m")
>>> q.decompose(["cm", "s"])
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

bases (Sequence[Unit | UnitBase | CompositeUnit | str])

Return type:

AbstractQuantity

property device: Device#

Device where the array is located.

Examples

>>> import unxt as u
>>> u.Quantity(1, "m").device
CpuDevice(id=0)
devices()#

Return the devices where the array is located.

Return type:

set[Device]

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.devices()
{CpuDevice(id=0)}
property dtype: dtype#

Data type of the array.

Examples

>>> import unxt as u
>>> u.Quantity(1, "m").dtype
dtype('int32')
flatten()#

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Quantity([[1, 2], [3, 4]], "m")
>>> q.flatten()
Quantity(Array([1, 2, 3, 4], dtype=int32), unit='m')
classmethod from_(cls: type[AbstractQuantity], *args: Any, **kwargs: Any)#
from_(cls: type[AbstractQuantity], value: ArrayLike | list[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex] | tuple[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex, ...], unit: Any, /, *, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a unxt.Quantity from an array-like value and a unit.

Parameters:
  • value – The array-like value.

  • unit – The unit of the value.

  • dtype – The data type of the array (keyword-only).

  • args (Any)

  • kwargs (Any)

Return type:

AbstractQuantity

Examples

For this example we’ll use the Quantity class. The same applies to any subclass of AbstractQuantity.

>>> import jax.numpy as jnp
>>> import unxt as u
>>> x = jnp.array([1.0, 2, 3])
>>> u.Quantity.from_(x, "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_([1.0, 2, 3], "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_((1.0, 2, 3), "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], value: ArrayLike | list[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex] | tuple[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex, ...], /, *, unit: Any, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Make a unxt.AbstractQuantity from an array-like value and a unit kwarg.

Examples

For this example we’ll use the unxt.Quantity class. The same applies to any subclass of unxt.AbstractQuantity.

>>> import unxt as u
>>> u.Quantity.from_([1.0, 2, 3], unit="m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], *, value: Any, unit: Any, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a AbstractQuantity from value and unit kwargs.

Examples

For this example we’ll use the Quantity class. The same applies to any subclass of AbstractQuantity.

>>> import unxt as u
>>> u.Quantity.from_(value=[1.0, 2, 3], unit="m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], mapping: Mapping[str, Any]) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from a Mapping.

Examples

For this example we’ll use the Quantity class. The same applies to any subclass of AbstractQuantity.

>>> import jax.numpy as jnp
>>> import unxt as u
>>> x = jnp.array([1.0, 2, 3])
>>> q = u.Quantity.from_({"value": x, "unit": "m"})
>>> q
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_({"value": q, "unit": "km"})
Quantity(Array([0.001, 0.002, 0.003], dtype=float32), unit='km')
from_(cls: type[AbstractQuantity], value: AbstractQuantity, unit: Any, /, *, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> u.Quantity.from_(q, "cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
from_(cls: type[AbstractQuantity], value: AbstractQuantity, unit: NoneType, /, *, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> u.Quantity.from_(q, None)
Quantity(Array(1, dtype=int32, ...), unit='m')
from_(cls: type[AbstractQuantity], value: AbstractQuantity, /, *, unit: Any | None = None, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity, with no unit change.

from_(cls: type[AbstractQuantity], value: Quantity, /, **kwargs: Any) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Quantity.from_(apyu.Quantity(1, "m"))
Quantity(Array(1., dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], value: Quantity, u: Any, /, **kwargs: Any) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Quantity.from_(apyu.Quantity(1, "m"), "cm")
Quantity(Array(100., dtype=float32), unit='cm')
from_(cls: type[Distance], value: ArrayLike, unit: Any, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> cxd.Distance.from_(1, "kpc")
Distance(1, 'kpc')
from_(cls: type[Distance], d: Distance, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> d = cxd.Distance(1, "kpc")
>>> cxd.Distance.from_(d) is d
True
>>> cxd.Distance.from_(d, dtype=float)
Distance(1., 'kpc')
from_(cls: type[Distance], d: Quantity[PhysicalType('length')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(1, "kpc")
>>> cxd.Distance.from_(q, dtype=float)
Distance(1., 'kpc')
from_(cls: type[Distance], p: Quantity[PhysicalType('angle')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from parallax.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(1, "mas")
>>> cxd.Distance.from_(q).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[Distance], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance modulus.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(10, "mag")
>>> cxd.Distance.from_(q).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[DistanceModulus], value: ArrayLike, unit: Any, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> DistanceModulus.from_(1, "mag")
DistanceModulus(1, 'mag')
from_(cls: type[DistanceModulus], dm: DistanceModulus, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance modulus.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> dm = DistanceModulus(1, "mag")
>>> DistanceModulus.from_(dm) is dm
True
>>> DistanceModulus.from_(dm, dtype=float)
DistanceModulus(1., 'mag')
from_(cls: type[DistanceModulus], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "mag")
>>> DistanceModulus.from_(q)
DistanceModulus(1, 'mag')
from_(cls: type[DistanceModulus], d: Distance, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import DistanceModulus
>>> d = cxd.Distance(1, "pc")
>>> DistanceModulus.from_(d)
DistanceModulus(-5., 'mag')
from_(cls: type[DistanceModulus], d: Quantity[PhysicalType('length')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "pc")
>>> DistanceModulus.from_(q)
DistanceModulus(-5., 'mag')
from_(cls: type[DistanceModulus], p: Quantity[PhysicalType('angle')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "mas")
>>> DistanceModulus.from_(q)
DistanceModulus(10., 'mag')
from_(cls: type[Distance], dm: DistanceModulus, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance modulus.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import DistanceModulus
>>> dm = DistanceModulus(10, "mag")
>>> cxd.Distance.from_(dm).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[Parallax], value: ArrayLike, unit: Any, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> Parallax.from_(1, "mas")
Parallax(1, 'mas')
from_(cls: type[Parallax], p: Parallax, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> p = Parallax(1, "mas")
>>> Parallax.from_(p) is p
True
>>> Parallax.from_(p, dtype=float)
Parallax(1., 'mas')
from_(cls: type[Parallax], p: Quantity[PhysicalType('angle')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> q = u.Q(1, "mas")
>>> Parallax.from_(q, dtype=float)
Parallax(1., 'mas')
from_(cls: type[Parallax], d: Distance | Quantity[PhysicalType('length')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from distance.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> d = cxd.Distance(10, "pc")
>>> Parallax.from_(d).uconvert("mas").round(2)
Parallax(100., 'mas')
>>> q = u.Q(10, "pc")
>>> Parallax.from_(q).uconvert("mas").round(2)
Parallax(100., 'mas')
from_(cls: type[Parallax], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Convert distance modulus to parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> dm = u.Q(10, "mag")
>>> Parallax.from_(dm).uconvert("mas").round(2)
Parallax(1., 'mas')
from_(cls: type[Distance], p: Parallax, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from parallax.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import Parallax
>>> p = Parallax(1, "mas")
>>> cxd.Distance.from_(p).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[DistanceModulus], p: Parallax, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from parallax.

>>> from coordinax.astro import DistanceModulus, Parallax
>>> p = Parallax(1, "mas")
>>> DistanceModulus.from_(p)
DistanceModulus(10., 'mag')
from_(cls: type[Parallax], dm: DistanceModulus, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Convert distance modulus to parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus, Parallax
>>> dm = DistanceModulus(10, "mag")
>>> Parallax.from_(dm).uconvert("mas").round(2)
Parallax(1., 'mas')
Parameters:
Return type:

AbstractQuantity

property mT: AbstractQuantity#

Matrix transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([[0, 1], [1, 2]], "m")
>>> q.mT
Quantity(Array([[0, 1],
                          [1, 2]], dtype=int32), unit='m')
max(*args: Any, **kwargs: Any)#

Return the maximum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.max()
Quantity(Array(3, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

mean(*args: Any, **kwargs: Any)#

Return the mean value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.mean()
Quantity(Array(2., dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

min(*args: Any, **kwargs: Any)#

Return the minimum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.min()
Quantity(Array(1, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

property ndim: int#

Number of dimensions.

Examples

>>> import unxt as u
>>> q = u.Quantity([[1]], "m")
>>> q.ndim
2
ravel()#

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Quantity([[1, 2], [3, 4]], "m")
>>> q.ravel()
Quantity(Array([1, 2, 3, 4], dtype=int32), unit='m')
reshape(*args: Any, order: str = 'C')#

Return a reshaped version of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3, 4], "m")
>>> q.reshape(2, 2)
Quantity(Array([[1, 2],
                          [3, 4]], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

round(*args: Any, **kwargs: Any)#

Round the array to the given number of decimals.

Examples

>>> import unxt as u
>>> q = u.Quantity([1.1, 2.2, 3.3], "m")
>>> q.round(0)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property shape: tuple[int, ...]#

Shape of the array.

property sharding: Any#

Return the sharding configuration of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.sharding
SingleDeviceSharding(device=..., memory_kind=...)
property size: int#

Total number of elements.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.size
3
squeeze(*args: Any, **kwargs: Any)#

Return the array with all single-dimensional entries removed.

Examples

>>> import unxt as u
>>> q = u.Quantity([[[1], [2], [3]]], "m")
>>> q.squeeze()
Quantity(Array([1, 2, 3], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

to(u: Any, /)#

Convert the quantity to the given units.

See unxt.quantity.AbstractQuantity.uconvert.

Examples

>>> from unxt import Quantity
>>> q = Quantity(1, "m")
>>> q.to("cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

u (Any)

Return type:

AbstractQuantity

to_device(device: None | Device = None)#

Move the array to a new device.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.to_device(None)
Quantity(Array(1, dtype=int32, weak_type=True), unit='m')
Parameters:

device (None | Device)

Return type:

AbstractQuantity

to_value(u: Any, /)#

Return the value in the given units.

See unxt.AbstractQuantity.ustrip.

Examples

>>> from unxt import Quantity
>>> q = Quantity(1, "m")
>>> q.to_value("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Union[Array, ndarray, bool, number, bool, int, float, complex]

uconvert(u: Any, /)#

Convert the quantity to the given units.

See also

None

convert a quantity to a new unit.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.uconvert("cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

u (Any)

Return type:

AbstractQuantity

ustrip(u: Any, /)#

Return the value in the given units.

See also

None

strip the units from a quantity.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.ustrip("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Array

value: AbstractVar[Shaped[Array, '*shape'] | Shaped[StaticValue, '*shape']]#

The value of the AbstractQuantity.

unit: AbstractVar[Unit | UnitBase | CompositeUnit]#

The unit associated with this value.

final class coordinax.distances.Distance(value: Any, unit: Any, *, check_negative: bool = True)#

Bases: AbstractDistance

Distance quantities.

The distance is a quantity with dimensions of length.

Examples

>>> import coordinax.distances as cxd
>>> cxd.Distance(10, "km")
Distance(10, 'km')

The units are checked to have length dimensions.

>>> try: cxd.Distance(10, "s")
... except ValueError as e: print(e)
Distance must have dimensions length.
Parameters:
value: Shaped[Array, '*shape']#

The distance value.

unit: Unit | UnitBase | CompositeUnit#

The unit associated with this value.

property T: AbstractQuantity#

Transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([[0, 1], [1, 2]], "m")
>>> q.T
Quantity(Array([[0, 1],
                          [1, 2]], dtype=int32), unit='m')
argmax(*args: Any, **kwargs: Any)#

Return the indices of the maximum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.argmax()
Array(2, dtype=int32)
Parameters:
Return type:

Array

argmin(*args: Any, **kwargs: Any)#

Return the indices of the minimum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.argmin()
Array(0, dtype=int32)
Parameters:
Return type:

Array

astype(*args: Any, **kwargs: Any)#

Copy the array and cast to a specified dtype.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.dtype
dtype('int32')
>>> q.astype(float)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property at: _QuantityIndexUpdateHelper#

Helper property for index update functionality.

The at property provides a functionally pure equivalent of in-place array modifications.

In particular:

Alternate syntax

Equivalent In-place expression

x = x.at[idx].set(y)

x[idx] = y

x = x.at[idx].add(y)

x[idx] += y

x = x.at[idx].subtract(y)

x[idx] -= y

x = x.at[idx].multiply(y)

x[idx] *= y

x = x.at[idx].divide(y)

x[idx] /= y

x = x.at[idx].power(y)

x[idx] **= y

x = x.at[idx].min(y)

x[idx] = minimum(x[idx], y)

x = x.at[idx].max(y)

x[idx] = maximum(x[idx], y)

x = x.at[idx].apply(ufunc)

ufunc.at(x, idx)

x = x.at[idx].get()

x = x[idx]

None of the x.at expressions modify the original x; instead they return a modified copy of x. However, inside a jit() compiled function, expressions like x = x.at[idx].set(y) are guaranteed to be applied in-place.

Unlike NumPy in-place operations such as x[idx] += y, if multiple indices refer to the same location, all updates will be applied (NumPy would only apply the last update, rather than applying all updates.) The order in which conflicting updates are applied is implementation-defined and may be nondeterministic (e.g., due to concurrency on some hardware platforms).

By default, JAX assumes that all indices are in-bounds. Alternative out-of-bound index semantics can be specified via the mode parameter (see below).

Parameters:
  • mode

    string specifying out-of-bound indexing mode. Options are:

    • "promise_in_bounds": (default) The user promises that indices are in bounds. No additional checking will be performed. In practice, this means that out-of-bounds indices in get() will be clipped, and out-of-bounds indices in set(), add(), etc. will be dropped.

    • "clip": clamp out of bounds indices into valid range.

    • "drop": ignore out-of-bound indices.

    • "fill": alias for "drop". For get(), the optional fill_value argument specifies the value that will be returned.

    See jax.lax.GatherScatterMode for more details.

  • wrap_negative_indices – If True (default) then negative indices indicate position from the end of the array, similar to Python and NumPy indexing. If False, then negative indices are considered out-of-bounds and behave according to the mode parameter.

  • fill_value – Only applies to the get() method: the fill value to return for out-of-bounds slices when mode is 'fill'. Ignored otherwise. Defaults to NaN for inexact types, the largest negative value for signed types, the largest positive value for unsigned types, and True for booleans.

  • indices_are_sorted – If True, the implementation will assume that the (normalized) indices passed to at[] are sorted in ascending order, which can lead to more efficient execution on some backends. If True but the indices are not actually sorted, the output is undefined.

  • unique_indices – If True, the implementation will assume that the (normalized) indices passed to at[] are unique, which can result in more efficient execution on some backends. If True but the indices are not actually unique, the output is undefined.

Examples

>>> x = jnp.arange(5.0)
>>> x
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[2].get()
Array(2., dtype=float32)
>>> x.at[2].add(10)
Array([ 0.,  1., 12.,  3.,  4.], dtype=float32)

By default, out-of-bound indices are ignored in updates, but this behavior can be controlled with the mode parameter:

>>> x.at[10].add(10)  # dropped
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[20].add(10, mode='clip')  # clipped
Array([ 0.,  1.,  2.,  3., 14.], dtype=float32)

For get(), out-of-bound indices are clipped by default:

>>> x.at[20].get()  # out-of-bounds indices clipped
Array(4., dtype=float32)
>>> x.at[20].get(mode='fill')  # out-of-bounds indices filled with NaN
Array(nan, dtype=float32)
>>> x.at[20].get(mode='fill', fill_value=-1)  # custom fill value
Array(-1., dtype=float32)

Negative indices count from the end of the array, but this behavior can be disabled by setting wrap_negative_indices = False:

>>> x.at[-1].set(99)
Array([ 0.,  1.,  2.,  3., 99.], dtype=float32)
>>> x.at[-1].set(99, wrap_negative_indices=False, mode='drop')  # dropped!
Array([0., 1., 2., 3., 4.], dtype=float32)
block_until_ready()#

Block until the array is ready.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.block_until_ready() is q
True
decompose(bases: Sequence[Unit | UnitBase | CompositeUnit | str], /)#

Decompose the quantity into the given bases.

Examples

>>> from unxt import Quantity
>>> q = Quantity(1, "m")
>>> q.decompose(["cm", "s"])
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

bases (Sequence[Unit | UnitBase | CompositeUnit | str])

Return type:

AbstractQuantity

property device: Device#

Device where the array is located.

Examples

>>> import unxt as u
>>> u.Quantity(1, "m").device
CpuDevice(id=0)
devices()#

Return the devices where the array is located.

Return type:

set[Device]

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.devices()
{CpuDevice(id=0)}
property distance: AbstractDistance#

The distance.

Examples

>>> import coordinax.distances as cxd
>>> d = cxd.Distance(10, "km")
>>> d.distance is d
True
>>> import coordinax.astro as cxastro
>>> cxastro.DistanceModulus(10, "mag").distance
Distance(1000., 'pc')
>>> p = cxastro.Parallax(1, "mas")
>>> p.distance.to("kpc")
Distance(1., 'kpc')
property dtype: dtype#

Data type of the array.

Examples

>>> import unxt as u
>>> u.Quantity(1, "m").dtype
dtype('int32')
flatten()#

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Quantity([[1, 2], [3, 4]], "m")
>>> q.flatten()
Quantity(Array([1, 2, 3, 4], dtype=int32), unit='m')
classmethod from_(cls: type[AbstractQuantity], *args: Any, **kwargs: Any)#
from_(cls: type[AbstractQuantity], value: ArrayLike | list[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex] | tuple[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex, ...], unit: Any, /, *, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a unxt.Quantity from an array-like value and a unit.

Parameters:
  • value – The array-like value.

  • unit – The unit of the value.

  • dtype – The data type of the array (keyword-only).

  • args (Any)

  • kwargs (Any)

Return type:

AbstractQuantity

Examples

For this example we’ll use the Quantity class. The same applies to any subclass of AbstractQuantity.

>>> import jax.numpy as jnp
>>> import unxt as u
>>> x = jnp.array([1.0, 2, 3])
>>> u.Quantity.from_(x, "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_([1.0, 2, 3], "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_((1.0, 2, 3), "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], value: ArrayLike | list[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex] | tuple[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex, ...], /, *, unit: Any, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Make a unxt.AbstractQuantity from an array-like value and a unit kwarg.

Examples

For this example we’ll use the unxt.Quantity class. The same applies to any subclass of unxt.AbstractQuantity.

>>> import unxt as u
>>> u.Quantity.from_([1.0, 2, 3], unit="m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], *, value: Any, unit: Any, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a AbstractQuantity from value and unit kwargs.

Examples

For this example we’ll use the Quantity class. The same applies to any subclass of AbstractQuantity.

>>> import unxt as u
>>> u.Quantity.from_(value=[1.0, 2, 3], unit="m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], mapping: Mapping[str, Any]) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from a Mapping.

Examples

For this example we’ll use the Quantity class. The same applies to any subclass of AbstractQuantity.

>>> import jax.numpy as jnp
>>> import unxt as u
>>> x = jnp.array([1.0, 2, 3])
>>> q = u.Quantity.from_({"value": x, "unit": "m"})
>>> q
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_({"value": q, "unit": "km"})
Quantity(Array([0.001, 0.002, 0.003], dtype=float32), unit='km')
from_(cls: type[AbstractQuantity], value: AbstractQuantity, unit: Any, /, *, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> u.Quantity.from_(q, "cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
from_(cls: type[AbstractQuantity], value: AbstractQuantity, unit: NoneType, /, *, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> u.Quantity.from_(q, None)
Quantity(Array(1, dtype=int32, ...), unit='m')
from_(cls: type[AbstractQuantity], value: AbstractQuantity, /, *, unit: Any | None = None, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity, with no unit change.

from_(cls: type[AbstractQuantity], value: Quantity, /, **kwargs: Any) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Quantity.from_(apyu.Quantity(1, "m"))
Quantity(Array(1., dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], value: Quantity, u: Any, /, **kwargs: Any) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Quantity.from_(apyu.Quantity(1, "m"), "cm")
Quantity(Array(100., dtype=float32), unit='cm')
from_(cls: type[Distance], value: ArrayLike, unit: Any, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> cxd.Distance.from_(1, "kpc")
Distance(1, 'kpc')
from_(cls: type[Distance], d: Distance, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> d = cxd.Distance(1, "kpc")
>>> cxd.Distance.from_(d) is d
True
>>> cxd.Distance.from_(d, dtype=float)
Distance(1., 'kpc')
from_(cls: type[Distance], d: Quantity[PhysicalType('length')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(1, "kpc")
>>> cxd.Distance.from_(q, dtype=float)
Distance(1., 'kpc')
from_(cls: type[Distance], p: Quantity[PhysicalType('angle')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from parallax.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(1, "mas")
>>> cxd.Distance.from_(q).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[Distance], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance modulus.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(10, "mag")
>>> cxd.Distance.from_(q).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[DistanceModulus], value: ArrayLike, unit: Any, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> DistanceModulus.from_(1, "mag")
DistanceModulus(1, 'mag')
from_(cls: type[DistanceModulus], dm: DistanceModulus, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance modulus.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> dm = DistanceModulus(1, "mag")
>>> DistanceModulus.from_(dm) is dm
True
>>> DistanceModulus.from_(dm, dtype=float)
DistanceModulus(1., 'mag')
from_(cls: type[DistanceModulus], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "mag")
>>> DistanceModulus.from_(q)
DistanceModulus(1, 'mag')
from_(cls: type[DistanceModulus], d: Distance, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import DistanceModulus
>>> d = cxd.Distance(1, "pc")
>>> DistanceModulus.from_(d)
DistanceModulus(-5., 'mag')
from_(cls: type[DistanceModulus], d: Quantity[PhysicalType('length')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "pc")
>>> DistanceModulus.from_(q)
DistanceModulus(-5., 'mag')
from_(cls: type[DistanceModulus], p: Quantity[PhysicalType('angle')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "mas")
>>> DistanceModulus.from_(q)
DistanceModulus(10., 'mag')
from_(cls: type[Distance], dm: DistanceModulus, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance modulus.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import DistanceModulus
>>> dm = DistanceModulus(10, "mag")
>>> cxd.Distance.from_(dm).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[Parallax], value: ArrayLike, unit: Any, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> Parallax.from_(1, "mas")
Parallax(1, 'mas')
from_(cls: type[Parallax], p: Parallax, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> p = Parallax(1, "mas")
>>> Parallax.from_(p) is p
True
>>> Parallax.from_(p, dtype=float)
Parallax(1., 'mas')
from_(cls: type[Parallax], p: Quantity[PhysicalType('angle')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> q = u.Q(1, "mas")
>>> Parallax.from_(q, dtype=float)
Parallax(1., 'mas')
from_(cls: type[Parallax], d: Distance | Quantity[PhysicalType('length')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from distance.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> d = cxd.Distance(10, "pc")
>>> Parallax.from_(d).uconvert("mas").round(2)
Parallax(100., 'mas')
>>> q = u.Q(10, "pc")
>>> Parallax.from_(q).uconvert("mas").round(2)
Parallax(100., 'mas')
from_(cls: type[Parallax], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Convert distance modulus to parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> dm = u.Q(10, "mag")
>>> Parallax.from_(dm).uconvert("mas").round(2)
Parallax(1., 'mas')
from_(cls: type[Distance], p: Parallax, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from parallax.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import Parallax
>>> p = Parallax(1, "mas")
>>> cxd.Distance.from_(p).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[DistanceModulus], p: Parallax, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from parallax.

>>> from coordinax.astro import DistanceModulus, Parallax
>>> p = Parallax(1, "mas")
>>> DistanceModulus.from_(p)
DistanceModulus(10., 'mag')
from_(cls: type[Parallax], dm: DistanceModulus, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Convert distance modulus to parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus, Parallax
>>> dm = DistanceModulus(10, "mag")
>>> Parallax.from_(dm).uconvert("mas").round(2)
Parallax(1., 'mas')
Parameters:
Return type:

AbstractQuantity

property mT: AbstractQuantity#

Matrix transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([[0, 1], [1, 2]], "m")
>>> q.mT
Quantity(Array([[0, 1],
                          [1, 2]], dtype=int32), unit='m')
max(*args: Any, **kwargs: Any)#

Return the maximum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.max()
Quantity(Array(3, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

mean(*args: Any, **kwargs: Any)#

Return the mean value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.mean()
Quantity(Array(2., dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

min(*args: Any, **kwargs: Any)#

Return the minimum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.min()
Quantity(Array(1, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

property ndim: int#

Number of dimensions.

Examples

>>> import unxt as u
>>> q = u.Quantity([[1]], "m")
>>> q.ndim
2
ravel()#

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Quantity([[1, 2], [3, 4]], "m")
>>> q.ravel()
Quantity(Array([1, 2, 3, 4], dtype=int32), unit='m')
reshape(*args: Any, order: str = 'C')#

Return a reshaped version of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3, 4], "m")
>>> q.reshape(2, 2)
Quantity(Array([[1, 2],
                          [3, 4]], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

round(*args: Any, **kwargs: Any)#

Round the array to the given number of decimals.

Examples

>>> import unxt as u
>>> q = u.Quantity([1.1, 2.2, 3.3], "m")
>>> q.round(0)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property shape: tuple[int, ...]#

Shape of the array.

property sharding: Any#

Return the sharding configuration of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.sharding
SingleDeviceSharding(device=..., memory_kind=...)
property size: int#

Total number of elements.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.size
3
squeeze(*args: Any, **kwargs: Any)#

Return the array with all single-dimensional entries removed.

Examples

>>> import unxt as u
>>> q = u.Quantity([[[1], [2], [3]]], "m")
>>> q.squeeze()
Quantity(Array([1, 2, 3], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

to(u: Any, /)#

Convert the quantity to the given units.

See unxt.quantity.AbstractQuantity.uconvert.

Examples

>>> from unxt import Quantity
>>> q = Quantity(1, "m")
>>> q.to("cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

u (Any)

Return type:

AbstractQuantity

to_device(device: None | Device = None)#

Move the array to a new device.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.to_device(None)
Quantity(Array(1, dtype=int32, weak_type=True), unit='m')
Parameters:

device (None | Device)

Return type:

AbstractQuantity

to_value(u: Any, /)#

Return the value in the given units.

See unxt.AbstractQuantity.ustrip.

Examples

>>> from unxt import Quantity
>>> q = Quantity(1, "m")
>>> q.to_value("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Union[Array, ndarray, bool, number, bool, int, float, complex]

uconvert(u: Any, /)#

Convert the quantity to the given units.

See also

None

convert a quantity to a new unit.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.uconvert("cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

u (Any)

Return type:

AbstractQuantity

ustrip(u: Any, /)#

Return the value in the given units.

See also

None

strip the units from a quantity.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.ustrip("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Array

check_negative: bool = True#

Whether to check that the distance is strictly non-negative.

final class coordinax.distances.Distance(value: Any, unit: Any, *, check_negative: bool = True)#

Bases: AbstractDistance

Distance quantities.

The distance is a quantity with dimensions of length.

Examples

>>> import coordinax.distances as cxd
>>> cxd.Distance(10, "km")
Distance(10, 'km')

The units are checked to have length dimensions.

>>> try: cxd.Distance(10, "s")
... except ValueError as e: print(e)
Distance must have dimensions length.
Parameters:
value: Shaped[Array, '*shape']#

The distance value.

unit: Unit | UnitBase | CompositeUnit#

The unit associated with this value.

property T: AbstractQuantity#

Transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([[0, 1], [1, 2]], "m")
>>> q.T
Quantity(Array([[0, 1],
                          [1, 2]], dtype=int32), unit='m')
argmax(*args: Any, **kwargs: Any)#

Return the indices of the maximum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.argmax()
Array(2, dtype=int32)
Parameters:
Return type:

Array

argmin(*args: Any, **kwargs: Any)#

Return the indices of the minimum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.argmin()
Array(0, dtype=int32)
Parameters:
Return type:

Array

astype(*args: Any, **kwargs: Any)#

Copy the array and cast to a specified dtype.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.dtype
dtype('int32')
>>> q.astype(float)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property at: _QuantityIndexUpdateHelper#

Helper property for index update functionality.

The at property provides a functionally pure equivalent of in-place array modifications.

In particular:

Alternate syntax

Equivalent In-place expression

x = x.at[idx].set(y)

x[idx] = y

x = x.at[idx].add(y)

x[idx] += y

x = x.at[idx].subtract(y)

x[idx] -= y

x = x.at[idx].multiply(y)

x[idx] *= y

x = x.at[idx].divide(y)

x[idx] /= y

x = x.at[idx].power(y)

x[idx] **= y

x = x.at[idx].min(y)

x[idx] = minimum(x[idx], y)

x = x.at[idx].max(y)

x[idx] = maximum(x[idx], y)

x = x.at[idx].apply(ufunc)

ufunc.at(x, idx)

x = x.at[idx].get()

x = x[idx]

None of the x.at expressions modify the original x; instead they return a modified copy of x. However, inside a jit() compiled function, expressions like x = x.at[idx].set(y) are guaranteed to be applied in-place.

Unlike NumPy in-place operations such as x[idx] += y, if multiple indices refer to the same location, all updates will be applied (NumPy would only apply the last update, rather than applying all updates.) The order in which conflicting updates are applied is implementation-defined and may be nondeterministic (e.g., due to concurrency on some hardware platforms).

By default, JAX assumes that all indices are in-bounds. Alternative out-of-bound index semantics can be specified via the mode parameter (see below).

Parameters:
  • mode

    string specifying out-of-bound indexing mode. Options are:

    • "promise_in_bounds": (default) The user promises that indices are in bounds. No additional checking will be performed. In practice, this means that out-of-bounds indices in get() will be clipped, and out-of-bounds indices in set(), add(), etc. will be dropped.

    • "clip": clamp out of bounds indices into valid range.

    • "drop": ignore out-of-bound indices.

    • "fill": alias for "drop". For get(), the optional fill_value argument specifies the value that will be returned.

    See jax.lax.GatherScatterMode for more details.

  • wrap_negative_indices – If True (default) then negative indices indicate position from the end of the array, similar to Python and NumPy indexing. If False, then negative indices are considered out-of-bounds and behave according to the mode parameter.

  • fill_value – Only applies to the get() method: the fill value to return for out-of-bounds slices when mode is 'fill'. Ignored otherwise. Defaults to NaN for inexact types, the largest negative value for signed types, the largest positive value for unsigned types, and True for booleans.

  • indices_are_sorted – If True, the implementation will assume that the (normalized) indices passed to at[] are sorted in ascending order, which can lead to more efficient execution on some backends. If True but the indices are not actually sorted, the output is undefined.

  • unique_indices – If True, the implementation will assume that the (normalized) indices passed to at[] are unique, which can result in more efficient execution on some backends. If True but the indices are not actually unique, the output is undefined.

Examples

>>> x = jnp.arange(5.0)
>>> x
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[2].get()
Array(2., dtype=float32)
>>> x.at[2].add(10)
Array([ 0.,  1., 12.,  3.,  4.], dtype=float32)

By default, out-of-bound indices are ignored in updates, but this behavior can be controlled with the mode parameter:

>>> x.at[10].add(10)  # dropped
Array([0., 1., 2., 3., 4.], dtype=float32)
>>> x.at[20].add(10, mode='clip')  # clipped
Array([ 0.,  1.,  2.,  3., 14.], dtype=float32)

For get(), out-of-bound indices are clipped by default:

>>> x.at[20].get()  # out-of-bounds indices clipped
Array(4., dtype=float32)
>>> x.at[20].get(mode='fill')  # out-of-bounds indices filled with NaN
Array(nan, dtype=float32)
>>> x.at[20].get(mode='fill', fill_value=-1)  # custom fill value
Array(-1., dtype=float32)

Negative indices count from the end of the array, but this behavior can be disabled by setting wrap_negative_indices = False:

>>> x.at[-1].set(99)
Array([ 0.,  1.,  2.,  3., 99.], dtype=float32)
>>> x.at[-1].set(99, wrap_negative_indices=False, mode='drop')  # dropped!
Array([0., 1., 2., 3., 4.], dtype=float32)
block_until_ready()#

Block until the array is ready.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.block_until_ready() is q
True
decompose(bases: Sequence[Unit | UnitBase | CompositeUnit | str], /)#

Decompose the quantity into the given bases.

Examples

>>> from unxt import Quantity
>>> q = Quantity(1, "m")
>>> q.decompose(["cm", "s"])
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

bases (Sequence[Unit | UnitBase | CompositeUnit | str])

Return type:

AbstractQuantity

property device: Device#

Device where the array is located.

Examples

>>> import unxt as u
>>> u.Quantity(1, "m").device
CpuDevice(id=0)
devices()#

Return the devices where the array is located.

Return type:

set[Device]

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.devices()
{CpuDevice(id=0)}
property distance: AbstractDistance#

The distance.

Examples

>>> import coordinax.distances as cxd
>>> d = cxd.Distance(10, "km")
>>> d.distance is d
True
>>> import coordinax.astro as cxastro
>>> cxastro.DistanceModulus(10, "mag").distance
Distance(1000., 'pc')
>>> p = cxastro.Parallax(1, "mas")
>>> p.distance.to("kpc")
Distance(1., 'kpc')
property dtype: dtype#

Data type of the array.

Examples

>>> import unxt as u
>>> u.Quantity(1, "m").dtype
dtype('int32')
flatten()#

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Quantity([[1, 2], [3, 4]], "m")
>>> q.flatten()
Quantity(Array([1, 2, 3, 4], dtype=int32), unit='m')
classmethod from_(cls: type[AbstractQuantity], *args: Any, **kwargs: Any)#
from_(cls: type[AbstractQuantity], value: ArrayLike | list[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex] | tuple[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex, ...], unit: Any, /, *, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a unxt.Quantity from an array-like value and a unit.

Parameters:
  • value – The array-like value.

  • unit – The unit of the value.

  • dtype – The data type of the array (keyword-only).

  • args (Any)

  • kwargs (Any)

Return type:

AbstractQuantity

Examples

For this example we’ll use the Quantity class. The same applies to any subclass of AbstractQuantity.

>>> import jax.numpy as jnp
>>> import unxt as u
>>> x = jnp.array([1.0, 2, 3])
>>> u.Quantity.from_(x, "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_([1.0, 2, 3], "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_((1.0, 2, 3), "m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], value: ArrayLike | list[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex] | tuple[jaxtyping.Shaped[Array, ''] | jaxtyping.Shaped[ndarray, ''] | bool | number | bool | int | float | complex, ...], /, *, unit: Any, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Make a unxt.AbstractQuantity from an array-like value and a unit kwarg.

Examples

For this example we’ll use the unxt.Quantity class. The same applies to any subclass of unxt.AbstractQuantity.

>>> import unxt as u
>>> u.Quantity.from_([1.0, 2, 3], unit="m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], *, value: Any, unit: Any, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a AbstractQuantity from value and unit kwargs.

Examples

For this example we’ll use the Quantity class. The same applies to any subclass of AbstractQuantity.

>>> import unxt as u
>>> u.Quantity.from_(value=[1.0, 2, 3], unit="m")
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], mapping: Mapping[str, Any]) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from a Mapping.

Examples

For this example we’ll use the Quantity class. The same applies to any subclass of AbstractQuantity.

>>> import jax.numpy as jnp
>>> import unxt as u
>>> x = jnp.array([1.0, 2, 3])
>>> q = u.Quantity.from_({"value": x, "unit": "m"})
>>> q
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
>>> u.Quantity.from_({"value": q, "unit": "km"})
Quantity(Array([0.001, 0.002, 0.003], dtype=float32), unit='km')
from_(cls: type[AbstractQuantity], value: AbstractQuantity, unit: Any, /, *, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> u.Quantity.from_(q, "cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
from_(cls: type[AbstractQuantity], value: AbstractQuantity, unit: NoneType, /, *, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> u.Quantity.from_(q, None)
Quantity(Array(1, dtype=int32, ...), unit='m')
from_(cls: type[AbstractQuantity], value: AbstractQuantity, /, *, unit: Any | None = None, dtype: Any = None) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity, with no unit change.

from_(cls: type[AbstractQuantity], value: Quantity, /, **kwargs: Any) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Quantity.from_(apyu.Quantity(1, "m"))
Quantity(Array(1., dtype=float32), unit='m')
from_(cls: type[AbstractQuantity], value: Quantity, u: Any, /, **kwargs: Any) AbstractQuantity
Parameters:
Return type:

AbstractQuantity

Construct a Quantity from another Quantity.

The value is converted to the new unit.

Examples

>>> import unxt as u
>>> import astropy.units as apyu
>>> u.Quantity.from_(apyu.Quantity(1, "m"), "cm")
Quantity(Array(100., dtype=float32), unit='cm')
from_(cls: type[Distance], value: ArrayLike, unit: Any, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> cxd.Distance.from_(1, "kpc")
Distance(1, 'kpc')
from_(cls: type[Distance], d: Distance, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> d = cxd.Distance(1, "kpc")
>>> cxd.Distance.from_(d) is d
True
>>> cxd.Distance.from_(d, dtype=float)
Distance(1., 'kpc')
from_(cls: type[Distance], d: Quantity[PhysicalType('length')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(1, "kpc")
>>> cxd.Distance.from_(q, dtype=float)
Distance(1., 'kpc')
from_(cls: type[Distance], p: Quantity[PhysicalType('angle')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from parallax.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(1, "mas")
>>> cxd.Distance.from_(q).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[Distance], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance modulus.

>>> import unxt as u
>>> import coordinax.distances as cxd
>>> q = u.Q(10, "mag")
>>> cxd.Distance.from_(q).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[DistanceModulus], value: ArrayLike, unit: Any, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> DistanceModulus.from_(1, "mag")
DistanceModulus(1, 'mag')
from_(cls: type[DistanceModulus], dm: DistanceModulus, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance modulus.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> dm = DistanceModulus(1, "mag")
>>> DistanceModulus.from_(dm) is dm
True
>>> DistanceModulus.from_(dm, dtype=float)
DistanceModulus(1., 'mag')
from_(cls: type[DistanceModulus], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "mag")
>>> DistanceModulus.from_(q)
DistanceModulus(1, 'mag')
from_(cls: type[DistanceModulus], d: Distance, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import DistanceModulus
>>> d = cxd.Distance(1, "pc")
>>> DistanceModulus.from_(d)
DistanceModulus(-5., 'mag')
from_(cls: type[DistanceModulus], d: Quantity[PhysicalType('length')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from distance.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "pc")
>>> DistanceModulus.from_(q)
DistanceModulus(-5., 'mag')
from_(cls: type[DistanceModulus], p: Quantity[PhysicalType('angle')], /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus
>>> q = u.Q(1, "mas")
>>> DistanceModulus.from_(q)
DistanceModulus(10., 'mag')
from_(cls: type[Distance], dm: DistanceModulus, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from distance modulus.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import DistanceModulus
>>> dm = DistanceModulus(10, "mag")
>>> cxd.Distance.from_(dm).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[Parallax], value: ArrayLike, unit: Any, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Construct a distance.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> Parallax.from_(1, "mas")
Parallax(1, 'mas')
from_(cls: type[Parallax], p: Parallax, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> p = Parallax(1, "mas")
>>> Parallax.from_(p) is p
True
>>> Parallax.from_(p, dtype=float)
Parallax(1., 'mas')
from_(cls: type[Parallax], p: Quantity[PhysicalType('angle')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> q = u.Q(1, "mas")
>>> Parallax.from_(q, dtype=float)
Parallax(1., 'mas')
from_(cls: type[Parallax], d: Distance | Quantity[PhysicalType('length')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Compute parallax from distance.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> d = cxd.Distance(10, "pc")
>>> Parallax.from_(d).uconvert("mas").round(2)
Parallax(100., 'mas')
>>> q = u.Q(10, "pc")
>>> Parallax.from_(q).uconvert("mas").round(2)
Parallax(100., 'mas')
from_(cls: type[Parallax], dm: Quantity[PhysicalType('unknown')], /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Convert distance modulus to parallax.

>>> import unxt as u
>>> from coordinax.astro import Parallax
>>> dm = u.Q(10, "mag")
>>> Parallax.from_(dm).uconvert("mas").round(2)
Parallax(1., 'mas')
from_(cls: type[Distance], p: Parallax, /, **kw: Any) Distance
Parameters:
Return type:

AbstractQuantity

Compute distance from parallax.

>>> import coordinax.distances as cxd
>>> from coordinax.astro import Parallax
>>> p = Parallax(1, "mas")
>>> cxd.Distance.from_(p).uconvert("pc").round(2)
Distance(1000., 'pc')
from_(cls: type[DistanceModulus], p: Parallax, /, **kw: Any) DistanceModulus
Parameters:
Return type:

AbstractQuantity

Compute distance modulus from parallax.

>>> from coordinax.astro import DistanceModulus, Parallax
>>> p = Parallax(1, "mas")
>>> DistanceModulus.from_(p)
DistanceModulus(10., 'mag')
from_(cls: type[Parallax], dm: DistanceModulus, /, **kw: Any) Parallax
Parameters:
Return type:

AbstractQuantity

Convert distance modulus to parallax.

>>> import unxt as u
>>> from coordinax.astro import DistanceModulus, Parallax
>>> dm = DistanceModulus(10, "mag")
>>> Parallax.from_(dm).uconvert("mas").round(2)
Parallax(1., 'mas')
Parameters:
Return type:

AbstractQuantity

property mT: AbstractQuantity#

Matrix transpose of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([[0, 1], [1, 2]], "m")
>>> q.mT
Quantity(Array([[0, 1],
                          [1, 2]], dtype=int32), unit='m')
max(*args: Any, **kwargs: Any)#

Return the maximum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.max()
Quantity(Array(3, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

mean(*args: Any, **kwargs: Any)#

Return the mean value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.mean()
Quantity(Array(2., dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

min(*args: Any, **kwargs: Any)#

Return the minimum value.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.min()
Quantity(Array(1, dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

property ndim: int#

Number of dimensions.

Examples

>>> import unxt as u
>>> q = u.Quantity([[1]], "m")
>>> q.ndim
2
ravel()#

Return a flattened version of the array.

Return type:

AbstractQuantity

Examples

>>> import unxt as u
>>> q = u.Quantity([[1, 2], [3, 4]], "m")
>>> q.ravel()
Quantity(Array([1, 2, 3, 4], dtype=int32), unit='m')
reshape(*args: Any, order: str = 'C')#

Return a reshaped version of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3, 4], "m")
>>> q.reshape(2, 2)
Quantity(Array([[1, 2],
                          [3, 4]], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

round(*args: Any, **kwargs: Any)#

Round the array to the given number of decimals.

Examples

>>> import unxt as u
>>> q = u.Quantity([1.1, 2.2, 3.3], "m")
>>> q.round(0)
Quantity(Array([1., 2., 3.], dtype=float32), unit='m')
Parameters:
Return type:

AbstractQuantity

property shape: tuple[int, ...]#

Shape of the array.

property sharding: Any#

Return the sharding configuration of the array.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.sharding
SingleDeviceSharding(device=..., memory_kind=...)
property size: int#

Total number of elements.

Examples

>>> import unxt as u
>>> q = u.Quantity([1, 2, 3], "m")
>>> q.size
3
squeeze(*args: Any, **kwargs: Any)#

Return the array with all single-dimensional entries removed.

Examples

>>> import unxt as u
>>> q = u.Quantity([[[1], [2], [3]]], "m")
>>> q.squeeze()
Quantity(Array([1, 2, 3], dtype=int32), unit='m')
Parameters:
Return type:

AbstractQuantity

to(u: Any, /)#

Convert the quantity to the given units.

See unxt.quantity.AbstractQuantity.uconvert.

Examples

>>> from unxt import Quantity
>>> q = Quantity(1, "m")
>>> q.to("cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

u (Any)

Return type:

AbstractQuantity

to_device(device: None | Device = None)#

Move the array to a new device.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.to_device(None)
Quantity(Array(1, dtype=int32, weak_type=True), unit='m')
Parameters:

device (None | Device)

Return type:

AbstractQuantity

to_value(u: Any, /)#

Return the value in the given units.

See unxt.AbstractQuantity.ustrip.

Examples

>>> from unxt import Quantity
>>> q = Quantity(1, "m")
>>> q.to_value("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Union[Array, ndarray, bool, number, bool, int, float, complex]

uconvert(u: Any, /)#

Convert the quantity to the given units.

See also

None

convert a quantity to a new unit.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.uconvert("cm")
Quantity(Array(100., dtype=float32, ...), unit='cm')
Parameters:

u (Any)

Return type:

AbstractQuantity

ustrip(u: Any, /)#

Return the value in the given units.

See also

None

strip the units from a quantity.

Examples

>>> import unxt as u
>>> q = u.Quantity(1, "m")
>>> q.ustrip("cm")
Array(100., dtype=float32, weak_type=True)
Parameters:

u (Any)

Return type:

Array

check_negative: bool = True#

Whether to check that the distance is strictly non-negative.