[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] Efficient (dynamic) slicing
From: |
Rafael Spring |
Subject: |
[Toon-members] Efficient (dynamic) slicing |
Date: |
Wed, 24 Feb 2010 16:23:23 -0800 |
Hello gentlemen,
I'd like to learn a little bit about efficient dynamic slicing of
Vectors and Matrices. Consider a situation where I hold a big Matrix
in an object and want to fill that Matrix blockwise giving slices of
the Matrix to an external function. Like this:
void fillSubMatrix(Matrix<>& slice) {
// write something to the sclice...
}
class MyMainMatrix {
public:
MyMainMatrix() : mMatrix(500, 10) {}
void fillMatrix();
private:
TooN::Matrix<> mMatrix;
};
void MyMainMatrix::fillMatrix() {
int inc = 5; // could be any number or dynamic
for (unsigned int i = 0; i < mMatrix.num_rows(); i += inc) {
fillSubMatrix(mMatrix.slice(i, 0, inc, mMatrix.num_cols()));
}
}
Following thread http://lists.nongnu.org/archive/html/toon-members/
2007-06/msg00003.html there seem to be performance penalties using
dynamic slicing. I assume the above code would also result in a
temporary object (storage allocated from the heap) being constructed
at each call to fillSubMatrix().
Would the following code be any better?
void fillSubMatrix(Matrix<-1, -1, double, TooN::Internal::Slice<-1,
1> >& slice) {
// write something to the sclice
}
Regards,
Rafael
- [Toon-members] Efficient (dynamic) slicing,
Rafael Spring <=