matrix vector multiply

42 views
Skip to first unread message

Debasish Das

unread,
Mar 15, 2015, 5:34:03 PM3/15/15
to scala-...@googlegroups.com
Hi,

When I am doing the following:

res := ata * x

ata is a DenseMatrix[Double]
x is DenseVector[Double]
res is DenseVector[Double]

basically I wanted to do blas.dgemv(ata, x, res) with no memory allocation. 

Are they equivalent ?

Thanks.
Deb

Debasish Das

unread,
Mar 15, 2015, 5:42:05 PM3/15/15
to scala-...@googlegroups.com
Or do I have to use OpMulMatrix.Impl2[M, T, T] and run res := mult(ata, x) to get blas.gemv ?

Debasish Das

unread,
Mar 15, 2015, 10:18:18 PM3/15/15
to scala-...@googlegroups.com
Seems default DenseMatrix * DenseVector will allocate memory for result but for almost all iterative optimizers the workspace memory that comes bundled in the State can be re-used. Today we are running DenseMatrices but then for CSCMatrics also this will show up...

Is it possible to have a in-place alternative for the result ?

Even if I use OpMulMatrix.Impl2[M, T, T] and do res := mult(ata, x), the output of gemv will be allocated but I already have the memory of res allocated in the state and I want something like mult(ata, x, res)

I see something like this is done in axpy through InPlaceImpl3 but that's defined for vector operations y = ax + b only...

def axpy[A, X, Y](a: A, x: X, y: Y)(implicit axpy: scaleAdd.InPlaceImpl3[Y, A, X]): Unit = { axpy(y, a, x) }

We need to define these in-place operators for matrices...

Should I list these down and open up an issue ? I need these 5 in-place for now I think

1. dgemv : for dense matrix vector multiply
2. dgetrf: LU triangular factorization cache
3. dpotrf: cholesky triangular factorization cache
4. dgetrs: for triangular back solves related to LU
5. dpotrs: for triangular back solves related to Cholesky

David Hall

unread,
Mar 16, 2015, 12:37:45 AM3/16/15
to scala-...@googlegroups.com
I need to come up with a general solution for operations that specify a sink. I've known about it for a while, but haven't decided what to do about it. Ultimately something expression tree or macro based is going to be the answer, but that's a ton of work.

In the short term, if you'd make a new trait parallel to UFunc.InPlaceImpl called UFunc.WithSinkImpl or something and make that the implicit capability trait, I'd appreciate it. That is,

def dgemv[Sink, M, V](m: M, v: V, sink: Sink)(implicit op: OpMulMatrix.WithSinkImpl[Sink, M, V]) = op(sink, m, v)

if you want to add scale parameters you can.

--
You received this message because you are subscribed to the Google Groups "Scala Breeze" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze...@googlegroups.com.
To post to this group, send email to scala-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-breeze/3d789ec2-092d-4f83-8dc7-2508c248e3bf%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages