Open mfeuerle opened 2 years ago
We could accomplish this with a dynamic attribute lookup hack:
def to_sparse_array(x):
cls = getattr(x, f'_{x.format}_container')
return cls(x)
It nearly worked. If x
is a matrix, the corresponding container is also a matrix, so the above function did in fact nothing, but
def tosparray(x):
if isdense(x):
return x
cls = getattr(_arrays, f'{x.format}_array')
return cls(x)
works. Unfortunalty, it only works for the default sparrays
located in _arrays
but not for other, e.g. a self implemented spmatrix
.
Is your feature request related to a problem? Please describe.
All the constructor methods in
scipy.sparse
(e.g.kron
,eye
, etc) are not yet transferred to the new array interface. I really like the numpy compatible element-wise multiplication, but the usage of those new arrays is really cumbersome since you have to manually change every single format. I would suggest a simple switcher method to simply switch between both formats.Describe the solution you'd like.
A straight forward solution would be something like
This would make the interplay between those two formats easier and especially the new arrays way more accessible.
Of course, this could (and probably) should be done in a more flexible way than simply
if
statements, so that it ideally works for allspmatrix
e.g. with something likeUnfortunatly, the result would be a
_sparray
of typeTMP
and not e.g. of typecoo_array
which is a problem e.g. forisspmatrix_coo
. But i think a quite easy solution is from this point not to far away.Describe alternatives you've considered.
No response
Additional context (e.g. screenshots, GIFs)
No response