tags:

views:

403

answers:

3

Hello!

I need to do a in-place transposition of a large matrix(so the simplest way to allocate another matrix and transpose 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?

+1  A: 

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.

David Seiler
+2  A: 

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.

AlexKR
+1  A: 

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.

Rhys Ulerich