ainmax 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ainmax might be problematic. Click here for more details.

Files changed (51) hide show
  1. ainmax/__init__.py +43 -0
  2. ainmax/_src/__init__.py +0 -0
  3. ainmax/_src/array.py +158 -0
  4. ainmax/_src/axis.py +57 -0
  5. ainmax/_src/axis_util.py +561 -0
  6. ainmax/_src/basearray.py +13 -0
  7. ainmax/_src/basearray.pyi +252 -0
  8. ainmax/_src/config.py +203 -0
  9. ainmax/_src/feidhm/__init__.py +18 -0
  10. ainmax/_src/feidhm/constructors.py +82 -0
  11. ainmax/_src/feidhm/creation.py +916 -0
  12. ainmax/_src/feidhm/indexing.py +736 -0
  13. ainmax/_src/feidhm/integrate.py +85 -0
  14. ainmax/_src/feidhm/linalg.py +1576 -0
  15. ainmax/_src/feidhm/methods.py +616 -0
  16. ainmax/_src/feidhm/operations.py +2252 -0
  17. ainmax/_src/feidhm/polynomials.py +478 -0
  18. ainmax/_src/feidhm/reductions.py +1122 -0
  19. ainmax/_src/feidhm/signal.py +594 -0
  20. ainmax/_src/feidhm/special.py +1149 -0
  21. ainmax/_src/feidhm/tensor_contractions.py +499 -0
  22. ainmax/_src/feidhm/ufuncs.py +1558 -0
  23. ainmax/_src/feidhm/util.py +202 -0
  24. ainmax/_src/filters.py +70 -0
  25. ainmax/_src/hof.py +340 -0
  26. ainmax/_src/nn/__init__.py +0 -0
  27. ainmax/_src/nn/activations.py +128 -0
  28. ainmax/_src/nn/conv.py +349 -0
  29. ainmax/_src/nn/linear.py +0 -0
  30. ainmax/_src/nn/misc.py +62 -0
  31. ainmax/_src/nn/normalization.py +61 -0
  32. ainmax/_src/nn/recurrent.py +7 -0
  33. ainmax/_src/partition.py +82 -0
  34. ainmax/_src/random.py +889 -0
  35. ainmax/_src/shard_map.py +172 -0
  36. ainmax/_src/sharding.py +154 -0
  37. ainmax/_src/typing.py +498 -0
  38. ainmax/_src/util.py +38 -0
  39. ainmax/feidhm/__init__.py +289 -0
  40. ainmax/feidhm/integrate.py +1 -0
  41. ainmax/feidhm/linalg.py +44 -0
  42. ainmax/feidhm/signal.py +16 -0
  43. ainmax/feidhm/special.py +57 -0
  44. ainmax/py.typed +0 -0
  45. ainmax/random.py +48 -0
  46. ainmax/sharding.py +5 -0
  47. ainmax/typing.py +38 -0
  48. ainmax-0.0.1.dist-info/METADATA +62 -0
  49. ainmax-0.0.1.dist-info/RECORD +51 -0
  50. ainmax-0.0.1.dist-info/WHEEL +4 -0
  51. ainmax-0.0.1.dist-info/licenses/LICENSE +21 -0
ainmax/__init__.py ADDED
@@ -0,0 +1,43 @@
1
+ from ainmax import feidhm as feidhm, random as random, typing as typing
2
+ from ainmax._src.axis import Axis as Axis
3
+ from ainmax._src.axis_util import (
4
+ axis_index as axis_index,
5
+ axis_indices as axis_indices,
6
+ axis_names as axis_names,
7
+ axis_selection_to_tuple as axis_selection_to_tuple,
8
+ axis_shape_to_tuple as axis_shape_to_tuple,
9
+ axis_sizes as axis_sizes,
10
+ axis_spec_to_tuple as axis_spec_to_tuple,
11
+ concatenate_axes as concatenate_axes,
12
+ intersect_axes as intersect_axes,
13
+ is_anonymous_axis as is_anonymous_axis,
14
+ is_axis_compatible as is_axis_compatible,
15
+ is_named_axis as is_named_axis,
16
+ make_axes as make_axes,
17
+ match_axes as match_axes,
18
+ remove_axes as remove_axes,
19
+ replace_axes as replace_axes,
20
+ resolve_axes as resolve_axes,
21
+ union_axes as union_axes,
22
+ )
23
+ from ainmax._src.config import (
24
+ config as config,
25
+ default_matmul_precision as default_matmul_precision,
26
+ enable_x64 as enable_x64,
27
+ numpy_dtype_promotion as numpy_dtype_promotion,
28
+ short_arrays as short_arrays,
29
+ )
30
+ from ainmax._src.filters import (
31
+ is_arrayish as is_arrayish,
32
+ is_inexact_arrayish as is_inexact_arrayish,
33
+ is_inexact_jax_array as is_inexact_jax_array,
34
+ is_inexact_jax_array_like as is_inexact_jax_array_like,
35
+ is_inexact_named_array as is_inexact_named_array,
36
+ is_jax_array as is_jax_array,
37
+ is_jax_array_like as is_jax_array_like,
38
+ is_named_array as is_named_array,
39
+ is_scalar as is_scalar,
40
+ )
41
+ from ainmax._src.hof import fold as fold, scan as scan, vmap as vmap
42
+ from ainmax._src.partition import PM as PM
43
+ from ainmax._src.typing import NamedArray as NamedArray, NamedArrayLike as NamedArrayLike
File without changes
ainmax/_src/array.py ADDED
@@ -0,0 +1,158 @@
1
+ import operator as op
2
+
3
+ import equinox as eqx
4
+ import jax.numpy as jnp
5
+ import numpy as np
6
+ import wadler_lindig as wl
7
+ from jax import Array
8
+ from jax.sharding import Sharding
9
+
10
+ from ainmax._src.axis_util import check_unique_axis_names
11
+ from ainmax._src.config import config
12
+ from ainmax._src.typing import Axis, NamedArray
13
+
14
+
15
+ def _validate_shape(array: Array, axes: tuple[Axis, ...]) -> None:
16
+ if array.ndim != len(axes):
17
+ raise ValueError(
18
+ f"Array has {array.ndim} dimensions but {len(axes)} axes were provided: {[ax.label for ax in axes]}"
19
+ )
20
+
21
+ for i, (size, ax) in enumerate(zip(array.shape, axes)):
22
+ if size != ax.size:
23
+ raise ValueError(
24
+ f"Axis {ax.label!r} at position {i} has declared size {ax.size} but array has size {size}"
25
+ )
26
+
27
+ check_unique_axis_names(axes)
28
+
29
+
30
+ class NamedArrayImpl(NamedArray, eqx.Module):
31
+ array: Array
32
+ axes: tuple[Axis, ...] = eqx.field(static=True)
33
+
34
+ def __check_init__(self):
35
+ _validate_shape(self.array, self.axes)
36
+
37
+ @property
38
+ def shape(self) -> tuple[int, ...]:
39
+ return self.array.shape
40
+
41
+ @property
42
+ def dtype(self) -> jnp.dtype:
43
+ return self.array.dtype
44
+
45
+ @property
46
+ def itemsize(self) -> int:
47
+ return self.dtype.itemsize
48
+
49
+ @property
50
+ def nbytes(self) -> int:
51
+ return self.array.nbytes
52
+
53
+ @property
54
+ def ndim(self) -> int:
55
+ return self.array.ndim
56
+
57
+ @property
58
+ def size(self) -> int:
59
+ return self.array.size
60
+
61
+ @property
62
+ def sharding(self) -> Sharding:
63
+ return self.array.sharding
64
+
65
+ def __pdoc__(self, **kwargs) -> wl.AbstractDoc:
66
+ """Wadler-Lindig pretty-printer for NamedArrayImpl.
67
+
68
+ Default (compact):
69
+ f32[x:32, y:32]
70
+
71
+ Verbose (pass ``verbose=True`` through ``wl.pdoc``/``wl.pformat`` kwargs):
72
+ NamedArray(
73
+ array=f32[32,32], axes=(Axis(name='x', size=32), Axis(name='y', size=32))
74
+ )
75
+
76
+ Handles ``array=None`` gracefully (equinox filtered/partitioned pytrees).
77
+ """
78
+ indent: int = kwargs.get("indent", 2)
79
+ short_arrays: bool = kwargs.get("short_arrays", True) and config.short_arrays
80
+ pdoc_kwargs = {"short_arrays": short_arrays, "indent": indent}
81
+
82
+ array = self.array
83
+ axes = self.axes
84
+
85
+ if not short_arrays or array is None:
86
+ return wl.bracketed(
87
+ begin=wl.TextDoc("NamedArray("),
88
+ docs=[
89
+ wl.TextDoc("array=") + wl.pdoc(array, **pdoc_kwargs),
90
+ wl.TextDoc("axes=") + wl.pdoc(axes, **pdoc_kwargs),
91
+ ],
92
+ sep=wl.comma,
93
+ end=wl.TextDoc(")"),
94
+ indent=indent,
95
+ )
96
+
97
+ # compact form: dtype[ax0_name:ax0_size, ax1_name:ax1_size, …]
98
+ dtype_str = (
99
+ str(array.dtype).replace("float", "f").replace("uint", "u").replace("int", "i").replace("complex", "c")
100
+ )
101
+
102
+ axis_docs = [wl.TextDoc(f"{ax.label}:{ax.size}") for ax in axes]
103
+
104
+ return wl.TextDoc(dtype_str) + wl.bracketed(
105
+ begin=wl.TextDoc("["),
106
+ docs=axis_docs,
107
+ sep=wl.comma,
108
+ end=wl.TextDoc("]"),
109
+ indent=indent,
110
+ )
111
+
112
+ def __len__(self):
113
+ try:
114
+ return self.shape[0]
115
+ except IndexError as err:
116
+ raise TypeError("len() of unsized object") from err # same as numpy error
117
+
118
+ def __bool__(self):
119
+ return bool(self.array)
120
+
121
+ def __float__(self):
122
+ return float(self.array)
123
+
124
+ def __int__(self):
125
+ return int(self.array)
126
+
127
+ def __complex__(self):
128
+ return complex(self.array)
129
+
130
+ def __hex__(self):
131
+ return hex(self.array)
132
+
133
+ def __oct__(self):
134
+ return oct(self.array)
135
+
136
+ def __index__(self):
137
+ return op.index(self.array)
138
+
139
+ def __repr__(self) -> str:
140
+ return wl.pformat(self)
141
+
142
+ def __str__(self) -> str:
143
+ return wl.pformat(self)
144
+
145
+ def __iter__(self):
146
+ return self.array.__iter__()
147
+
148
+ def __array__(self, dtype: np.dtype | None = None, context: None = None, copy: bool | None = None):
149
+ del context # unused
150
+
151
+ kwds = {} if copy is None else {"copy": copy}
152
+ return np.asarray(self.array, dtype=dtype, **kwds) # pyrefly: ignore[no-matching-overload]
153
+
154
+
155
+ def _short_dtype(array) -> str:
156
+ """Contract dtype the same way wl.array_summary does internally."""
157
+ s = str(array.dtype)
158
+ return s.replace("float", "f").replace("uint", "u").replace("int", "i").replace("complex", "c")
ainmax/_src/axis.py ADDED
@@ -0,0 +1,57 @@
1
+ import keyword
2
+ import re
3
+ from collections.abc import Mapping, Sequence
4
+ from dataclasses import dataclass, replace
5
+
6
+
7
+ _AXIS_NAME = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
8
+
9
+
10
+ def validate_axis_name(name) -> str:
11
+ if not isinstance(name, str):
12
+ raise TypeError(f"Axis name must be a string, got {type(name).__name__}")
13
+
14
+ if not _AXIS_NAME.fullmatch(name):
15
+ raise ValueError(f"Invalid axis name: {name!r}")
16
+
17
+ if keyword.iskeyword(name) or keyword.issoftkeyword(name):
18
+ raise ValueError(f"Axis name is a Python keyword: {name!r}")
19
+
20
+ return name
21
+
22
+
23
+ @dataclass(frozen=True, slots=True)
24
+ class Axis:
25
+ size: int
26
+ name: str | None = None
27
+
28
+ def __post_init__(self):
29
+ if isinstance(self.size, bool) or not isinstance(self.size, int):
30
+ raise TypeError(f"Axis size must be an integer, got {type(self.size).__name__}")
31
+ if self.size <= 0:
32
+ raise ValueError(f"Axis size must be positive, got {self.size}")
33
+
34
+ if self.name is not None:
35
+ validate_axis_name(self.name)
36
+
37
+ def rename(self, name: str):
38
+ return replace(self, name=name)
39
+
40
+ def resize(self, size: int):
41
+ return replace(self, size=size)
42
+
43
+ @property
44
+ def label(self) -> str:
45
+ return self.name if self.name is not None else "?"
46
+
47
+
48
+ AxisLike = str | Axis
49
+
50
+ AxisDict = Mapping[str, int]
51
+ AxisDim = int | Axis
52
+ AxisShape = AxisDim | Sequence[AxisDim] | AxisDict
53
+
54
+ AxisSpec = AxisLike | Sequence[AxisLike]
55
+
56
+ AxisSelector = int | AxisLike
57
+ AxisSelection = AxisSelector | Sequence[int | AxisLike]