Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <Eigen/Dense>
- #include "eigen_mematrix.h"
- #include "eigen_mematrix.cpp"
- #include <time.h>
- using namespace Eigen;
- using namespace std;
- int main()
- {
- int a1, a2, b1, b2;
- a1 = b1 = b2 = 2139;
- a2 = 3;
- MatrixXd randomNumbers = MatrixXd::Random(a1, a2);
- mematrix<double> probRandom(a1, a2);
- mematrix<double> tXX;
- probRandom.data=randomNumbers;
- //symMat should be a symmetric matrix since this is a covariance matrix
- MatrixXd symMat = MatrixXd::Ones(b1, b2);
- mematrix<double> probSym(b1,b2);
- probSym.data=symMat;
- MatrixXd newmat;
- int n = 200;
- clock_t t1, t2;
- float diff;
- //repeat everything multiple times to exclude other processes interfering
- for (int b = 0; b < 3; b++)
- {
- //eigen native implementation for multiplying
- t1 = clock();
- for (int a = 0; a < n; a++)
- {
- MatrixXd tx = randomNumbers.transpose();
- tx=tx*symMat;
- newmat=tx*randomNumbers;
- }
- t2 = clock();
- diff = ((float) t2 - (float) t1) / 1000000.0F;
- printf("eigen mult. : %.2lf seconds \n", diff);
- //make use of interface to eigen implementation for multiplying
- t1 = clock();
- for (int a = 0; a < n; a++)
- {
- newmat=probRandom.data.transpose()*probSym.data*probRandom.data;
- }
- t2 = clock();
- diff = ((float) t2 - (float) t1) / 1000000.0F;
- printf("probabel mult: %.2lf seconds \n", diff);
- //eigen native implementation for setting values
- double putvalue=12.34;
- t1 = clock();
- for (int a = 0; a < n; a++)
- {
- for (int i = 0; i < b1; i++){
- for (int j = 0; j < b2; j++){
- probSym.put(putvalue,i,j);
- }
- }
- }
- t2 = clock();
- diff = ((float) t2 - (float) t1) / 1000000.0F;
- printf("probabel : put %.2lf seconds \n", diff);
- //make use of interface to eigen implementation for setting values
- t1 = clock();
- for (int a = 0; a < n; a++)
- {
- for (int i = 0; i < b1; i++){
- for (int j = 0; j < b2; j++){
- symMat(i,j)=putvalue;
- }
- }
- }
- t2 = clock();
- diff = ((float) t2 - (float) t1) / 1000000.0F;
- printf("eigen : put %.2lf seconds \n", diff);
- }//end loop over all functions
- }//end of main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement