Skip to content

Instantly share code, notes, and snippets.

@tiandiao123
Created April 24, 2021 22:12
Show Gist options
  • Save tiandiao123/609f5ec817110907987a8e3ddd59f8a5 to your computer and use it in GitHub Desktop.
Save tiandiao123/609f5ec817110907987a8e3ddd59f8a5 to your computer and use it in GitHub Desktop.
eigen experiments
#include <iostream>
#include <Eigen/Dense>
#include <Eigen/StdVector>
using Eigen::MatrixXd;
using namespace std;
using namespace Eigen;
void initialize(MatrixXd& matrix){
for(int i=0;i<matrix.rows();i++){
for(int j=0;j<matrix.cols();j++){
matrix(i,j) = (i+j)*1.0;
}
}
}
int normalize(ArrayXXf& arr, ArrayXf& mean, ArrayXf& std){
return 0;
}
int main()
{
std::cout << "testing array functions" << std::endl;
int num_of_rows = 10;
int num_of_cols = 20;
ArrayXXf arr(num_of_rows, num_of_cols);
// initialize array
for(int i=0;i<20;i++){
arr.col(i) = Eigen::ArrayXf::LinSpaced(num_of_rows, 0, i);
}
MatrixXd m(num_of_rows,num_of_cols);
initialize(m);
std::cout << "original matrix: " << std::endl;
std::cout << m << std::endl;
VectorXd means_rows = m.rowwise().mean();
std::cout << "print means by rows" << std::endl;
std::cout << means_rows.size() << std::endl;
for(int i=0;i<means_rows.size();i++){
//means_rows(i) = m.row(i).mean();
std::cout << means_rows(i) << " ";
}
std::cout << std::endl;
std::cout << "testing minus" << std::endl;
auto result = m.colwise() - means_rows;
std::cout << result << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment