|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -from typing import TYPE_CHECKING |
| 3 | +from typing import TYPE_CHECKING, Literal |
4 | 4 |
|
5 | 5 | import numpy as np
|
6 | 6 | import pytest
|
|
20 | 20 | TestBuffer,
|
21 | 21 | TestNDArrayLike,
|
22 | 22 | )
|
23 |
| -from zarr.testing.utils import gpu_test |
| 23 | +from zarr.testing.utils import gpu_mark, gpu_test, skip_if_no_gpu |
24 | 24 |
|
25 | 25 | if TYPE_CHECKING:
|
26 | 26 | import types
|
@@ -200,3 +200,39 @@ def test_gpu_buffer_prototype() -> None:
|
200 | 200 | def test_cpu_buffer_as_scalar() -> None:
|
201 | 201 | buf = cpu.buffer_prototype.nd_buffer.create(shape=(), dtype="int64")
|
202 | 202 | assert buf.as_scalar() == buf.as_ndarray_like()[()] # type: ignore[index]
|
| 203 | + |
| 204 | + |
| 205 | +@pytest.mark.parametrize( |
| 206 | + "prototype", |
| 207 | + [ |
| 208 | + cpu.buffer_prototype, |
| 209 | + pytest.param( |
| 210 | + gpu.buffer_prototype, |
| 211 | + marks=[gpu_mark, skip_if_no_gpu], |
| 212 | + ), |
| 213 | + BufferPrototype( |
| 214 | + buffer=cpu.Buffer, |
| 215 | + nd_buffer=NDBufferUsingTestNDArrayLike, |
| 216 | + ), |
| 217 | + ], |
| 218 | +) |
| 219 | +@pytest.mark.parametrize( |
| 220 | + "shape", |
| 221 | + [ |
| 222 | + (1, 2), |
| 223 | + (1, 2, 3), |
| 224 | + ], |
| 225 | +) |
| 226 | +@pytest.mark.parametrize("dtype", ["int32", "float64"]) |
| 227 | +@pytest.mark.parametrize("order", ["C", "F"]) |
| 228 | +def test_empty( |
| 229 | + prototype: BufferPrototype, shape: tuple[int, ...], dtype: str, order: Literal["C", "F"] |
| 230 | +) -> None: |
| 231 | + buf = prototype.nd_buffer.empty(shape=shape, dtype=dtype, order=order) |
| 232 | + result = buf.as_ndarray_like() |
| 233 | + assert result.shape == shape |
| 234 | + assert result.dtype == dtype |
| 235 | + if order == "C": |
| 236 | + assert result.flags.c_contiguous # type: ignore[attr-defined] |
| 237 | + else: |
| 238 | + assert result.flags.f_contiguous # type: ignore[attr-defined] |
0 commit comments