P: n/a

i would like to have a C++ code for the transpose of a matrix if
anyone could assist me with it i would be glad to have it  
Share this Question
P: n/a

dorcas wrote: i would like to have a C++ code for the transpose of a matrix if anyone could assist me with it i would be glad to have it
If you're too lazy to do your own homework, don't ask us. Go to
any Web search engine and look for it. At least then nobody will
have assisted you in cheating.  
P: n/a

Victor Bazarov wrote: dorcas wrote: i would like to have a C++ code for the transpose of a matrix if anyone could assist me with it i would be glad to have it
If you're too lazy to do your own homework, don't ask us. Go to any Web search engine and look for it. At least then nobody will have assisted you in cheating.
I know this is not what the OP requested, but if the exercice is to
perform an "in situ" transpose  i.e. perform the transpose by swapping
matrix elements  it turns out to be surprisingly difficult. Try it if
you've nothing better to do.

Lionel B  
P: n/a

Lionel B wrote: Victor Bazarov wrote:
dorcas wrote:
i would like to have a C++ code for the transpose of a matrix if anyone could assist me with it i would be glad to have it
If you're too lazy to do your own homework, don't ask us. Go to any Web search engine and look for it. At least then nobody will have assisted you in cheating.
I know this is not what the OP requested, but if the exercice is to perform an "in situ" transpose  i.e. perform the transpose by swapping matrix elements  it turns out to be surprisingly difficult. Try it if you've nothing better to do.
I am not sure whom you're addressing in your last sentence.  
P: n/a

Victor Bazarov wrote: Lionel B wrote: Victor Bazarov wrote:
dorcas wrote:
i would like to have a C++ code for the transpose of a matrix if anyone could assist me with it i would be glad to have it
[...]
I know this is not what the OP requested, but if the exercice is to perform an "in situ" transpose  i.e. perform the transpose by swapping matrix elements  it turns out to be surprisingly difficult. Try it if you've nothing better to do.
I am not sure whom you're addressing in your last sentence.
The World (sorry if that wasn't clear).

Lionel B  
P: n/a

Lionel B wrote: Victor Bazarov wrote:
Lionel B wrote:
Victor Bazarov wrote:
dorcas wrote:
>i would like to have a C++ code for the transpose of a matrix if >anyone could assist me with it i would be glad to have it
[...]
I know this is not what the OP requested, but if the exercice is to perform an "in situ" transpose  i.e. perform the transpose by swapping matrix elements  it turns out to be surprisingly difficult. Try it if you've nothing better to do.
I am not sure whom you're addressing in your last sentence.
The World (sorry if that wasn't clear).
No worries. I for some reason find it surprising that you find the
inplace transpose "surprisingly difficult". Of course, it very much
depends on the data structure for the matrix and the performance you
want to achieve, I guess, but for a straightforward representation
that has nested operator[] defined (like for a twodimensional array
or a vector of vectors), two nested loops of calls to 'std::swap' is
all you need. Is that what you call "difficult"? I can see how it
could be difficult to the OP, of course...
V  
P: n/a

Lionel B wrote: I know this is not what the OP requested, but if the exercice is to perform an "in situ" transpose  i.e. perform the transpose by swapping matrix elements  it turns out to be surprisingly difficult. Try it if you've nothing better to do.
Why ?
Transposing the matrix in place can be done easily by looping trough all
elements (i,j) of the upper triangular part of the matrix, and swap each
element (i,j) with element (j,i).

Ares Lagae
Computer Graphics Research Group, Katholieke Universiteit Leuven http://www.cs.kuleuven.ac.be/~ares/  
P: n/a

Ares Lagae wrote: Lionel B wrote:
I know this is not what the OP requested, but if the exercice is to perform an "in situ" transpose  i.e. perform the transpose by swapping matrix elements  it turns out to be surprisingly difficult. Try it if you've nothing better to do.
Why ?
Transposing the matrix in place can be done easily by looping trough all elements (i,j) of the upper triangular part of the matrix, and swap each element (i,j) with element (j,i).
Try that for a nonsquare matrix ;)

Lionel B  
P: n/a

Lionel B wrote: Ares Lagae wrote:
Lionel B wrote:
I know this is not what the OP requested, but if the exercice is to perform an "in situ" transpose  i.e. perform the transpose by swapping matrix elements  it turns out to be surprisingly difficult. Try it if you've nothing better to do.
Why ?
Transposing the matrix in place can be done easily by looping trough all elements (i,j) of the upper triangular part of the matrix, and swap each element (i,j) with element (j,i).
Try that for a nonsquare matrix ;)
With certain data structures it's by definition impossible.
V  
P: n/a

Victor Bazarov wrote: Lionel B wrote: Ares Lagae wrote:
Lionel B wrote:
I know this is not what the OP requested, but if the exercice is to perform an "in situ" transpose  i.e. perform the transpose by swapping matrix elements  it turns out to be surprisingly difficult. Try it if you've nothing better to do.
Why ?
Transposing the matrix in place can be done easily by looping trough all elements (i,j) of the upper triangular part of the matrix, and swap each element (i,j) with element (j,i).
Try that for a nonsquare matrix ;)
With certain data structures it's by definition impossible.
Let's say sequential, rowmajor storage. As far as I know this problem
was first solved in the paper:
Windley, P. F. "Transposing Matrices in a Digital Computer." Computer
J. 2, 4748, Apr. 1959.
available online at: http://www3.oup.co.uk/computer_journ...7.sgm.abs.html

Lionel B  
P: n/a

dorcas wrote: I would like to have a C++ code for the transpose of a matrix if anyone could assist me with it i would be glad to have it
Take a look at
The C++ Scalar, Vector, Matrix and Tensor class Library http://www.netwood.net/~edwin/svmtl/
cat svmtl/src/vector/doubleVector/doubleVector.cc  
P: n/a

E. Robert Tisdale wrote: dorcas wrote:
I would like to have a C++ code for the transpose of a matrix if anyone could assist me with it i would be glad to have it
Take a look at The C++ Scalar, Vector, Matrix and Tensor class Library
http://www.netwood.net/~edwin/svmtl/
[...]
Interesting... is this your own algorithm? Having another look at the
paper:
Windley, P. F. "Transposing Matrices in a Digital Computer." Computer
J. 2, 4748, Apr. 1959.
mentioned in a previous post of mine, I think your algorithm is the
same as one attributed there to one "J. C. Gower". The author's own
algorithm, he says, "... saves going around each cycle once, but ...
involves more reading and writing operations ...".
Knuth (natch) also gives several variations in:
Knuth, D. E. "Transposing a Rectangular Matrix." Ch. 1.3.3 Ex. 12. The
Art of Computer Programming, Vol. 1: Fundamental Algorithms, 3rd ed.

Lionel B  
P: n/a

Lionel B wrote: E. Robert Tisdale wrote:
dorcas wrote:
I would like to have a C++ code for the transpose of a matrix if anyone could assist me with it i would be glad to have it Take a look at The C++ Scalar, Vector, Matrix and Tensor class Library
http://www.netwood.net/~edwin/svmtl/
[...]
Interesting... is this your own algorithm?
I find it very difficult to read and understand papers
like the ones that you cite without first implementing
my own algorithm.
Having another look at the paper:
Windley, P. F. "Transposing Matrices in a Digital Computer." Computer J. 2, 4748, Apr. 1959.
The online copy of this is a tiff file which my browser (Mozilla)
doesn't handle very well  I couldn't print it.
mentioned in a previous post of mine, I think your algorithm is the same as one attributed there to one "J. C. Gower". The author's own algorithm, he says, "... saves going around each cycle once, but ... involves more reading and writing operations ...".
Knuth (natch) also gives several variations in:
Knuth, D. E. "Transposing a Rectangular Matrix." Ch. 1.3.3 Ex. 12. The Art of Computer Programming, Vol. 1: Fundamental Algorithms, 3rd ed.
I appreciate the references.
I have since collected and read many papers on this topic
but they all seem to require a search for the cycles.
I would expect a performance implementation of the SVMTL
to implement an optimal algorithm for inplace transpose
but I thought that my implementation was more appropriate
for the reference library because it seemed to me to be
more transparent.   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 3750
 replies: 12
 date asked: Jul 23 '05
