1111import numpy as np
1212import numpy .typing as npt
1313
14- from zarr .core .buffer import core
15- from zarr .core .buffer .core import ArrayLike , BufferPrototype , NDArrayLike
14+ import zarr .abc .buffer
1615
1716if TYPE_CHECKING :
1817 from collections .abc import Iterable
2625 cp = None
2726
2827
29- class Buffer (core .Buffer ):
28+ class Buffer (zarr . abc . buffer .Buffer ):
3029 """A flat contiguous memory block on the GPU
3130
3231 We use Buffer throughout Zarr to represent a contiguous block of memory.
@@ -47,7 +46,7 @@ class Buffer(core.Buffer):
4746 array-like object that must be 1-dim, contiguous, and byte dtype.
4847 """
4948
50- def __init__ (self , array_like : ArrayLike ) -> None :
49+ def __init__ (self , array_like : zarr . abc . buffer . ArrayLike ) -> None :
5150 if cp is None :
5251 raise ImportError (
5352 "Cannot use zarr.buffer.gpu.Buffer without cupy. Please install cupy."
@@ -83,7 +82,7 @@ def create_zero_length(cls) -> Self:
8382 return cls (cp .array ([], dtype = "b" ))
8483
8584 @classmethod
86- def from_buffer (cls , buffer : core .Buffer ) -> Self :
85+ def from_buffer (cls , buffer : zarr . abc . buffer .Buffer ) -> Self :
8786 """Create an GPU Buffer given an arbitrary Buffer
8887 This will try to be zero-copy if `buffer` is already on the
8988 GPU and will trigger a copy if not.
@@ -101,7 +100,7 @@ def from_bytes(cls, bytes_like: BytesLike) -> Self:
101100 def as_numpy_array (self ) -> npt .NDArray [Any ]:
102101 return cast (npt .NDArray [Any ], cp .asnumpy (self ._data ))
103102
104- def __add__ (self , other : core .Buffer ) -> Self :
103+ def __add__ (self , other : zarr . abc . buffer .Buffer ) -> Self :
105104 other_array = other .as_array_like ()
106105 assert other_array .dtype == np .dtype ("b" )
107106 gpu_other = Buffer (other_array )
@@ -111,7 +110,7 @@ def __add__(self, other: core.Buffer) -> Self:
111110 )
112111
113112
114- class NDBuffer (core .NDBuffer ):
113+ class NDBuffer (zarr . abc . buffer .NDBuffer ):
115114 """A n-dimensional memory block on the GPU
116115
117116 We use NDBuffer throughout Zarr to represent a n-dimensional memory block.
@@ -136,7 +135,7 @@ class NDBuffer(core.NDBuffer):
136135 ndarray-like object that is convertible to a regular Numpy array.
137136 """
138137
139- def __init__ (self , array : NDArrayLike ) -> None :
138+ def __init__ (self , array : zarr . abc . buffer . NDArrayLike ) -> None :
140139 if cp is None :
141140 raise ImportError (
142141 "Cannot use zarr.buffer.gpu.NDBuffer without cupy. Please install cupy."
@@ -208,10 +207,10 @@ def __getitem__(self, key: Any) -> Self:
208207 def __setitem__ (self , key : Any , value : Any ) -> None :
209208 if isinstance (value , NDBuffer ):
210209 value = value ._data
211- elif isinstance (value , core .NDBuffer ):
210+ elif isinstance (value , zarr . abc . buffer .NDBuffer ):
212211 gpu_value = NDBuffer (value .as_ndarray_like ())
213212 value = gpu_value ._data
214213 self ._data .__setitem__ (key , value )
215214
216215
217- buffer_prototype = BufferPrototype (buffer = Buffer , nd_buffer = NDBuffer )
216+ buffer_prototype = zarr . abc . buffer . BufferPrototype (buffer = Buffer , nd_buffer = NDBuffer )
0 commit comments