arraybridge 0.3.0__py3-none-any.whl → 0.3.2__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.
- arraybridge/__init__.py +3 -1
- arraybridge/array_geometry.py +57 -0
- arraybridge/decorators.py +3 -2
- {arraybridge-0.3.0.dist-info → arraybridge-0.3.2.dist-info}/METADATA +2 -1
- {arraybridge-0.3.0.dist-info → arraybridge-0.3.2.dist-info}/RECORD +7 -6
- {arraybridge-0.3.0.dist-info → arraybridge-0.3.2.dist-info}/WHEEL +0 -0
- {arraybridge-0.3.0.dist-info → arraybridge-0.3.2.dist-info}/licenses/LICENSE +0 -0
arraybridge/__init__.py
CHANGED
|
@@ -5,9 +5,10 @@ This package provides automatic memory type conversion, declarative decorators,
|
|
|
5
5
|
and unified utilities for working with multiple array/tensor frameworks.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
__version__ = "0.3.
|
|
8
|
+
__version__ = "0.3.2"
|
|
9
9
|
|
|
10
10
|
from . import decorators as _decorators
|
|
11
|
+
from .array_geometry import ArrayGeometry
|
|
11
12
|
from .array_payload import ArrayPayload
|
|
12
13
|
from .converters import convert_memory, detect_memory_type
|
|
13
14
|
from .dtype_scaling import SCALING_FUNCTIONS
|
|
@@ -39,6 +40,7 @@ __all__ = [
|
|
|
39
40
|
"MemoryType",
|
|
40
41
|
"MemoryContractAttribute",
|
|
41
42
|
"ArrayPayload",
|
|
43
|
+
"ArrayGeometry",
|
|
42
44
|
"CPU_MEMORY_TYPES",
|
|
43
45
|
"GPU_MEMORY_TYPES",
|
|
44
46
|
"SUPPORTED_MEMORY_TYPES",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Framework-neutral array geometry inspection."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import numpy as np
|
|
9
|
+
|
|
10
|
+
from arraybridge.array_payload import ArrayPayload
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True, slots=True)
|
|
14
|
+
class ArrayGeometry:
|
|
15
|
+
"""Concrete shape metadata without moving array data between frameworks."""
|
|
16
|
+
|
|
17
|
+
shape: tuple[int, ...]
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def ndim(self) -> int:
|
|
21
|
+
"""Return the rank derived from the canonical shape."""
|
|
22
|
+
|
|
23
|
+
return len(self.shape)
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def from_value(cls, value: Any) -> ArrayGeometry | None:
|
|
27
|
+
"""Inspect an array or nominal payload without forcing host conversion."""
|
|
28
|
+
|
|
29
|
+
data = value.array_payload_data() if isinstance(value, ArrayPayload) else value
|
|
30
|
+
declared_shape = getattr(data, "shape", None)
|
|
31
|
+
if declared_shape is not None:
|
|
32
|
+
try:
|
|
33
|
+
return cls(tuple(int(axis_size) for axis_size in declared_shape))
|
|
34
|
+
except (TypeError, ValueError):
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
array = np.asarray(data)
|
|
39
|
+
except (TypeError, ValueError):
|
|
40
|
+
return None
|
|
41
|
+
return cls(tuple(int(axis_size) for axis_size in array.shape))
|
|
42
|
+
|
|
43
|
+
@classmethod
|
|
44
|
+
def require_from_value(
|
|
45
|
+
cls,
|
|
46
|
+
value: Any,
|
|
47
|
+
*,
|
|
48
|
+
value_name: str = "Value",
|
|
49
|
+
) -> ArrayGeometry:
|
|
50
|
+
"""Return concrete geometry or reject a value without an array shape."""
|
|
51
|
+
|
|
52
|
+
geometry = cls.from_value(value)
|
|
53
|
+
if geometry is None:
|
|
54
|
+
raise TypeError(
|
|
55
|
+
f"{value_name} requires concrete array geometry, got " f"{type(value).__name__}."
|
|
56
|
+
)
|
|
57
|
+
return geometry
|
arraybridge/decorators.py
CHANGED
|
@@ -23,6 +23,7 @@ from typing import Any, ClassVar, TypeVar, cast
|
|
|
23
23
|
|
|
24
24
|
import numpy as np
|
|
25
25
|
from metaclass_registry import AutoRegisterMeta, RegistryFamily, RegistryKeyAttribute
|
|
26
|
+
from python_introspect import RuntimeParameterDeclarationABC
|
|
26
27
|
|
|
27
28
|
from arraybridge.array_payload import ArrayPayload
|
|
28
29
|
from arraybridge.oom_recovery import _execute_with_oom_recovery
|
|
@@ -60,7 +61,7 @@ class DtypeConversion(Enum):
|
|
|
60
61
|
return dtype_map.get(self, None)
|
|
61
62
|
|
|
62
63
|
|
|
63
|
-
class DtypeConversionConfig(
|
|
64
|
+
class DtypeConversionConfig(RuntimeParameterDeclarationABC):
|
|
64
65
|
"""Nominal dtype conversion config surface consumed by decorators."""
|
|
65
66
|
|
|
66
67
|
@property
|
|
@@ -90,7 +91,7 @@ class DtypeConversionConfig(ABC):
|
|
|
90
91
|
)
|
|
91
92
|
|
|
92
93
|
|
|
93
|
-
class SliceBySliceRuntimeParameter:
|
|
94
|
+
class SliceBySliceRuntimeParameter(RuntimeParameterDeclarationABC):
|
|
94
95
|
"""Nominal slice-by-slice execution parameter consumed by decorators."""
|
|
95
96
|
|
|
96
97
|
preserve_for_execution = True
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: arraybridge
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Unified API for NumPy, CuPy, PyTorch, TensorFlow, JAX, and pyclesperanto with automatic memory type conversion
|
|
5
5
|
Project-URL: Homepage, https://github.com/OpenHCSDev/arraybridge
|
|
6
6
|
Project-URL: Documentation, https://arraybridge.readthedocs.io
|
|
@@ -23,6 +23,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
|
23
23
|
Requires-Python: >=3.10
|
|
24
24
|
Requires-Dist: metaclass-registry>=0.1.5
|
|
25
25
|
Requires-Dist: numpy>=1.20
|
|
26
|
+
Requires-Dist: python-introspect>=0.1.11
|
|
26
27
|
Provides-Extra: all
|
|
27
28
|
Requires-Dist: cupy>=10.0; extra == 'all'
|
|
28
29
|
Requires-Dist: jax>=0.3; extra == 'all'
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
arraybridge/__init__.py,sha256=
|
|
1
|
+
arraybridge/__init__.py,sha256=xFy8ESRzsIy8ydjdPQs33C5Ed6HH6YUsn65HSmQTtzM,2326
|
|
2
|
+
arraybridge/array_geometry.py,sha256=CopfGmFVKwV5l-lOTImhm1YVh18weUng0ReEF58qlPI,1689
|
|
2
3
|
arraybridge/array_operations.py,sha256=fp69o9BYcCzfhmLcWrH68SVGSfPL3nb6Cty-Amd_oQM,13082
|
|
3
4
|
arraybridge/array_payload.py,sha256=6_jJwPRya0MHrUNSA9kXPlTISpLa0G74rqDValGXKx4,1079
|
|
4
5
|
arraybridge/converters.py,sha256=q44E6Pg1rJz8yq6WQIPLOZPv1lqqcUcEG4Gh4D5M1_o,2649
|
|
5
6
|
arraybridge/converters_registry.py,sha256=_hHtbd-3SMIKUw8fvNu3twPWJY7qHyNyQ_NhVp3eSHQ,5647
|
|
6
|
-
arraybridge/decorators.py,sha256=
|
|
7
|
+
arraybridge/decorators.py,sha256=mYIxBbCuWQVN8dhAE2M7i2Yo0KbcMyY4MZmsfGXGm-0,19975
|
|
7
8
|
arraybridge/dtype_scaling.py,sha256=KDgYyCvxgsQXLJJl_bs5nH46zQimsA7c1Olv6xJ2z1o,831
|
|
8
9
|
arraybridge/exceptions.py,sha256=fhej5ZS39QcBFWzNeNYjoqeLVnOgwwp-cWIme25jyuo,752
|
|
9
10
|
arraybridge/framework_config.py,sha256=5yTTt9NWcwzKDMXbc-fqCdiFl-piKOt3SUnxmRXXCQk,744
|
|
@@ -14,7 +15,7 @@ arraybridge/slice_processing.py,sha256=5R10OmHW8BSbJFwT1URd2Sz3P15o5EhaI2VnVUUIv
|
|
|
14
15
|
arraybridge/stack_utils.py,sha256=FVikN0XG-Xryw-1p9MaSRUTZet7kLcy0gTEERSjc9r4,6915
|
|
15
16
|
arraybridge/types.py,sha256=1otpHqFJfGc9RY40VCzNCkqpTnR8cfckhY44HnuGudI,33191
|
|
16
17
|
arraybridge/utils.py,sha256=RqThtYScPEOEQG491dA8b_VvUTjgcFhwLbh0erQu5Ns,4833
|
|
17
|
-
arraybridge-0.3.
|
|
18
|
-
arraybridge-0.3.
|
|
19
|
-
arraybridge-0.3.
|
|
20
|
-
arraybridge-0.3.
|
|
18
|
+
arraybridge-0.3.2.dist-info/METADATA,sha256=tX2dNiYptc7DpXQUqV8x5BX5RzVSMLOD9wM-4xQmg5o,5275
|
|
19
|
+
arraybridge-0.3.2.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
20
|
+
arraybridge-0.3.2.dist-info/licenses/LICENSE,sha256=xagEoeTAj1WT64RmyR3E6HH-eTGdgXN6gqPMUUt7L_Y,1070
|
|
21
|
+
arraybridge-0.3.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|