Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
124 lines (81 sloc) 2.94 KB

Eigen

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.

Middle rows from a matrix

This example shows the way to generate a random matrix, print it and then print only he middle rows.

Create a project

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

.. literalinclude:: /_static/code/cpp/examples/eigen/DenseBase_middleRows_int.cpp
   :language: cpp
   :linenos:

Manage your dependencies

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.

Build the project

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

Open and build

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