Skip to content

Bug: mean -> matmul of size zero array fails #877

Open
@crusaderky

Description

@crusaderky

array_api_extra.cov currently crashes in sparse on the edge case of size zero arrays.

>>> a = sparse.zeros((1, 0))
>>> a
<COO: shape=(1, 0), dtype=float64, nnz=0, fill_value=0.0>
>>> b = a - sparse.mean(a, axis=1)
site-packages/sparse/numba_backend/_umath.py:529: RuntimeWarning: invalid value encountered in divide
  fill_value_array = self.func(*zero_args, dtype=self.dtype, **self.kwargs)
>>> b
<COO: shape=(1, 0), dtype=float64, nnz=0, fill_value=nan>
>>> b @ b.T
ValueError: This operation requires zero fill values, but argument 0 had a fill value of nan.

Expected results

fill_value should not be considered in matmul of an array with size 0.

Please describe your system.

sparse 0.17.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorneeds triageIssue has not been confirmed nor labeled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions