Repository: cubed-dev/cubed
Pull request #636 (2024-12-04 16:37:19)

Array API tests fixes
Fix some failures in https://github.com/cubed-dev/cubed/actions/workflows/array-api-tests.yml (there may be more).


Patch:
diff --git a/cubed/array_api/creation_functions.py b/cubed/array_api/creation_functions.py
index 717ec725..ffbbd9bd 100644
--- a/cubed/array_api/creation_functions.py
+++ b/cubed/array_api/creation_functions.py
@@ -145,6 +145,8 @@ def full(
             dtype = nxp.int64
         elif isinstance(fill_value, float):
             dtype = nxp.float64
+        elif isinstance(fill_value, complex):
+            dtype = nxp.complex128
         else:
             raise TypeError("Invalid input to full")
     chunksize = to_chunksize(normalize_chunks(chunks, shape=shape, dtype=dtype))
diff --git a/cubed/array_api/manipulation_functions.py b/cubed/array_api/manipulation_functions.py
index 4948d203..93ea2341 100644
--- a/cubed/array_api/manipulation_functions.py
+++ b/cubed/array_api/manipulation_functions.py
@@ -47,14 +47,16 @@ def broadcast_to(x, /, shape, *, chunks=None):
     ):
         raise ValueError(f"cannot broadcast shape {x.shape} to shape {shape}")
 
-    # TODO: fix case where shape has a dimension of size zero
-
     if chunks is None:
         # New dimensions and broadcast dimensions have chunk size 1
         # This behaviour differs from dask where it is the full dimension size
         xchunks = normalize_chunks(x.chunks, x.shape, dtype=x.dtype)
-        chunks = tuple((1,) * s for s in shape[:ndim_new]) + tuple(
-            bd if old > 1 else ((1,) * new if new > 0 else (0,))
+
+        def chunklen(shapelen):
+            return (1,) * shapelen if shapelen > 0 else (0,)
+
+        chunks = tuple(chunklen(s) for s in shape[:ndim_new]) + tuple(
+            bd if old > 1 else chunklen(new)
             for bd, old, new in zip(xchunks, x.shape, shape[ndim_new:])
         )
     else:


Test patch:
diff --git a/.github/workflows/array-api-tests.yml b/.github/workflows/array-api-tests.yml
index 46f79f6c..4f6ff66a 100644
--- a/.github/workflows/array-api-tests.yml
+++ b/.github/workflows/array-api-tests.yml
@@ -108,6 +108,8 @@ jobs:
           # edge case failures (https://github.com/cubed-dev/cubed/issues/420)
           array_api_tests/test_linalg.py::test_tensordot
           array_api_tests/test_linalg.py::test_vecdot
+          # (getitem with negative step size is not implemented)
+          array_api_tests/test_array_object.py::test_getitem
 
           # not implemented
           array_api_tests/test_array_object.py::test_setitem
diff --git a/cubed/tests/test_array_api.py b/cubed/tests/test_array_api.py
index 4ea6653c..327e6726 100644
--- a/cubed/tests/test_array_api.py
+++ b/cubed/tests/test_array_api.py
@@ -474,7 +474,8 @@ def test_broadcast_arrays(executor):
 @pytest.mark.parametrize(
     "shape, chunks, new_shape, new_chunks, new_chunks_expected",
     [
-        # ((5, 1, 6), (3, 1, 3), (5, 0, 6), None, ((3, 2), (0,), (3, 3))),  # fails
+        ((), (), (0,), None, ((0,),)),
+        ((5, 1, 6), (3, 1, 3), (5, 0, 6), None, ((3, 2), (0,), (3, 3))),
         ((5, 1, 6), (3, 1, 3), (5, 4, 6), None, ((3, 2), (1, 1, 1, 1), (3, 3))),
         ((5, 1, 6), (3, 1, 3), (2, 5, 1, 6), None, ((1, 1), (3, 2), (1,), (3, 3))),
         ((5, 1, 6), (3, 1, 3), (5, 3, 6), (3, 3, 3), ((3, 2), (3,), (3, 3))),