Skip to content

Matrix-vector product with preallocation #234

@dpo

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!

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