Skip to content

Commit

Permalink
feat: renames (#114)
Browse files Browse the repository at this point in the history
* refactor: rename base velocity file
* refactor: rename base position file
* refactor: rename AbstractVector to AbstractPosition
* refactor: rename AbstractVectorDifferential to AbstractVelocity
* refactor: rename AbstractVectorBase to AbstractVector
  • Loading branch information
nstarman authored Jun 1, 2024
1 parent 14f7c1a commit 7993407
Show file tree
Hide file tree
Showing 28 changed files with 210 additions and 212 deletions.
16 changes: 8 additions & 8 deletions src/coordinax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

from . import (
_base,
_base_dif,
_base_vec,
_base_pos,
_base_vel,
_d1,
_d2,
_d3,
Expand All @@ -23,8 +23,8 @@
operators,
)
from ._base import *
from ._base_dif import *
from ._base_vec import *
from ._base_pos import *
from ._base_vel import *
from ._d1 import *
from ._d2 import *
from ._d3 import *
Expand All @@ -39,8 +39,8 @@

__all__ = ["__version__", "operators"]
__all__ += _base.__all__
__all__ += _base_vec.__all__
__all__ += _base_dif.__all__
__all__ += _base_pos.__all__
__all__ += _base_vel.__all__
__all__ += _d1.__all__
__all__ += _d2.__all__
__all__ += _d3.__all__
Expand All @@ -58,8 +58,8 @@
# Cleanup
del (
_base,
_base_dif,
_base_vec,
_base_vel,
_base_pos,
_exceptions,
_transform,
_typing,
Expand Down
38 changes: 18 additions & 20 deletions src/coordinax/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__all__ = [
# vector classes
"AbstractVectorBase",
"AbstractVector",
# other
"ToUnitsOptions",
]
Expand Down Expand Up @@ -30,7 +30,7 @@
if TYPE_CHECKING:
from typing_extensions import Self

BT = TypeVar("BT", bound="AbstractVectorBase")
BT = TypeVar("BT", bound="AbstractVector")


class ToUnitsOptions(Enum):
Expand All @@ -43,7 +43,7 @@ class ToUnitsOptions(Enum):
# ===================================================================


class AbstractVectorBase(eqx.Module): # type: ignore[misc]
class AbstractVector(eqx.Module): # type: ignore[misc]
"""Base class for all vector types.
A vector is a collection of components that can be represented in different
Expand All @@ -54,7 +54,7 @@ class AbstractVectorBase(eqx.Module): # type: ignore[misc]
@classproperty
@classmethod
@abstractmethod
def _cartesian_cls(cls) -> type["AbstractVectorBase"]:
def _cartesian_cls(cls) -> type["AbstractVector"]:
"""Return the corresponding Cartesian vector class.
Examples
Expand All @@ -77,8 +77,8 @@ def _cartesian_cls(cls) -> type["AbstractVectorBase"]:
@classmethod
@dispatch
def constructor(
cls: "type[AbstractVectorBase]", obj: Mapping[str, Quantity], /
) -> "AbstractVectorBase":
cls: "type[AbstractVector]", obj: Mapping[str, Quantity], /
) -> "AbstractVector":
"""Construct a vector from a mapping.
Parameters
Expand Down Expand Up @@ -117,10 +117,10 @@ def constructor(
@classmethod
@dispatch
def constructor(
cls: "type[AbstractVectorBase]",
cls: "type[AbstractVector]",
obj: Quantity | u.Quantity,
/, # TODO: shape hint
) -> "AbstractVectorBase":
) -> "AbstractVector":
"""Construct a vector from a Quantity array.
The array is expected to have the components as the last dimension.
Expand Down Expand Up @@ -182,7 +182,7 @@ def __getitem__(self, index: Any) -> "Self":
Returns
-------
AbstractVectorBase
AbstractVector
The vector with the slice applied.
Examples
Expand Down Expand Up @@ -364,7 +364,7 @@ def to_device(self, device: None | Device = None) -> "Self":
Returns
-------
AbstractVectorBase
AbstractVector
The vector moved to the new device.
Examples
Expand Down Expand Up @@ -426,7 +426,7 @@ def reshape(self, *shape: Any, order: str = "C") -> "Self":
Returns
-------
AbstractVectorBase
AbstractVector
The vector with the reshaped components.
Examples
Expand Down Expand Up @@ -555,7 +555,7 @@ def represent_as(self, target: type[BT], /, *args: Any, **kwargs: Any) -> BT:
raise NotImplementedError

@dispatch
def to_units(self, units: Any) -> "AbstractVectorBase":
def to_units(self, units: Any) -> "AbstractVector":
"""Convert the vector to the given units.
Parameters
Expand Down Expand Up @@ -593,7 +593,7 @@ def to_units(self, units: Any) -> "AbstractVectorBase":
@dispatch
def to_units(
self, units: Mapping[u.PhysicalType | str, Unit | str], /
) -> "AbstractVectorBase":
) -> "AbstractVector":
"""Convert the vector to the given units.
Parameters
Expand Down Expand Up @@ -639,9 +639,7 @@ def to_units(
)

@dispatch
def to_units(
self, _: Literal[ToUnitsOptions.consistent], /
) -> "AbstractVectorBase":
def to_units(self, _: Literal[ToUnitsOptions.consistent], /) -> "AbstractVector":
"""Convert the vector to a self-consistent set of units.
Parameters
Expand Down Expand Up @@ -726,15 +724,15 @@ def __str__(self) -> str:


# TODO: move to the class in py3.11+
@AbstractVectorBase.constructor._f.register # type: ignore[attr-defined, misc] # noqa: SLF001
@AbstractVector.constructor._f.register # type: ignore[attr-defined, misc] # noqa: SLF001
def constructor( # noqa: D417
cls: type[AbstractVectorBase], obj: AbstractVectorBase, /
) -> AbstractVectorBase:
cls: type[AbstractVector], obj: AbstractVector, /
) -> AbstractVector:
"""Construct a vector from another vector.
Parameters
----------
obj : :class:`coordinax.AbstractVectorBase`
obj : :class:`coordinax.AbstractVector`
The vector to construct from.
Examples
Expand Down
32 changes: 16 additions & 16 deletions src/coordinax/_base_vec.py → src/coordinax/_base_pos.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Representation of coordinates in different systems."""

__all__ = ["AbstractVector"]
__all__ = ["AbstractPosition"]

import operator
import warnings
Expand All @@ -16,18 +16,18 @@

from unxt import Quantity

from ._base import AbstractVectorBase
from ._base import AbstractVector
from ._utils import classproperty, dataclass_items

if TYPE_CHECKING:
from typing_extensions import Self

VT = TypeVar("VT", bound="AbstractVector")
VT = TypeVar("VT", bound="AbstractPosition")

VECTOR_CLASSES: set[type["AbstractVector"]] = set()
VECTOR_CLASSES: set[type["AbstractPosition"]] = set()


class AbstractVector(AbstractVectorBase): # pylint: disable=abstract-method
class AbstractPosition(AbstractVector): # pylint: disable=abstract-method
"""Abstract representation of coordinates in different systems."""

def __init_subclass__(cls, **kwargs: Any) -> None:
Expand All @@ -44,7 +44,7 @@ def __init_subclass__(cls, **kwargs: Any) -> None:
@classproperty
@classmethod
@abstractmethod
def differential_cls(cls) -> type["AbstractVectorDifferential"]:
def differential_cls(cls) -> type["AbstractVelocity"]:
"""Return the corresponding differential vector class.
Examples
Expand Down Expand Up @@ -79,7 +79,7 @@ def __neg__(self) -> "Self":

def __add__(self, other: Any) -> "Self":
"""Add another object to this vector."""
if not isinstance(other, AbstractVector):
if not isinstance(other, AbstractPosition):
return NotImplemented

# The base implementation is to convert to Cartesian and perform the
Expand All @@ -93,7 +93,7 @@ def __add__(self, other: Any) -> "Self":

def __sub__(self, other: Any) -> "Self":
"""Add another object to this vector."""
if not isinstance(other, AbstractVector):
if not isinstance(other, AbstractPosition):
return NotImplemented

# The base implementation is to convert to Cartesian and perform the
Expand All @@ -106,30 +106,30 @@ def __sub__(self, other: Any) -> "Self":
).represent_as(type(self))

@dispatch
def __mul__(self: "AbstractVector", other: Any) -> Any:
def __mul__(self: "AbstractPosition", other: Any) -> Any:
return NotImplemented

@dispatch
def __mul__(self: "AbstractVector", other: ArrayLike) -> Any:
def __mul__(self: "AbstractPosition", other: ArrayLike) -> Any:
return replace(self, **{k: v * other for k, v in dataclass_items(self)})

@dispatch
def __truediv__(self: "AbstractVector", other: Any) -> Any:
def __truediv__(self: "AbstractPosition", other: Any) -> Any:
return NotImplemented

@dispatch
def __truediv__(self: "AbstractVector", other: ArrayLike) -> Any:
def __truediv__(self: "AbstractPosition", other: ArrayLike) -> Any:
return replace(self, **{k: v / other for k, v in dataclass_items(self)})

# ---------------------------------
# Reverse binary operations

@dispatch
def __rmul__(self: "AbstractVector", other: Any) -> Any:
def __rmul__(self: "AbstractPosition", other: Any) -> Any:
return NotImplemented

@dispatch
def __rmul__(self: "AbstractVector", other: ArrayLike) -> Any:
def __rmul__(self: "AbstractPosition", other: ArrayLike) -> Any:
return replace(self, **{k: other * v for k, v in dataclass_items(self)})

# ===============================================================
Expand All @@ -141,7 +141,7 @@ def represent_as(self, target: type[VT], /, *args: Any, **kwargs: Any) -> VT:
Parameters
----------
target : type[AbstractVector]
target : type[AbstractPosition]
The type to represent the vector as.
*args : Any
Extra arguments. Raises a warning if any are given.
Expand All @@ -150,7 +150,7 @@ def represent_as(self, target: type[VT], /, *args: Any, **kwargs: Any) -> VT:
Returns
-------
AbstractVector
AbstractPosition
The vector represented as the target type.
Warns
Expand Down
26 changes: 12 additions & 14 deletions src/coordinax/_base_dif.py → src/coordinax/_base_vel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Representation of coordinates in different systems."""
"""Representation of velocities in different systems."""

__all__ = ["AbstractVectorDifferential"]
__all__ = ["AbstractVelocity"]

import warnings
from abc import abstractmethod
Expand All @@ -13,19 +13,19 @@

from unxt import Quantity

from ._base import AbstractVectorBase
from ._base_vec import AbstractVector
from ._base import AbstractVector
from ._base_pos import AbstractPosition
from ._utils import classproperty, dataclass_items

if TYPE_CHECKING:
from typing_extensions import Self

DT = TypeVar("DT", bound="AbstractVectorDifferential")
DT = TypeVar("DT", bound="AbstractVelocity")

DIFFERENTIAL_CLASSES: set[type["AbstractVectorDifferential"]] = set()
DIFFERENTIAL_CLASSES: set[type["AbstractVelocity"]] = set()


class AbstractVectorDifferential(AbstractVectorBase): # pylint: disable=abstract-method
class AbstractVelocity(AbstractVector): # pylint: disable=abstract-method
"""Abstract representation of vector differentials in different systems."""

def __init_subclass__(cls, **kwargs: Any) -> None:
Expand All @@ -38,7 +38,7 @@ def __init_subclass__(cls, **kwargs: Any) -> None:
@classproperty
@classmethod
@abstractmethod
def integral_cls(cls) -> type["AbstractVector"]:
def integral_cls(cls) -> type["AbstractPosition"]:
"""Return the corresponding vector class.
Examples
Expand Down Expand Up @@ -83,9 +83,7 @@ def __neg__(self) -> "Self":
# Binary operations

@dispatch # type: ignore[misc]
def __mul__(
self: "AbstractVectorDifferential", other: Quantity
) -> "AbstractVector":
def __mul__(self: "AbstractVelocity", other: Quantity) -> "AbstractPosition":
"""Multiply the vector by a :class:`unxt.Quantity`.
Examples
Expand All @@ -110,7 +108,7 @@ def __mul__(

@partial(jax.jit, static_argnums=1)
def represent_as(
self, target: type[DT], position: AbstractVector, /, *args: Any, **kwargs: Any
self, target: type[DT], position: AbstractPosition, /, *args: Any, **kwargs: Any
) -> DT:
"""Represent the vector as another type."""
if any(args):
Expand All @@ -121,15 +119,15 @@ def represent_as(
return represent_as(self, target, position, **kwargs)

@partial(jax.jit)
def norm(self, position: AbstractVector, /) -> Quantity["speed"]:
def norm(self, position: AbstractPosition, /) -> Quantity["speed"]:
"""Return the norm of the vector."""
return self.represent_as(self._cartesian_cls, position).norm()


# =============================================================================


class AdditionMixin(AbstractVectorBase):
class AdditionMixin(AbstractVector):
"""Mixin for addition operations."""

def __add__(self: "Self", other: Any, /) -> "Self":
Expand Down
Loading

0 comments on commit 7993407

Please sign in to comment.