Skip to content

Commit 0d74554

Browse files
committed
Add a LazyArray.to_cframe()
1 parent 0dc169f commit 0d74554

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/blosc2/lazyexpr.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,10 @@ def __array_interface__(self):
465465
"version": 3,
466466
}
467467

468+
# Provide a way to serialize the LazyArray
469+
def to_cframe(self):
470+
return self.compute().to_cframe()
471+
468472

469473
def convert_inputs(inputs):
470474
if not inputs or len(inputs) == 0:

tests/ndarray/test_lazyexpr.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,3 +1423,18 @@ def test_scalar_dtypes(values):
14231423
avalue2 = blosc2.asarray(value2) if hasattr(value2, "shape") else value2
14241424
dtype2 = (avalue1 * avalue2).dtype
14251425
assert dtype1 == dtype2, f"Expected {dtype1} but got {dtype2}"
1426+
1427+
1428+
def test_to_cframe():
1429+
N = 1_000
1430+
dtype = "float64"
1431+
a = blosc2.linspace(0, 1, N * N, dtype=dtype, shape=(N, N))
1432+
b = blosc2.linspace(1, 2, N * N, dtype=dtype, shape=(N, N))
1433+
c = blosc2.linspace(0, 1, N, dtype=dtype, shape=(N,))
1434+
expr = a**3 + blosc2.sin(a**2)
1435+
cframe = expr.to_cframe()
1436+
assert len(cframe) > 0
1437+
arr = blosc2.ndarray_from_cframe(cframe)
1438+
assert arr.shape == expr.shape
1439+
assert arr.dtype == expr.dtype
1440+
assert np.allclose(arr[:], expr[:])

0 commit comments

Comments
 (0)