Skip to content

Commit

Permalink
🎨 style(dimensions): restructure private files (#372)
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Starkman <[email protected]>
  • Loading branch information
nstarman authored Jan 21, 2025
1 parent ef1e1d6 commit 1b4f527
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 31 deletions.
6 changes: 5 additions & 1 deletion src/unxt/_src/dimensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

__all__ = ["AbstractDimension", "dimension", "dimension_of"]

from .core import AbstractDimension, dimension, dimension_of
from .api import AbstractDimension, dimension, dimension_of

# Register the dispatches
# isort: split
from . import core # noqa: F401
41 changes: 41 additions & 0 deletions src/unxt/_src/dimensions/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Units objects in JAX.
Copyright (c) 2023 Galactic Dynamics. All rights reserved.
"""

__all__ = ["dimension", "dimension_of"]

from typing import Any, TypeAlias

import astropy.units as apyu
from plum import dispatch

AbstractDimension: TypeAlias = apyu.PhysicalType


@dispatch.abstract
def dimension(obj: Any, /) -> AbstractDimension:
"""Construct the dimension.
.. note::
This function uses multiple dispatch. Dispatches made in other modules
may not be included in the rendered docs. To see the full range of
options, execute ``unxt.dims.dimension.methods`` in an interactive
Python session.
"""


@dispatch.abstract
def dimension_of(obj: Any, /) -> AbstractDimension:
"""Return the dimension of the given units.
.. note::
This function uses multiple dispatch. Dispatches made in other modules
may not be included in the rendered docs. To see the full range of
options, execute ``unxt.dimension_of.methods`` in an interactive Python
session.
"""
33 changes: 3 additions & 30 deletions src/unxt/_src/dimensions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,23 @@
Copyright (c) 2023 Galactic Dynamics. All rights reserved.
"""

__all__ = ["dimension", "dimension_of"]
__all__: list[str] = []

from typing import Any, TypeAlias

import astropy.units as apyu
from astropy.units import Unit
from plum import dispatch

from .api import AbstractDimension

AbstractUnits: TypeAlias = apyu.UnitBase | Unit
AbstractDimension: TypeAlias = apyu.PhysicalType


# ===================================================================
# Construct the dimensions


@dispatch.abstract
def dimension(obj: Any, /) -> AbstractDimension:
"""Construct the dimension.
.. note::
This function uses multiple dispatch. Dispatches made in other modules
may not be included in the rendered docs. To see the full range of
options, execute ``unxt.dims.dimension.methods`` in an interactive
Python session.
"""


@dispatch
def dimension(obj: AbstractDimension, /) -> AbstractDimension:
"""Construct dimension from a dimension object.
Expand Down Expand Up @@ -71,20 +58,6 @@ def dimension(obj: str, /) -> AbstractDimension:
# Get the dimension


@dispatch.abstract
def dimension_of(obj: Any, /) -> AbstractDimension:
"""Return the dimension of the given units.
.. note::
This function uses multiple dispatch. Dispatches made in other modules
may not be included in the rendered docs. To see the full range of
options, execute ``unxt.dimension_of.methods`` in an interactive Python
session.
"""


@dispatch
def dimension_of(obj: Any, /) -> None:
"""Most objects have no dimension.
Expand Down

0 comments on commit 1b4f527

Please sign in to comment.