Eigen is a high-level C++ library of template headers for linear algebra, matrix and vector operations, numerical solvers and related algorithms.
Eigen library is at eigen/eigen, which is generated from this github repo.
This example shows the way to generate a random matrix, print it and then print only he middle rows.
Create a simple project and the following file inside it.
$ bii init eigen_example -L
$ cd eigen_example
$ # copy DenseBase_middleRows_int.cpp
DenseBase_middleRows_int.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <Eigen/Core>
#include <iostream>
using namespace Eigen;
using namespace std;
int main(void)
{
int const N = 5;
MatrixXi A(N,N);
A.setRandom();
cout << "A =\n" << A << '\n' << endl;
cout << "A(2..3,:) =\n" << A.middleRows(2,2) << endl;
return 0;
}
|
Check the dependencies of the project with bii deps:
$ bii deps
INFO: Processing changes...
your_user/eigen_example depends on:
system:
iostream
unresolved:
Eigen/Core
Edit the biicode.conf file generated in the project folder. Add your [requirements]
depending on the version you want and map your [includes]
:
[requirements]
eigen/eigen: 6
[includes]
Eigen/*: eigen/eigen
Check again with bii deps to show all dependencies are now resolved.
Now, build and run the code.
$ bii build
$ cd bin
$ # run executable
A =
-16343 -660 -10679 -15893 16007
2083 -4906 11761 -13389 -1780
-10050 12974 6897 -4442 -12482
10116 10578 443 -11557 -16231
2785 8080 -6423 -10948 -16092
A(2..3,:) =
-10050 12974 6897 -4442 -12482
10116 10578 443 -11557 -16231
You can check all the Eigen examples uploaded in biicode and execute any of them, just have to open examples/eigen block.
Create a project and open the examples:
~$ bii init eigen_example
~$ cd eigen_example
~$ bii open examples/eigen
~$ bii build
Execute any you want, for example, show the matrix’s middle rows:
~/eigen_sample$ bin/examples_eigen_DenseBase_middleRows_int
A =
-16343 -660 -10679 -15893 16007
2083 -4906 11761 -13389 -1780
-10050 12974 6897 -4442 -12482
10116 10578 443 -11557 -16231
2785 8080 -6423 -10948 -16092
A(2..3,:) =
-10050 12974 6897 -4442 -12482
10116 10578 443 -11557 -16231