我知道将Eigen类型与动态内存结合使用时会出现对齐问题。因此,我决定Eigen::DontAlign 根据此页面禁用向量化,但是以下代码仍在执行时一致地引发SIGSEGV。如果有人可以阐明为什么会发生,我会很高兴。从我的角度来看,使用Eigen::DontAlign应该使我摆脱了对齐的复杂性。
#include <Eigen/Dense>
#include <vector>
int main()
{
using vec_t = Eigen::Matrix< double, 4, 1, Eigen::DontAlign >;
std::vector< vec_t > foo;
foo.emplace_back( 0.0, 0.0, 0.0, 1.0 );
vec_t vec{ -4.0, 1.0, 3.0, 1.0 };
foo.push_back( vec );
}
Run Code Online (Sandbox Code Playgroud)
GDB输出:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000408bed in Eigen::internal::evaluator<Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 1, 2, 4, 1> > >::packet<0, double __vector(4)>(long long, long long) const (this=0x22fa90, row=0, col=0)
at C:/Dev/Eigen/Eigen/src/Core/CoreEvaluators.h:197
197 return ploadt<PacketType, LoadMode>(m_data + row + col * …Run Code Online (Sandbox Code Playgroud) 我做了一个矩阵类,我想实现一个转置方法:
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
}
}
Run Code Online (Sandbox Code Playgroud)
问题是如何在不分配全新矩阵(该类用于大密集矩阵)的情况下实现非平方矩阵的转置方法,而是在其中.还有办法吗?