Am Donnerstag 29 November 2007 10:34:04 schrieb nisha kannookadan:
Ok, I optimized my program (now its with pass by reference and the resize stuff is out):
void Wavelet::ttrans(matrix& At, int level) { matrix cfe1, cfe2, cfo, cfe, c, d; int N,s2;
N = (At.size1()+1)/2; s2 = At.size2(); scalar_matrix zer(N,s2);
for (int ii = 1; ii <= level; ii++) {
cfo = subslice(At, 0,2,N, 0,1,s2); cfe = subslice(At, 1,2,N-1, 0,1,s2); A subslice is lightweight handle for maybe a heavyweight matrix. This line cfo = subslice(At, 0,2,N, 0,1,s2); eliminates the performance gain, since cfo is a full flagged matrix.
However, don't know if its allowed to apply a subrange to a subslice. Can you spend a full working example plus data? Its very hard to give tips on template libraries without the tips I get from of my compiler :)
c = (cfe + (subrange(cfo, 0,N-1, 0,s2)+subrange(cfo, 1,N, 0,s2))*0.5);
zer.resize(N,s2,true); cfe1 = zer; cfe2 = zer;
(subrange(cfe1, 0,N-1, 0,s2)).assign(cfe); (subrange(cfe2, 1,N, 0,s2)).assign(cfe); d = cfo-(cfe1+cfe2)*0.5;
(subrange(At, 0,N-1, 0,At.size2())).assign(c); (subrange(At, N-1,2*N-1, 0,At.size2())).assign(d);
N = N/2; }
cfe1.clear(); cfe2.clear(); cfo.clear(); cfe.clear(); c.clear(); d.clear();
}
But I guessed, its still not good enough, and wanted to work with pointer to mend copying..and the result was the next code piece, which compiles, but terminates when I run it..
void Wavelet::ttrans(matrix& At, int level) { matrix cfe1, cfe2, *cfo, *cfe, *c, *d;
PLEASE don't use ublas matrices as pointers! They are not made for this (no virtual destructors for performace reasons). If you want to avoid copying, allways use references. BTW: Theres a ublas mailing list - http://lists.boost.org/mailman/listinfo.cgi/ublas which is read by all ublas devs and power users. If someone knows how get the most performace out of your code, they do. And again, yu will get the most (useful) feedback if you provide a working examples which can be hacked. Best, -- Maik