[SciPy-User] scipy.sparse.[vh]stack and a_sparse_matrix.__setitem__(ndarray, value) broken
Frédéric Bastien
nouiz at nouiz.org
Tue Dec 3 13:29:29 EST 2013
On Mon, Dec 2, 2013 at 5:13 PM, Pauli Virtanen <pav at iki.fi> wrote:
> 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.
Thanks for the fix! I didn't realize this was a bug fix at the same
time. I don't want bug-for-bug backward compatibility.
>> 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.
Done. But a user told it had scipy 0.13.1 and had this problem. I
tested with that version, and I don't have this problem. So it is
probably in the development version as you tell. Here is the issues:
https://github.com/scipy/scipy/issues/3111
thanks
Fred
More information about the SciPy-User
mailing list