Skip to content

Commit

Permalink
feat: constructor for GalileanSpatialTranslationOperator (#192)
Browse files Browse the repository at this point in the history
* feat: constructor for GalileanSpatialTranslationOperator
* ci: ignore pylint arguments-differ because of plum

Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman authored Sep 19, 2024
1 parent 062c4ae commit 70ef37d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@
ignore-paths = [".*/_version.py"]
messages_control.disable = [
"abstract-method", # pylint doesn't like ABC hierarchies
"arguments-differ", # plum-dispatch
"cyclic-import", # broken?
"design",
"duplicate-code",
Expand Down
52 changes: 51 additions & 1 deletion src/coordinax/_src/operators/galilean/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

from dataclasses import replace
from typing import Any, Literal, final
from typing_extensions import override

import equinox as eqx
from plum import convert
from jaxtyping import ArrayLike
from plum import convert, dispatch

import quaxed.numpy as jnp
from unxt import Quantity
Expand Down Expand Up @@ -176,6 +178,54 @@ class GalileanSpatialTranslationOperator(AbstractGalileanOperator):

# -------------------------------------------

@override
@classmethod
@dispatch
def constructor(
cls: "type[GalileanSpatialTranslationOperator]",
x: ArrayLike | list[float | int],
unit: str, # TODO: support unit object
/,
) -> "GalileanSpatialTranslationOperator":
"""Construct a spatial translation operator.
Examples
--------
>>> from unxt import Quantity
>>> import coordinax as cx
>>> op = cx.operators.GalileanSpatialTranslationOperator.constructor([1, 1, 1], "kpc")
>>> op.translation.x
Quantity['length'](Array(1., dtype=float32), unit='kpc')
""" # noqa: E501
return cls(Quantity(x, unit))

@override
@classmethod
@dispatch
def constructor(
cls: "type[GalileanSpatialTranslationOperator]",
x: ArrayLike | list[float | int],
*,
unit: Any,
) -> "GalileanSpatialTranslationOperator":
"""Construct a spatial translation operator.
Examples
--------
>>> from unxt import Quantity
>>> import coordinax as cx
>>> op = cx.operators.GalileanSpatialTranslationOperator.constructor([1, 1, 1], "kpc")
>>> op.translation.x
Quantity['length'](Array(1., dtype=float32), unit='kpc')
""" # noqa: E501
return cls(Quantity(x, unit))

# -------------------------------------------

@property
def is_inertial(self) -> Literal[True]:
"""Galilean translation is an inertial frame-preserving transformation.
Expand Down

0 comments on commit 70ef37d

Please sign in to comment.