[SciPy-Dev] utility for composing sparse matrices

Robert Cimrman cimrman3 at ntc.zcu.cz
Tue Sep 21 02:45:36 EDT 2010


On Mon, 20 Sep 2010, josef.pktd at gmail.com wrote:
> On Mon, Sep 20, 2010 at 6:25 AM, Robert Cimrman <cimrman3 at ntc.zcu.cz> wrote:
>> On Mon, 20 Sep 2010, Pauli Virtanen wrote:
>>> Mon, 20 Sep 2010 10:26:58 +0200, Robert Cimrman wrote:
>>>> FYI: I have created a function that creates a sparse matrix from sparse
>>>> (or dense) blocks, somewhat in the spirit of np.r_ and friends, see the
>>>> example below.
>>>>
>>>> Shall we add it to scipy.sparse? It may help to go around some of the
>>>> fancy-indexing limitations.
>>>
>>> Add some tests, and I see no problem in putting it in. Also, I'd check
>>> that cases such as
>>>
>>>       compose_sparse([A, B])
>>>       compose_sparse(A)
>>>
>>> are handled sensibly.
>>>
>>> Also, the equivalent function in `Numpy` is called `bmat`. Should the
>>> name here reflect that.
>>
>> I have been using numpy so long, unaware of bmat - call me exlusive array
>> user :). It's sensible to make it work with 0D and 1D arrays, yes.
>
> I never heard of it either, but it looks useful and needs some advertising.

<grr> there is even bmat() in scipy.sparse which I found just after 
writing compose_sparse() - the two functions use a slightly different 
strategy, so it might be interesting to compare them performance-wise.

As a side note, I did perform google search first, and bmat() did not 
show, so better advertising is needed. Or I just cannot use google :}.

> The equivalent of scipy.linalg.block_diag would also be very useful
> for building sparse matrices (in stats).

At least I have created [1] for constructing sparse block diagonal matrix 
(do not tell me it's already there :)).

[1] http://projects.scipy.org/scipy/ticket/1284

r.

>>> Also, we would need to think if it is possible to get the sparse matrices
>>> in Scipy to play along with functions in Numpy. (E.g. np.bmat() and
>>> np.linalg.dot() doing the correct stuff for sparse matrices.)
>>
>> I would love to see this. I guess some basic sparse matrix support would
>> have to be in Numpy directly(?). A good candidate is IMHO the COO format -
>> it is simple, can be easily converted and has the 'data' array.
>>
>> I will create an enhancement ticket with the function renamed to bmat, and
>> a test, then.
>>
>> r.
>> _______________________________________________
>> SciPy-Dev mailing list
>> SciPy-Dev at scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-dev
>>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>


More information about the SciPy-Dev mailing list