我创建了一个矩阵类,我想实现一个转置方法:
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
}
}
问题是如何在不分配整个新矩阵的情况下(该类用于大型密集矩阵),就地实现非方阵的转置方法。是否有方法可以做到这一点?
std::vector
。 - Fytch