Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Incorrect behavior of sparse_arr.sum(out=out) for some arguments #26149

Description

@seberg

Describe your issue.

Found while porting over CuPy to support 1.18, one of the tests passes both out= and dtype=. It appears that in some cases, SciPy (since gh-24496) fails to return the out identity.

So basically mostly an inconvenience to track down why the test is failing (and now work around it).
I admit it is a rather odd to pass both dtype= and out=, but preserving strict out identity is maybe a nice simple fix anyway.

Reproducing Code Example

import numpy as np
import scipy
import scipy.sparse as sp
print("scipy", scipy.__version__, "numpy", np.__version__)

a = np.array([[0.0, 1.0], [2.0, 0.0]], dtype=np.float32)
A = sp.csr_array(a)
out = np.empty(2)

# Both dtype and `out` (yes, this is nonsense that `dtype=` is smaller than out...)
assert A.sum(axis=0, out=out, dtype=np.float32) is out

If you apply it along axis=, things pass.

Error message

`out` identity return isn't preserved (and a fresh array of dtype `dtype=dtype` returned instead).

SciPy/NumPy/Python version and system information

1.18 and current main. NumPy is irrelevant.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.sparse

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions