Skip to content

Commit

Permalink
refactor: cleanup (#81)
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <nstarman@users.noreply.github.com>
  • Loading branch information
nstarman authored Sep 17, 2024
1 parent 7e6687e commit 0a04f96
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
31 changes: 16 additions & 15 deletions src/quaxed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@
quaxed: Pre-quaxed libraries for multiple dispatch over abstract array types in JAX
"""
# pylint: disable=C0415,W0621

# pylint: disable=redefined-builtin
from __future__ import annotations

__all__ = ["__version__", "lax", "scipy"]
from typing import TYPE_CHECKING

import sys
from typing import Any

import plum
from jaxtyping import ArrayLike

from . import _jax, lax, scipy
from . import _jax, lax, numpy, scipy
from ._jax import *
from ._setup import JAX_VERSION
from ._version import version as __version__
from ._version import version as __version__ # noqa: F401

__all__ = ["lax", "numpy", "scipy"]
__all__ += _jax.__all__

if JAX_VERSION < (0, 4, 32):
Expand All @@ -26,15 +22,16 @@
__all__ += ["array_api"]


# Simplify the display of ArrayLike
plum.activate_union_aliases()
plum.set_union_alias(ArrayLike, "ArrayLike")
if TYPE_CHECKING:
from typing import Any


def __getattr__(name: str) -> Any: # TODO: fuller annotation
"""Forward all other attribute accesses to Quaxified JAX."""
import jax # pylint: disable=C0415,W0621
from quax import quaxify # pylint: disable=C0415,W0621
import sys

import jax
from quax import quaxify

# TODO: detect if the attribute is a function or a module.
# If it is a function, quaxify it. If it is a module, return a proxy object
Expand All @@ -45,3 +42,7 @@ def __getattr__(name: str) -> Any: # TODO: fuller annotation
setattr(sys.modules[__name__], name, out)

return out


# Clean up the namespace
del TYPE_CHECKING
11 changes: 7 additions & 4 deletions src/quaxed/_types.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""Copyright (c) 2023 Nathaniel Starkman. All rights reserved.
quaxed: Pre-quaxed libraries for multiple dispatch over abstract array types in JAX
"""
"""Copyright (c) 2023 Nathaniel Starkman. All rights reserved."""

__all__: list[str] = []

from typing import Any, Protocol, runtime_checkable

import jax.numpy as jnp
import plum
from jaxtyping import ArrayLike

# Simplify the display of ArrayLike
plum.activate_union_aliases()
plum.set_union_alias(ArrayLike, "ArrayLike")


@runtime_checkable
Expand Down

0 comments on commit 0a04f96

Please sign in to comment.