GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add easier way to create dense vectors and matrices · Issue #378 · python-graphblas/python-graphblas

Add easier way to create dense vectors and matrices #378

New issue
Copy link
New issue
Copy link
Closed
#382
Closed
Add easier way to create dense vectors and matrices#378
#382
Copy link
Labels
featureSomething is missingSomething is missingioData input, output, and conversionsData input, output, and conversions

Description

@eriknw
eriknw
opened on Jan 30, 2023
Issue body actions

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).

These are all possible to do today, such as:

A = Matrix(a.dtype, nrows=a.shape[0], ncols=a.shape[1])
A[:, :] = a

# vs

A = Matrix.from_foo(a)

and

A = Matrix(nrows=nrows, ncols=ncols)
A << scalar

# vs

A = Matrix.from_foo(scalar, nrows=nrows, ncols=ncols)

and

v = Vector(a.dtype, size=a.size)
v[:] = a
A = v.diag()

# vs

A = Vector.from_foo(a).diag()

# vs

A = Vector.from_coo(np.arange(n), a, size=n).diag()

# vs

A = Matrix.from_coo(np.arange(n), np.arange(n), a, nrows=n, ncols=n)

# vs

A = Matrix.from_bar(a)

(Note that there are suitesparse-specific constructors such as Matrix.ss.import_fullr)

Possible signatures:

def from_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?

def from_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.

Reacted by Sultan Orazbayev

Activity

  1. eriknw commented on Feb 4, 2023

    @eriknw
    eriknw
    on Feb 4, 2023
    MemberAuthor
    More actions

    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:

    >>> D = Vector.from_dense(a).diag()
    >>> I = Vector.from_dense(1, size=n).diag()
  2. eriknw
    added
    featureSomething is missingSomething is missing
    ioData input, output, and conversionsData input, output, and conversions
    on Feb 4, 2023
  3. eriknw
    closed this as completedin #382on Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureSomething is missingSomething is missingioData input, output, and conversionsData input, output, and conversions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.