You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add easier way to create dense vectors and matrices #378
It may be nice to have constructors to create Vector or Matrix from "dense" a.k.a "full" data. It should be able to handle numpy arrays, list of lists, and scalars. I think scalars are important to create iso-valued objects.
Creating full objects from numpy arrays is more difficult than it ought to be in GraphBLAS. For example, see Matrix._from_dense.
Relatedly, we could add a method to create a diagonal matrix from an array or scalar (for example, to create an identity matrix).
v=Vector(a.dtype, size=a.size)
v[:] =aA=v.diag()
# vsA=Vector.from_foo(a).diag()
# vsA=Vector.from_coo(np.arange(n), a, size=n).diag()
# vsA=Matrix.from_coo(np.arange(n), np.arange(n), a, nrows=n, ncols=n)
# vsA=Matrix.from_bar(a)
(Note that there are suitesparse-specific constructors such as Matrix.ss.import_fullr)
Possible signatures:
deffrom_foo(values, dtype=None, *, nrows=None, ncols=None, name=None):
... # create full matrix from array, list of lists, or scalar# what about rowwise or columnwise? Should we add `order="rowwise"` keyword?deffrom_bar(values, dtype=None, *, k=0, nrows=None, ncols=None, name=None):
... # create matrix with data on the kth diagonal from array, list, or scalar (or Vector?)
Also related is gb.io.from_numpy, whose behavior we could reconsider.
My current opinion: if we add e.g. Vector.from_dense, then I don't think we need a method to create a diagonal matrix from a numpy array. It's easy enough to do:
Activity
eriknw commentedon Feb 4, 2023
My current opinion: if we add e.g.
Vector.from_dense, then I don't think we need a method to create a diagonal matrix from a numpy array. It's easy enough to do: