[SciPy-User] scipy.sparse.[vh]stack and a_sparse_matrix.__setitem__(ndarray, value) broken

Pauli Virtanen pav at iki.fi
Mon Dec 2 17:13:23 EST 2013


Hi,

02.12.2013 23:18, Frédéric Bastien kirjoitti:
[clip]
> 1) a_sparse_matrix.__setitem(ndarray, value) don't work anymore when
> the ndarray contain only 2 value.
>
> Fix: casting the ndarray to a tuple:

That it worked similarly as a tuple is a bug, actually.
The current behavior is correct:

>>> from scipy.sparse import csr_matrix
>>> import numpy as np
>>> x = np.arange(5*5).reshape(5,5)
>>> y = csr_matrix(x)
>>> x[np.array([1,3])]
array([[ 5,  6,  7,  8,  9],
       [15, 16, 17, 18, 19]])
>>> y[np.array([1,3])].todense()
matrix([[ 5,  6,  7,  8,  9],
        [15, 16, 17, 18, 19]])
>>> y[np.array([1,3])] = 5
>>> y[np.array([1,3])].todense()
matrix([[5, 5, 5, 5, 5],
        [5, 5, 5, 5, 5]])

Now, you could perhaps argue for bug-for-bug backward compatibility, but
unfortunately this is not a realistic option in the current state of
scipy.sparse.

> 2) scipy.sparse.vstack(block, format=self.format,
>                                       dtype=self.dtype)
> 
> Do not cast block to the wanted dtype.
> 
> Fix: check if the dtype is right, if not, call astype(dtype)
> 
> 3) same as 2 for hstack

These are probably due to the CSR/CSC fast path added recently to
hstack/vstack in scipy master. Please report this to the Scipy issue
tracker, so we remember it.

-- 
Pauli Virtanen




More information about the SciPy-User mailing list