Skip to content

Matrix-vector product with preallocation #234

Description

@dpo

Is it possible currently to specify an array for the result of A * x? In Krylov methods where many matrix-vector products will be computed, it's often possible to save time and memory by preallocating the result and overwriting it. Something like A.matvec(x, y), which should be equivalent to y = A * x. It's a little bit un-python-esque, but combined with LinearOperators, it's possible to define a custom operator that uses a preallocated array transparently, e.g.,

def OperatorWithPreallocation(A):
  y = np.empty(A.shape[0])
  def matvec(x):
    A.matvec(x, y)
    return y

  ...

and then

B = OperatorWithPreallocation(A)
B * x  # python-esque!

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions