我正在使用Eigen库编写一些要在Raspberry Pi上运行的c ++代码,以处理我的数组和矩阵。我编写的代码在Linux上可以运行,但是当我在Raspberry Pi上运行它时,会引发此错误:
Eigen::internal::matrix_array<T, Size, MatrixOptions, Align>::internal::matrix_array()
[with T = double, int Size = 2, int MatrixOptions = 2, bool Align = true]:
Assertion `(reinterpret_cast<size_t>(array) & (sizemask)) == 0 && "this assertion
is explained here: http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html
READ THIS WEB PAGE !!! ****"' failed.
我通读了错误中给我的链接,并尝试按照代码的指示重新定义整个代码中的各种定义,但无济于事。我正在执行大量矩阵运算,但无法确定到底哪里出了问题。
为了使事情更简洁,这里是我的类定义,省略了除函数定义之外的所有内容:
class TileBlock{
public:
TileBlock();
TileBlock(REGION_BD ®ion_bd, std::shared_ptr<Tile> linked_tile, int Hin);
TileBlock(REGION_BD ®ION_BD, std::shared_ptr<Tile> linked_tile, int Hin,
std::string alfa_str,
std::string bta_str,
std::string w_lower_str,
std::string w_upper_str,
std::string x_str,
std::string w_str,
std::string w_sol_str,
std::string y_exit_str,
std::string z_exit_str,
std::string bta_smp_str,
std::string alfa_sol_str,
std::string alfa_smp_str,
std::string w_smp_str,
std::string x_smp_str);
~TileBlock();
public:
void cbta();
void cbra(int idx_r_from,REGION_BD &theRegion,double r_min,
long int N_REGION_TOTAL, Eigen::RowVectorXi& region_target_2,
Eigen::RowVectorXi& region_neighbors);
static int find_sample(Eigen::RowVectorXd& ySmp, double y);
private:
void cbta_s1(double w, double d,
Eigen::RowVectorXd& xSmp,
Eigen::Matrix<double,2,N_CBTA_W>& btaSmp,
Eigen::Matrix<double,2,1>& returnMatrix);
void cbta_s2(double w, double d,
Eigen::RowVectorXd& xSmp,
Eigen::Matrix<double,2,N_CBTA_W>& btaSmp,
Eigen::Matrix<double,2,1>& returnMatrix);
void interp_broken_seg(Eigen::RowVectorXd& x_data,
Eigen::Matrix<double,2,Eigen::Dynamic>& y_data,
Eigen::RowVectorXd& x_interp,
Eigen::Matrix<double,2,Eigen::Dynamic>& y_interp);
template <typename Derived1, typename Derived2>
void remove_inf_values(Eigen::MatrixBase<Derived1>& v,
Eigen::MatrixBase<Derived2>& returnMatrix);
template <typename Derived_a, typename Derived_b>
void find_zeros(Eigen::MatrixBase<Derived_a>& fSmp,
Eigen::MatrixBase<Derived_b>& returnMatrix);
double pi2pi(double x);
};
class Tile{
public:
Tile(int H, Eigen::Matrix<int,Eigen::Dynamic,4> tile_vertices);
Tile(std::string traversal_type_str,
std::string traversal_faces_str,
std::string cell_xform_str,
std::string channel_data_str,
std::string cell_edge_str,
std::string cell_vertices_str,
std::string connectivity_str);
~Tile();
public:
Eigen::Matrix<int,Eigen::Dynamic,4> channel_data;
Eigen::Matrix<double,4,Eigen::Dynamic> cell_vertices;
Eigen::Matrix<int,Eigen::Dynamic,1> traversal_type;
Eigen::Matrix<int,Eigen::Dynamic,2> cell_xform;
Eigen::Matrix<int,Eigen::Dynamic,1> traversal_faces;
Eigen::Matrix<double,Eigen::Dynamic,4> cell_edge;
std::shared_ptr<TileBlock> tile_block;
std::shared_ptr<Eigen::SparseMatrix<int,Eigen::RowMajor>> connectivity;
void set_tile_data(int, Eigen::Matrix<int,Eigen::Dynamic,4>);
void addTileBlock(REGION_BD ®ion_bd, std::shared_ptr<TileBlock> this_tile, int H);
void setMatricesFromJSON(std::string traversal_type_str,
std::string traversal_faces_str,
std::string cell_xform_str,
std::string channel_data_str,
std::string cell_edge_str,
std::string cell_vertices_str);
void setConnectivityFromJSON(std::string connectivity_str);
};
现在,以下代码段是我认为遇到麻烦的地方。它位于setMatricesFromJSON
函数的定义中:
/******* cell_vertices_str *******/
temp_char_double[cell_vertices_str.size() +1];
strcpy(temp_char_double, cell_vertices_str.c_str());
burner_array.clear();
token_double = strtok (temp_char_double,"[");
counter = 0;
while (token_double != NULL)
{
burner_array.push_back(token_double);
token_double = strtok (NULL, "[");
counter++;
}
ss.clear();
ss << burner_array[0];
ss >> test_str;
n = std::count(test_str.begin(), test_str.end(), ',');
cell_vertices = Matrix4Xd::Zero(counter,n);
test_str.clear();
ss.clear();
for (size_t i = 0; i < counter; i++)
{
std::vector<double> ind_num_array;
char *token_double;
token_double = strtok (burner_array[i],",]");
int j = 0;
std::stringstream ss;
while (token_double != NULL)
{
ss.clear();
ss << token_double;
double temp_val;
ss >> temp_val;
ind_num_array.push_back(temp_val);
token_double = strtok (NULL, ",]");
j++;
}
for (size_t k = 0; k < j; k++)
{
this->cell_vertices(i,k) = ind_num_array[k];
}
}
代码在Linux上运行没有问题。但是,当我尝试在Raspberry Pi上运行它时,会收到上述错误。我对c ++还是很陌生,这里有很多代码我没有包括在内,因为有很多代码,我想尽可能精确地回答我的问题。感谢您提供的所有帮助!我已经尝试解决这个问题已有一段时间了。