[SciPy-Dev] Sparse Matrix Prototype
Tue Mar 5 09:12:21 CST 2013
On Tue, Mar 5, 2013 at 2:47 PM, Daniel Smith <firstname.lastname@example.org> wrote:
>> On Tue, Mar 5, 2013 at 1:57 PM, Daniel Smith <email@example.com> wrote:
>>> I've been working on adding fancy indexing to the LIL sparse matrix
>>> class and have run into a problem. Judging from the tests, no decision
>>> has been made as to what NumPy structure the class should replicate.
>>> In particular, some of the tests assume ndarray behavior, and others
>>> assume matrix behavior. The biggest difference is in row/column vector
>>> behavior. Take for example:
>>> A = np.zeros((5, 5))
>>> B = np.matrix(A)
>>> A[:, 1]
>>> array([0, 0, 0, 0, 0])
>>> B[:, 1]
>>> matrix([ , , , ,  ])
>>> Since NumPy is encouraging people to use ndarrays over matrices, it
>>> might make sense to reproduce the ndarray behavior. However, since the
>>> class has other matrix-specific behavior, e.g. being only
>>> two-dimensional, it might be confusing to have the class behave like
>>> an ndarray in other ways. Until a decision is made, no version of the
>>> class will pass all the tests as currently written. Any input would be
>>> greatly appreciated.
>> I find the "matrixness" of sparse matrices to be constantly annoying
>> and a source of tons of special cases in code that wants to handle
>> both sparse and dense matrices... but it is what it is. If they can't
>> act like ndarrays, better they act like np.matrix's than like some
>> weird mash-up of the two. And in particular the key thing for this
>> indexing example is that we *can't* return a sparse 1-d ndarray-alike,
>> right, because we have no structure to represent sparse 1-d things?
> We have at least one sparse 1-d ndarray like thing in a sparse column
> vector, a 1xN matrix.
I thought the whole point of your example was that for the given sort
of indexing, ndarray's return an object with shape (N,) and
np.matrix's return an object with shape (N, 1), and the question was
which should sparse matrices do? And my point was that there's no such
thing as a sparse matrix with shape (N,) so the choice was sort of
obvious? Maybe I'm just missing something.
More information about the SciPy-Dev