Skip to content

Commit d4be973

Browse files
committed
Public API for buffer objects
This moves the public imports from buffer things out of `zarr.core`. Abstract stuff is availble under `zarr.abc.buffer`. Concrete implementations are available under `zarr.buffer.{cpu,gpu}`.
1 parent cf37198 commit d4be973

File tree

6 files changed

+49
-2
lines changed

6 files changed

+49
-2
lines changed

docs/user-guide/extending.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ Coming soon.
8383
Custom array buffers
8484
--------------------
8585

86-
Coming soon.
86+
zarr-python provides control where and how arrays stored in memory through
87+
:mod:`zarr.buffer`. Currently both CPU (the default) and GPU implementations are
88+
provided (see :ref:`user-guide-gpu` for more). You can implement your own buffer
89+
classes by implementing the interface defined in :mod:`zarr.abc.buffer`.
8790

8891
Other extensions
8992
----------------

src/zarr/abc/buffer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from zarr.core.buffer.core import ArrayLike, Buffer, BufferPrototype, NDArrayLike, NDBuffer
2+
3+
__all__ = [
4+
"ArrayLike",
5+
"Buffer",
6+
"BufferPrototype",
7+
"NDArrayLike",
8+
"NDBuffer",
9+
]

src/zarr/buffer/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
Public API for implementations of the Zarr Buffer interface.
3+
4+
See Also
5+
========
6+
arr.abc.buffer: Abstract base class for the Zarr Buffer interface.
7+
"""
8+
9+
from ..core.buffer import default_buffer_prototype
10+
from . import cpu, gpu
11+
12+
__all__ = ["cpu", "default_buffer_prototype", "gpu"]

src/zarr/buffer/cpu.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from zarr.core.buffer.cpu import (
2+
Buffer,
3+
NDBuffer,
4+
as_numpy_array_wrapper,
5+
buffer_prototype,
6+
numpy_buffer_prototype,
7+
)
8+
9+
__all__ = [
10+
"Buffer",
11+
"NDBuffer",
12+
"as_numpy_array_wrapper",
13+
"buffer_prototype",
14+
"numpy_buffer_prototype",
15+
]

src/zarr/buffer/gpu.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from zarr.core.buffer.gpu import Buffer, NDBuffer, buffer_prototype
2+
3+
__all__ = [
4+
"Buffer",
5+
"NDBuffer",
6+
"buffer_prototype",
7+
]

tests/test_buffer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import pytest
77

88
import zarr
9+
from zarr.abc.buffer import ArrayLike, BufferPrototype, NDArrayLike
10+
from zarr.buffer import cpu, gpu
911
from zarr.codecs.blosc import BloscCodec
1012
from zarr.codecs.crc32c_ import Crc32cCodec
1113
from zarr.codecs.gzip import GzipCodec
1214
from zarr.codecs.transpose import TransposeCodec
1315
from zarr.codecs.zstd import ZstdCodec
14-
from zarr.core.buffer import ArrayLike, BufferPrototype, NDArrayLike, cpu, gpu
1516
from zarr.storage import MemoryStore, StorePath
1617
from zarr.testing.buffer import (
1718
NDBufferUsingTestNDArrayLike,

0 commit comments

Comments
 (0)