[SciPy-Dev] Minimal sparse array interface

CJ Carey perimosocordiae at gmail.com
Fri Jun 4 16:53:21 EDT 2021


On Fri, Jun 4, 2021 at 3:51 PM Stefan van der Walt <stefanv at berkeley.edu>
wrote:

> HI CJ,
>
> On Thu, Jun 3, 2021, at 21:39, CJ Carey wrote:
>
> I wrote a lightweight sparse ndarray library a few years ago:
> https://github.com/perimosocordiae/sparray
>
> It uses Cython for some hot loops, otherwise it's fairly simple. It uses a
> flattened COO-like format that's pretty efficient for common ndarray use
> cases. I was planning to add other backends, but then I finished my degree
> and got a Real Job.
>
>
> I presume sparray does not work with the linear algebra facilities in
> SciPy?
>
>
I haven't tested for scipy.linalg compatibility specifically. I expect we
might need something similar to the existing is_pydata_spmatrix() check:
https://github.com/scipy/scipy/blob/f89d39901af543a1a656585f8b8f3ec059788e1e/scipy/sparse/sputils.py#L344

That said, I just picked an example at random to test:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.expm_multiply.html
And here's the result:

In [1]: from scipy.sparse import csc_matrix

In [2]: from scipy.sparse.linalg import expm, expm_multiply

In [3]: A = csc_matrix([[1, 0], [0, 1]])

In [4]: B = np.array([np.exp(-1.), np.exp(-2.)])

In [5]: expm_multiply(A, B, start=1, stop=2, num=3, endpoint=True)

Out[5]:
array([[1.     , 0.36788],
       [1.64872, 0.60653],
       [2.71828, 1.     ]])

In [6]: import sparray

In [7]: A2 = sparray.FlatSparray.from_spmatrix(A)

In [8]: expm_multiply(A2, B, start=1, stop=2, num=3, endpoint=True)

Out[8]:
array([[1.     , 0.36788],
       [1.64872, 0.60653],
       [2.71828, 1.     ]])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/scipy-dev/attachments/20210604/01f98d8e/attachment.html>


More information about the SciPy-Dev mailing list