Skip to content

Public API for buffer objects #2876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/2871.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add public :mod:`zarr.buffer` API for controlling how data is stored in memory.
5 changes: 4 additions & 1 deletion docs/user-guide/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ Coming soon.
Custom array buffers
--------------------

Coming soon.
zarr-python provides control where and how arrays stored in memory through
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
zarr-python provides control where and how arrays stored in memory through
Zarr-Python provides control for where and how arrays stored in memory through

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're inconsistent about zarr-python vs. Zarr-python in the docs.

:mod:`zarr.buffer`. Currently both CPU (the default) and GPU implementations are
provided (see :ref:`user-guide-gpu` for more). You can implement your own buffer
classes by implementing the interface defined in :mod:`zarr.abc.buffer`.

Other extensions
----------------
Expand Down
9 changes: 9 additions & 0 deletions src/zarr/abc/buffer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from zarr.core.buffer.core import ArrayLike, Buffer, BufferPrototype, NDArrayLike, NDBuffer

__all__ = [
"ArrayLike",
"Buffer",
"BufferPrototype",
"NDArrayLike",
"NDBuffer",
]
12 changes: 12 additions & 0 deletions src/zarr/buffer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Public API for implementations of the Zarr Buffer interface.
See Also
========
arr.abc.buffer: Abstract base class for the Zarr Buffer interface.
"""

from ..core.buffer import default_buffer_prototype
from . import cpu, gpu

__all__ = ["cpu", "default_buffer_prototype", "gpu"]
15 changes: 15 additions & 0 deletions src/zarr/buffer/cpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from zarr.core.buffer.cpu import (
Buffer,
NDBuffer,
as_numpy_array_wrapper,
buffer_prototype,
numpy_buffer_prototype,
)

__all__ = [
"Buffer",
"NDBuffer",
"as_numpy_array_wrapper",
"buffer_prototype",
"numpy_buffer_prototype",
]
7 changes: 7 additions & 0 deletions src/zarr/buffer/gpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from zarr.core.buffer.gpu import Buffer, NDBuffer, buffer_prototype

__all__ = [
"Buffer",
"NDBuffer",
"buffer_prototype",
]
3 changes: 2 additions & 1 deletion tests/test_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import pytest

import zarr
from zarr.abc.buffer import ArrayLike, BufferPrototype, NDArrayLike
from zarr.buffer import cpu, gpu
from zarr.codecs.blosc import BloscCodec
from zarr.codecs.crc32c_ import Crc32cCodec
from zarr.codecs.gzip import GzipCodec
from zarr.codecs.transpose import TransposeCodec
from zarr.codecs.zstd import ZstdCodec
from zarr.core.buffer import ArrayLike, BufferPrototype, NDArrayLike, cpu, gpu
from zarr.storage import MemoryStore, StorePath
from zarr.testing.buffer import (
NDBufferUsingTestNDArrayLike,
Expand Down