|
Ublas : |
From: Albert Strasheim (fullung_at_[hidden])
Date: 2007-05-30 08:38:08
Hello all
In the code I'm writing I typically have my data in a matrix, with each row
representing a data "point" and each column a dimension of the data.
Frequently, I want to do things like subtract a vector (like a mean vector)
from all the rows, or divide all the rows by some vector (like a variance
vector).
I would like to write:
datamatrix -= meanvec;
datamatrix /= varvec;
and sometimes
datarow -= meanvec;
datarow /= varvec;
Unless I am mistaken, one can't do this with uBLAS as-is?
Are defining extra operators outside of the matrix and vector classes the
right way add these operations so that I can use them in my code? Or maybe
there's an existing way to write this kind of thing without having to resort
to a for-loop each time?
For now, I'd settle for operations that work if matrix.size2() ==
vector.size() and vec1.size() == vec2.size(). At some distant point in the
future one might want to support broadcasting [1]. If the sizes don't match
up, some exception is thrown.
Any suggestions on how anybody else addressed this issue would be much
appreciated.
Cheers,
Albert
[1] http://www.scipy.org/EricsBroadcastingDoc