Eigen (C++ library): Difference between revisions

From David's Wiki
Line 8: Line 8:
For optimal performance, I recommend using the following flags when compiling.<br>
For optimal performance, I recommend using the following flags when compiling.<br>
====GCC====
====GCC====
*<code>-mfma</code> Enable fused multiply add
*<code>-march=native</code> and <code>-mtune=native</code> if running only locally
*<code>-mavx2</code> Enable avx2 vector instructions
**Otherwise, at a minimum
**<code>-mfma</code> Enable fused multiply add
**<code>-mavx2</code> Enable avx2 vector instructions
*<code>-DEIGEN_NO_DEBUG</code> Set preprocessor define for eigen optimizations
*<code>-DEIGEN_NO_DEBUG</code> Set preprocessor define for eigen optimizations
*<code>-fopenmp</code> OpenMP parallel execution
*<code>-fopenmp</code> OpenMP parallel execution

Revision as of 18:14, 10 February 2022

Eigen is a template header-only C++ linear algebra library. It is one of the fastest and most popular.

Website

Usage

Compilation

Reference
For optimal performance, I recommend using the following flags when compiling.

GCC

  • -march=native and -mtune=native if running only locally
    • Otherwise, at a minimum
    • -mfma Enable fused multiply add
    • -mavx2 Enable avx2 vector instructions
  • -DEIGEN_NO_DEBUG Set preprocessor define for eigen optimizations
  • -fopenmp OpenMP parallel execution

Data to Eigen

You can use Eigen::Map to create an eigen view for your existing data.

Math

SVD

Eigen comes with a few SVD implementations in its SVD Module.
If you only need low-rank approximations then you may be interested in randomized SVD.
This can be 10-20x faster when calculating low-rank approximations on large matrices.
Github Implementation
Finding structure with randomness paper
Facebook Blog post