PythonOptimizers / cysparse

Python/Cython library to replace PySparse
http://PythonOptimizers.github.io/cysparse
7 stars 3 forks source link

Matrix-vector product with preallocation #234

Open dpo opened 8 years ago

dpo commented 8 years ago

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!
ghost commented 8 years ago

Currently, no.

ghost commented 8 years ago

Will implement it "soon".

ghost commented 8 years ago

Can be done without "too much work".

ghost commented 8 years ago

Do you want this for LL, CSC and CSR?

dpo commented 8 years ago

Ideally ;-)

ghost commented 8 years ago

Doable.

ghost commented 8 years ago

I guess you only use a contiguous y vector? @dpo

dpo commented 8 years ago

Is that a strong requirement? Why wouldn't it work with general indexing?

ghost commented 8 years ago

Not a strong requirement, just more work to do this efficiently. ;-)

ghost commented 8 years ago

So I guess we'll go for the more general case...

dpo commented 8 years ago

Sorry you asked whether y should be contiguous. I guess it's ok. I can't think of a situation where a non-contiguous y would be useful, but I suppose it will happen one day.