Skip to content

scipy and/or numpy change is causing tests to fail in another project #3345

Closed
argriffing opened this Issue Feb 18, 2014 · 5 comments

2 participants

@argriffing

The test failures are in one of the comments in
cvxgrp/cvxpy@4d747e7

I don't know scipy.sparse well enough to say if this is an actual regression, but I can replicate the test failures. Maybe it's just problems in the cvxpy project in which case this issue can be closed.

@pv
SciPy member
pv commented Feb 18, 2014

I'm not able to reproduce the test failures. How do you reproduce them?

Works for me with Numpy 1.8.0, Scipy 0.14.0.dev-7cefb25 (current master), with 1.7.1 + 0.14.0.dev-7cefb25, and with 1.7.1 + 0.13.3.

Does not work with Scipy 0.12.0.

@argriffing

@pv the test failures are with the development branches of numpy and scipy, and it's possible that I'm reproducing a failure to install numpy/scipy correctly :)

Maybe the problem is bad installation, or just a problem in cvxpy, or maybe a numpy regression, or maybe a regression in the interaction between numpy and scipy. Only the latter situation would be interesting here.

@pv
SciPy member
pv commented Feb 18, 2014

Ok, the issue seems to be that cvxopt relies on this behavior:

import numpy as np
from scipy.sparse import csr_matrix
np.multiply(csr_matrix([[1, 2]]), np.array([csr_matrix([[3], [4]])], dtype=object))
# -> array([ <1x1 sparse matrix of type '<type 'numpy.int64'>'
#         with 1 stored elements in Compressed Sparse Row format>], dtype=object)

In Numpy 1.9.0-dev + Scipy 0.14.0-dev this gets routed to csr_matrix.__numpy_ufunc__, which does something undefined with the object array arg.

Previously, this did np.array([a.__mul__(b) for b in rhs], dtype=object).
This behavior is recovered by explicitly casting also the first arg to object array

np.multiply(np.array(csr_matrix([[1, 2]]), dtype=object), 
            np.array([csr_matrix([[3], [4]])], dtype=object))
@argriffing

oh my

@pv pv added a commit to pv/scipy-work that referenced this issue Feb 18, 2014
@pv pv BUG: sparse: restore previous behavior in numpy ufuncs with object ar…
…rays

Some users may rely on ufuncs distributing operations on sparse matrices
across each entry of an object array.

Fixes gh-3345
a3e0973
@pv
SciPy member
pv commented Feb 18, 2014

Previous behavior vs. object arrays restored in gh-3346 (fixes cvxopt test failures).

The previous behavior was quite glitchy, however:

>>> np.multiply(np.array([csr_matrix([[3], [4]])], dtype=object), csr_matrix([[1, 2]]))
NotImplemented

The recommendation to people relying on this is to not rely on automatic
casts to object arrays, but to cast explicitly.

@pv pv added a commit to pv/scipy-work that referenced this issue Feb 18, 2014
@pv pv BUG: sparse: restore previous behavior in numpy ufuncs with object ar…
…rays

Some users may rely on ufuncs distributing operations on sparse matrices
across each entry of an object array.

Fixes gh-3345
869bce9
@argriffing argriffing closed this in #3346 Feb 18, 2014
@pv pv added this to the 0.14.0 milestone Feb 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.