decent-array 0.2.3__tar.gz → 0.2.5__tar.gz
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.
- {decent_array-0.2.3 → decent_array-0.2.5}/PKG-INFO +1 -1
- decent_array-0.2.5/decent_array/_constants.py +25 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/__init__.py +6 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_abstracts/backend.py +12 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_backend_manager.py +21 -3
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/math.py +21 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_jax/jax_backend.py +12 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_numpy/numpy_backend.py +12 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_pytorch/pytorch_backend.py +12 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_tensorflow/tensorflow_backend.py +12 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/types/_dtypes.py +3 -6
- {decent_array-0.2.3 → decent_array-0.2.5}/pyproject.toml +1 -1
- {decent_array-0.2.3 → decent_array-0.2.5}/tests/test_backend_manager.py +9 -2
- decent_array-0.2.5/tests/test_bindings.py +92 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/tests/test_iop_functions.py +15 -0
- decent_array-0.2.3/decent_array/_constants.py +0 -10
- {decent_array-0.2.3 → decent_array-0.2.5}/.github/CODEOWNERS +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/.github/dependabot.yml +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/.github/workflows/ci.yaml +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/.gitignore +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/LICENSE +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/README.md +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/benchmarks/bench_array.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/benchmarks/bench_common.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/benchmarks/bench_iop.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/benchmarks/profile_hotpath.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/__init__.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/_array.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/_errors.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/_utils.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_abstracts/__init__.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/__init__.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/bit_operators.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/comparison.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/creation.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/linalg.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/manipulations.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/operators.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/reductions.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/rng.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/utils.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_jax/__init__.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_numpy/__init__.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_pytorch/__init__.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_tensorflow/__init__.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/py.typed +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/types/__init__.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/decent_array/types/_types.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/Makefile +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/make.bat +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/requirements.txt +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/_static/custom.css +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/_static/logo.png +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/_templates/module.rst.jinja +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/_templates/package.rst.jinja +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/api/decent_array.array.rst +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/api/decent_array.interoperability.rst +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/api/decent_array.rst +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/api/decent_array.types.rst +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/author.rst +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/conf.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/developer.rst +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/index.rst +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/docs/source/user.rst +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/readthedocs.yaml +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/tests/conftest.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/tests/test_array.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/tests/test_dtypes.py +0 -0
- {decent_array-0.2.3 → decent_array-0.2.5}/tests/test_iop_rng.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: decent-array
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
4
4
|
Summary: A library of array operations and linear algebra primitives for interoperability across ML frameworks.
|
|
5
5
|
Project-URL: Documentation, https://decent-array.readthedocs.io/en/latest/
|
|
6
6
|
Project-URL: Source, https://github.com/team-decent/decent-array
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Numerical constants."""
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
_CONSTANTS = {
|
|
6
|
+
"e": math.e,
|
|
7
|
+
"inf": math.inf,
|
|
8
|
+
"nan": math.nan,
|
|
9
|
+
"pi": math.pi,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
e = _CONSTANTS["e"]
|
|
13
|
+
inf = _CONSTANTS["inf"]
|
|
14
|
+
nan = _CONSTANTS["nan"]
|
|
15
|
+
pi = _CONSTANTS["pi"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _reset() -> None:
|
|
19
|
+
"""Set/reset constants to the Python math defaults."""
|
|
20
|
+
global e, inf, nan, pi # noqa: PLW0603
|
|
21
|
+
|
|
22
|
+
e = _CONSTANTS["e"]
|
|
23
|
+
inf = _CONSTANTS["inf"]
|
|
24
|
+
nan = _CONSTANTS["nan"]
|
|
25
|
+
pi = _CONSTANTS["pi"]
|
|
@@ -50,6 +50,9 @@ from ._iop.math import (
|
|
|
50
50
|
add,
|
|
51
51
|
divide,
|
|
52
52
|
floor_divide,
|
|
53
|
+
isfinite,
|
|
54
|
+
isinf,
|
|
55
|
+
isnan,
|
|
53
56
|
multiply,
|
|
54
57
|
negative,
|
|
55
58
|
positive,
|
|
@@ -111,6 +114,9 @@ __all__ = [
|
|
|
111
114
|
"get_seed",
|
|
112
115
|
"greater",
|
|
113
116
|
"greater_equal",
|
|
117
|
+
"isfinite",
|
|
118
|
+
"isinf",
|
|
119
|
+
"isnan",
|
|
114
120
|
"less",
|
|
115
121
|
"less_equal",
|
|
116
122
|
"matmul",
|
{decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_abstracts/backend.py
RENAMED
|
@@ -270,6 +270,18 @@ class Backend(ABC):
|
|
|
270
270
|
def sqrt(self, x: Array) -> Array:
|
|
271
271
|
"""Element-wise square root."""
|
|
272
272
|
|
|
273
|
+
@abstractmethod
|
|
274
|
+
def isfinite(self, x: Array) -> Array:
|
|
275
|
+
"""Element-wise test for finite values."""
|
|
276
|
+
|
|
277
|
+
@abstractmethod
|
|
278
|
+
def isinf(self, x: Array) -> Array:
|
|
279
|
+
"""Element-wise test for infinite values."""
|
|
280
|
+
|
|
281
|
+
@abstractmethod
|
|
282
|
+
def isnan(self, x: Array) -> Array:
|
|
283
|
+
"""Element-wise test for NaN values."""
|
|
284
|
+
|
|
273
285
|
# Comparisons — both operands may be Array or scalar.
|
|
274
286
|
|
|
275
287
|
@abstractmethod
|
|
@@ -131,6 +131,17 @@ def reset_backends() -> None:
|
|
|
131
131
|
for listener in _BACKEND_LISTENERS:
|
|
132
132
|
listener(None)
|
|
133
133
|
|
|
134
|
+
# clear dtypes bindings
|
|
135
|
+
for dt in dtypes._ALL_DTYPES: # noqa: SLF001
|
|
136
|
+
dt._available = False # noqa: SLF001
|
|
137
|
+
dt._backend_dtype = None # noqa: SLF001
|
|
138
|
+
|
|
139
|
+
dtypes._AVAILABLE_DTYPES.clear() # noqa: SLF001
|
|
140
|
+
dtypes._BACKEND_DTYPE_TO_DTYPE.clear() # noqa: SLF001
|
|
141
|
+
|
|
142
|
+
# clear constants bindings, restoring to Python math defaults
|
|
143
|
+
constants._reset() # noqa: SLF001
|
|
144
|
+
|
|
134
145
|
|
|
135
146
|
def default_device() -> Devices:
|
|
136
147
|
"""
|
|
@@ -219,6 +230,14 @@ def _bind_dtypes(backend: Backend | None) -> None:
|
|
|
219
230
|
dt._available = backend_dt is not None # noqa: SLF001
|
|
220
231
|
dt._backend_dtype = backend_dt # noqa: SLF001
|
|
221
232
|
|
|
233
|
+
# refresh caches of available dtypes and reverse mapping
|
|
234
|
+
dtypes._AVAILABLE_DTYPES.clear() # noqa: SLF001
|
|
235
|
+
dtypes._AVAILABLE_DTYPES.update(dt for dt in dtypes._ALL_DTYPES if dt.available) # noqa: SLF001
|
|
236
|
+
|
|
237
|
+
dtypes._BACKEND_DTYPE_TO_DTYPE.clear() # noqa: SLF001
|
|
238
|
+
for dt in dtypes._AVAILABLE_DTYPES: # noqa: SLF001
|
|
239
|
+
dtypes._BACKEND_DTYPE_TO_DTYPE[dt.backend_dtype] = dt # noqa: SLF001
|
|
240
|
+
|
|
222
241
|
|
|
223
242
|
def _bind_constants(backend: Backend | None) -> None:
|
|
224
243
|
"""Bind constants to the corresponding backend constants."""
|
|
@@ -226,6 +245,5 @@ def _bind_constants(backend: Backend | None) -> None:
|
|
|
226
245
|
return
|
|
227
246
|
for name in constants._CONSTANTS: # noqa: SLF001
|
|
228
247
|
backend_c = getattr(backend, name, None)
|
|
229
|
-
if backend_c is None:
|
|
230
|
-
|
|
231
|
-
setattr(constants, name, backend_c)
|
|
248
|
+
if backend_c is not None:
|
|
249
|
+
setattr(constants, name, backend_c)
|
|
@@ -147,3 +147,24 @@ def sqrt(x: Array) -> Array:
|
|
|
147
147
|
if _BACKEND_INSTANCE is None:
|
|
148
148
|
raise no_backend_error
|
|
149
149
|
return _BACKEND_INSTANCE.sqrt(x)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def isfinite(x: Array) -> Array:
|
|
153
|
+
"""Element-wise test for finite values."""
|
|
154
|
+
if _BACKEND_INSTANCE is None:
|
|
155
|
+
raise no_backend_error
|
|
156
|
+
return _BACKEND_INSTANCE.isfinite(x)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def isinf(x: Array) -> Array:
|
|
160
|
+
"""Element-wise test for infinite values."""
|
|
161
|
+
if _BACKEND_INSTANCE is None:
|
|
162
|
+
raise no_backend_error
|
|
163
|
+
return _BACKEND_INSTANCE.isinf(x)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def isnan(x: Array) -> Array:
|
|
167
|
+
"""Element-wise test for NaN values."""
|
|
168
|
+
if _BACKEND_INSTANCE is None:
|
|
169
|
+
raise no_backend_error
|
|
170
|
+
return _BACKEND_INSTANCE.isnan(x)
|
|
@@ -255,6 +255,18 @@ class JaxBackend(Backend):
|
|
|
255
255
|
def sqrt(self, x: Array) -> Array:
|
|
256
256
|
return Array(jnp.sqrt(x.value))
|
|
257
257
|
|
|
258
|
+
def isfinite(self, x: Array) -> Array:
|
|
259
|
+
"""Element-wise test for finite values."""
|
|
260
|
+
return Array(jnp.isfinite(x.value))
|
|
261
|
+
|
|
262
|
+
def isinf(self, x: Array) -> Array:
|
|
263
|
+
"""Element-wise test for infinite values."""
|
|
264
|
+
return Array(jnp.isinf(x.value))
|
|
265
|
+
|
|
266
|
+
def isnan(self, x: Array) -> Array:
|
|
267
|
+
"""Element-wise test for NaN values."""
|
|
268
|
+
return Array(jnp.isnan(x.value))
|
|
269
|
+
|
|
258
270
|
# Comparisons
|
|
259
271
|
|
|
260
272
|
def equal(self, x1: int | float | complex | Array, x2: int | float | complex | Array) -> Array:
|
{decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_numpy/numpy_backend.py
RENAMED
|
@@ -267,6 +267,18 @@ class NumpyBackend(Backend):
|
|
|
267
267
|
def sqrt(self, x: Array) -> Array:
|
|
268
268
|
return Array(np.sqrt(x.value))
|
|
269
269
|
|
|
270
|
+
def isfinite(self, x: Array) -> Array:
|
|
271
|
+
"""Element-wise test for finite values."""
|
|
272
|
+
return Array(np.isfinite(x.value))
|
|
273
|
+
|
|
274
|
+
def isinf(self, x: Array) -> Array:
|
|
275
|
+
"""Element-wise test for infinite values."""
|
|
276
|
+
return Array(np.isinf(x.value))
|
|
277
|
+
|
|
278
|
+
def isnan(self, x: Array) -> Array:
|
|
279
|
+
"""Element-wise test for NaN values."""
|
|
280
|
+
return Array(np.isnan(x.value))
|
|
281
|
+
|
|
270
282
|
# Comparisons
|
|
271
283
|
|
|
272
284
|
def equal(self, x1: int | float | complex | Array, x2: int | float | complex | Array) -> Array:
|
{decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_pytorch/pytorch_backend.py
RENAMED
|
@@ -268,6 +268,18 @@ class PyTorchBackend(Backend):
|
|
|
268
268
|
def sqrt(self, x: Array) -> Array:
|
|
269
269
|
return Array(torch.sqrt(x.value))
|
|
270
270
|
|
|
271
|
+
def isfinite(self, x: Array) -> Array:
|
|
272
|
+
"""Element-wise test for finite values."""
|
|
273
|
+
return Array(torch.isfinite(x.value))
|
|
274
|
+
|
|
275
|
+
def isinf(self, x: Array) -> Array:
|
|
276
|
+
"""Element-wise test for infinite values."""
|
|
277
|
+
return Array(torch.isinf(x.value))
|
|
278
|
+
|
|
279
|
+
def isnan(self, x: Array) -> Array:
|
|
280
|
+
"""Element-wise test for NaN values."""
|
|
281
|
+
return Array(torch.isnan(x.value))
|
|
282
|
+
|
|
271
283
|
# Comparisons
|
|
272
284
|
|
|
273
285
|
def equal(self, x1: int | float | complex | Array, x2: int | float | complex | Array) -> Array:
|
|
@@ -278,6 +278,18 @@ class TensorflowBackend(Backend):
|
|
|
278
278
|
def sqrt(self, x: Array) -> Array:
|
|
279
279
|
return Array(tf.sqrt(x.value))
|
|
280
280
|
|
|
281
|
+
def isfinite(self, x: Array) -> Array:
|
|
282
|
+
"""Element-wise test for finite values."""
|
|
283
|
+
return Array(tf.math.is_finite(x.value))
|
|
284
|
+
|
|
285
|
+
def isinf(self, x: Array) -> Array:
|
|
286
|
+
"""Element-wise test for infinite values."""
|
|
287
|
+
return Array(tf.math.is_inf(x.value))
|
|
288
|
+
|
|
289
|
+
def isnan(self, x: Array) -> Array:
|
|
290
|
+
"""Element-wise test for NaN values."""
|
|
291
|
+
return Array(tf.math.is_nan(x.value))
|
|
292
|
+
|
|
281
293
|
# Comparisons
|
|
282
294
|
|
|
283
295
|
def equal(self, x1: int | float | complex | Array, x2: int | float | complex | Array) -> Array:
|
|
@@ -74,7 +74,7 @@ class dtype: # noqa: N801
|
|
|
74
74
|
"""Check equivalence by ``name`` attributes."""
|
|
75
75
|
if not isinstance(other, dtype):
|
|
76
76
|
return NotImplemented
|
|
77
|
-
return self.name == other.name
|
|
77
|
+
return self.name == other.name
|
|
78
78
|
|
|
79
79
|
def __hash__(self) -> int:
|
|
80
80
|
"""Hash of the dtype."""
|
|
@@ -131,12 +131,9 @@ _NUMERIC_DTYPES = _INTEGRAL_DTYPES | _REAL_FLOATING_DTYPES | _COMPLEX_FLOATING_D
|
|
|
131
131
|
_ALL_DTYPES = _BOOL_DTYPES | _NUMERIC_DTYPES | _MISCELLANEOUS_DTYPES
|
|
132
132
|
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
134
|
+
# caches for available dtypes and reverse mapping; these are populated during set_backend
|
|
135
|
+
_AVAILABLE_DTYPES: set[dtype] = set()
|
|
137
136
|
_BACKEND_DTYPE_TO_DTYPE: dict[Any, dtype] = {}
|
|
138
|
-
for dt in _AVAILABLE_DTYPES:
|
|
139
|
-
_BACKEND_DTYPE_TO_DTYPE[dt._backend_dtype] = dt # noqa: SLF001
|
|
140
137
|
|
|
141
138
|
|
|
142
139
|
_ALIASES = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "decent-array"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.5"
|
|
4
4
|
authors = [{name = "Simon Granström"}, {name = "Nicola Bastianello"}]
|
|
5
5
|
maintainers = [{name = "Team Decent"}]
|
|
6
6
|
description = "A library of array operations and linear algebra primitives for interoperability across ML frameworks."
|
|
@@ -98,8 +98,15 @@ def test_set_backend_instantiates_dtypes() -> None:
|
|
|
98
98
|
dt2 = float32 # global dtype bound during set_dtype
|
|
99
99
|
dt3 = dtype("float32") # backend is set, so this is bound to backend dtype
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
assert
|
|
101
|
+
# check availability status
|
|
102
|
+
assert not dt1.available
|
|
103
|
+
assert dt2.available
|
|
104
|
+
assert dt3.available
|
|
105
|
+
|
|
106
|
+
# equality check the name attribute, so all these should be true (irrespective of availability)
|
|
107
|
+
assert dt1 == dt2
|
|
108
|
+
assert dt1 == dt3
|
|
109
|
+
assert dt2 == dt3
|
|
103
110
|
|
|
104
111
|
dt4 = dtype("int16")
|
|
105
112
|
assert dt3 != dt4
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Tests for dtype initialization and backend binding."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import math
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
from decent_array.interoperability import _backend_manager
|
|
9
|
+
from decent_array.interoperability._backend_manager import reset_backends
|
|
10
|
+
from decent_array.types import _dtypes
|
|
11
|
+
import decent_array._constants as constants
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.fixture(autouse=True)
|
|
15
|
+
def reset_backend_state():
|
|
16
|
+
"""Reset backend state before and after each test."""
|
|
17
|
+
reset_backends()
|
|
18
|
+
yield
|
|
19
|
+
reset_backends()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_all_dtypes_are_bound_to_backend(backend: tuple) -> None:
|
|
23
|
+
"""Every dtype is bound to the corresponding backend attribute."""
|
|
24
|
+
backend_instance = _backend_manager._BACKEND_INSTANCE
|
|
25
|
+
|
|
26
|
+
assert backend_instance is not None
|
|
27
|
+
|
|
28
|
+
for name in _dtypes._SUPPORTED:
|
|
29
|
+
dt = getattr(_dtypes, name)
|
|
30
|
+
expected_backend_dtype = getattr(backend_instance, name, None)
|
|
31
|
+
|
|
32
|
+
assert dt.backend_dtype is expected_backend_dtype
|
|
33
|
+
assert dt.available is (expected_backend_dtype is not None)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_available_dtypes_cache_is_correct(backend: tuple) -> None:
|
|
37
|
+
expected = {
|
|
38
|
+
dt for dt in _dtypes._ALL_DTYPES if dt.available
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
assert _dtypes._AVAILABLE_DTYPES == expected
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_dtypes_returns_only_available_dtypes(backend: tuple) -> None:
|
|
45
|
+
available = _dtypes.dtypes()
|
|
46
|
+
|
|
47
|
+
assert available
|
|
48
|
+
assert all(dt.available for dt in available.values())
|
|
49
|
+
assert set(available.values()) == _dtypes._AVAILABLE_DTYPES
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_backend_dtype_mapping_is_correct(backend: tuple) -> None:
|
|
53
|
+
expected = {
|
|
54
|
+
dt.backend_dtype: dt
|
|
55
|
+
for dt in _dtypes._AVAILABLE_DTYPES
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
assert _dtypes._BACKEND_DTYPE_TO_DTYPE == expected
|
|
59
|
+
|
|
60
|
+
for dt in _dtypes._AVAILABLE_DTYPES:
|
|
61
|
+
assert (
|
|
62
|
+
_dtypes._BACKEND_DTYPE_TO_DTYPE[dt.backend_dtype]
|
|
63
|
+
is dt
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_reset_clears_dtype_bindings(backend: tuple) -> None:
|
|
68
|
+
"""Resetting backends clears dtype bindings and caches."""
|
|
69
|
+
assert _backend_manager._BACKEND_INSTANCE is not None
|
|
70
|
+
assert _dtypes._AVAILABLE_DTYPES
|
|
71
|
+
|
|
72
|
+
reset_backends()
|
|
73
|
+
|
|
74
|
+
assert _backend_manager._BACKEND_INSTANCE is None
|
|
75
|
+
assert not _dtypes._AVAILABLE_DTYPES
|
|
76
|
+
assert not _dtypes._BACKEND_DTYPE_TO_DTYPE
|
|
77
|
+
|
|
78
|
+
for dt in _dtypes._ALL_DTYPES:
|
|
79
|
+
assert dt.available is False
|
|
80
|
+
assert dt.backend_dtype is None
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def test_reset_restores_default_constants(backend: tuple) -> None:
|
|
84
|
+
"""Resetting the backend restores Python math defaults."""
|
|
85
|
+
assert _backend_manager._BACKEND_INSTANCE is not None
|
|
86
|
+
|
|
87
|
+
reset_backends()
|
|
88
|
+
|
|
89
|
+
assert constants.e == math.e
|
|
90
|
+
assert constants.inf == math.inf
|
|
91
|
+
assert math.isnan(constants.nan)
|
|
92
|
+
assert constants.pi == math.pi
|
|
@@ -478,6 +478,21 @@ def test_sqrt(backend: tuple) -> None:
|
|
|
478
478
|
np.testing.assert_allclose(_np(iop.sqrt(arr)), [1.0, 2.0, 3.0])
|
|
479
479
|
|
|
480
480
|
|
|
481
|
+
def test_isfinite(backend: tuple) -> None:
|
|
482
|
+
arr = iop.from_numpy(np.array([1.0, np.inf, -np.inf, np.nan], dtype=np.float32))
|
|
483
|
+
np.testing.assert_array_equal(_np(iop.isfinite(arr)), [True, False, False, False])
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def test_isinf(backend: tuple) -> None:
|
|
487
|
+
arr = iop.from_numpy(np.array([1.0, np.inf, -np.inf, np.nan], dtype=np.float32))
|
|
488
|
+
np.testing.assert_array_equal(_np(iop.isinf(arr)), [False, True, True, False])
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
def test_isnan(backend: tuple) -> None:
|
|
492
|
+
arr = iop.from_numpy(np.array([1.0, np.inf, -np.inf, np.nan], dtype=np.float32))
|
|
493
|
+
np.testing.assert_array_equal(_np(iop.isnan(arr)), [False, False, False, True])
|
|
494
|
+
|
|
495
|
+
|
|
481
496
|
# Operators --------------------------------------------------------------
|
|
482
497
|
|
|
483
498
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_abstracts/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/bit_operators.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_iop/manipulations.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_pytorch/__init__.py
RENAMED
|
File without changes
|
{decent_array-0.2.3 → decent_array-0.2.5}/decent_array/interoperability/_tensorflow/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|