Skip to content
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

Bug: Fill values 0 and -0 seen as different #802

Closed
2 of 3 tasks
aulemahal opened this issue Oct 31, 2024 · 2 comments
Closed
2 of 3 tasks

Bug: Fill values 0 and -0 seen as different #802

aulemahal opened this issue Oct 31, 2024 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior needs triage Issue has not been confirmed nor labeled

Comments

@aulemahal
Copy link

aulemahal commented Oct 31, 2024

sparse version checks

  • I checked that this issue has not been reported before list of issues.

  • I have confirmed this bug exists on the latest version of sparse.

  • I have confirmed this bug exists on the main branch of sparse.

Describe the bug

I can't concatenate two arrays that have fill values of 0.0 and -0.0 as the values are seen as different, inconsistent.

Doesn't happen on the last release (0.15.4) but it does when I install the main branch.

Steps or code to reproduce the bug

import numpy as np
import sparse as sp

a = sp.COO(np.array([[0, 3]]), [1.0, 4.0], (4,))
b = sp.COO(np.array([[0, 3]]), [6.0, 8.0], (4,))

print(a)
# <COO: shape=(4,), dtype=float64, nnz=2, fill_value=0.0>

print(-b)
# <COO: shape=(4,), dtype=float64, nnz=2, fill_value=-0.0>

sp.concat([a, b])
# Works

sp.concat([a, -b])
# Fails

Expected results

<COO: shape=(8,), dtype=float64, nnz=4, fill_value=0>

Actual results

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[4], line 6
      4 a = sp.COO(np.array([[0, 3]]), [1.0, 4.0], (4,))
      5 b = sp.COO(np.array([[0, 3]]), [6.0, 8.0], (4,))
----> 6 sp.concat([a, -b])

File ~/miniforge3/envs/xesmf/lib/python3.12/site-packages/sparse/numba_backend/_common.py:1543, in concatenate(arrays, axis, compressed_axes)
   1540 if not builtins.all(isinstance(arr, GCXS) for arr in arrays):
   1541     from ._coo import concatenate as coo_concat
-> 1543     return coo_concat(arrays, axis)
   1545 from ._compressed import concatenate as gcxs_concat
   1547 return gcxs_concat(arrays, axis, compressed_axes)

File ~/miniforge3/envs/xesmf/lib/python3.12/site-packages/sparse/numba_backend/_coo/common.py:160, in concatenate(arrays, axis)
    134 """
    135 Concatenate the input arrays along the given dimension.
    136 
   (...)
    156 [`numpy.concatenate`][] : NumPy equivalent function
    157 """
    158 from .core import COO
--> 160 check_consistent_fill_value(arrays)
    162 if axis is None:
    163     axis = 0

File ~/miniforge3/envs/xesmf/lib/python3.12/site-packages/sparse/numba_backend/_utils.py:636, in check_consistent_fill_value(arrays)
    634 for i, arg in enumerate(arrays):
    635     if not equivalent(fv, arg.fill_value):
--> 636         raise ValueError(
    637             "This operation requires consistent fill-values, "
    638             f"but argument {i:d} had a fill value of {arg.fill_value!s}, which "
    639             f"is different from a fill_value of {fv!s} in the first "
    640             "argument."
    641         )

ValueError: This operation requires consistent fill-values, but argument 1 had a fill value of -0.0, which is different from a fill_value of 0.0 in the first argument.

Please describe your system.

  1. Linux, Fedora 40, 6.11.5-200.fc40.x86_64
  2. sparse version : 0.16.0a10.dev83+g440bd35
  3. NumPy version : 2.0.2
  4. Numba version : 0.60.0

Relevant log output

No response

@aulemahal aulemahal added bug Indicates an unexpected problem or unintended behavior needs triage Issue has not been confirmed nor labeled labels Oct 31, 2024
@willow-ahrens
Copy link
Collaborator

These two values are indeed different though, right? Otherwise we would have 1/cat(A, B) != cat(1/A, 1/B)?

@aulemahal
Copy link
Author

Ah, I didn't see it that way... Indeed, for that operation, numpy yields inf and -inf which are different.

Then I guess it's a new feature I simply didn't expect, and not a bug! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior needs triage Issue has not been confirmed nor labeled
Projects
None yet
Development

No branches or pull requests

2 participants