From 70ef37d0a122d243ce68d9ccc85dc22d547a9b05 Mon Sep 17 00:00:00 2001 From: Nathaniel Starkman Date: Thu, 19 Sep 2024 15:47:34 -0400 Subject: [PATCH] feat: constructor for GalileanSpatialTranslationOperator (#192) * feat: constructor for GalileanSpatialTranslationOperator * ci: ignore pylint arguments-differ because of plum Signed-off-by: nstarman --- pyproject.toml | 1 + .../_src/operators/galilean/translation.py | 52 ++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 191616b..fabd2a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/src/coordinax/_src/operators/galilean/translation.py b/src/coordinax/_src/operators/galilean/translation.py index 8fe7fe3..a2ff534 100644 --- a/src/coordinax/_src/operators/galilean/translation.py +++ b/src/coordinax/_src/operators/galilean/translation.py @@ -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 @@ -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.