I made a matrix class and I would like to implement a method for transposition:
template<typename T>
void Matrix<T>::Transpose()
{
// for square matrices
if(this->Width() == this->Height())
{
for(std::size_t y = 1; y < this->Height(); ++y)
{
for(std::size_t x = 0; x < y; ++x)
{
// the function operator is used to access the entries of the matrix
std::swap((*this)(x, y), (*this)(y, x));
}
}
}
else
{
// TODO
}
}
The question is how to implement the transpose method for non-square matrices without allocating a whole new matrix (the class is used for big dense matrices) but inplace. Is there even a way?