开发者

C++ matrix transposion. Boost uBLAS and double*?

I need to do a in-place transposition of a large matrix(so the simplest way to allocate another matrix and transpos开发者_开发百科e to it won't work). Unfortunately, this large matrix isn't square. And worse, the matrix is stored in an array of doubles with number of columns and rows stored separately.

I found that boost has the uBLAS library, but I didn't find a way to wrap my array of doubles in uBLAS matrix. Is there a way to do this?

Or do you recommend another ways to do the job?


If you have very big matrices and you dont want to store the temporary copies one solution would be to wrap your matrix array into the class and provide different adapters which will iterate through the elements in normal or transposed way. This is not very cache efficient but saves memory on large matrices.


As matrix operations go, matrix transposition is fairly easy to get right. I'd recommend just doing it yourself, and not worrying about uBLAS (at least for this problem). There are a few subtleties, but wikipedia's article on in-place matrix transposition is startlingly thorough.

If you have a little control over the data representation, you can do even better. If you have a matrix M with a transpose T, then clearly M[x][y] == T[y][x], so depending on what you need the transposed matrix for you may not need to perform any data transformations at all.


Depending on your use case particulars you're right about large, non-square transposition. In core versus out-of-core seems to be the biggest distinction anyone cares about.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜