Eigen (C++ library): Difference between revisions

From David's Wiki
No edit summary
Line 1: Line 1:
Eigen is a template header-only C++ linear algebra library. It is one of the fastest and most popular.
Eigen is a template header-only C++ linear algebra library. You can think of it as as [[numpy]] for C++.


[http://eigen.tuxfamily.org/index.php?title=Main_Page Website]
[http://eigen.tuxfamily.org/index.php?title=Main_Page Website]
Line 29: Line 29:
[https://arxiv.org/abs/0909.4061 Finding structure with randomness paper]<br>
[https://arxiv.org/abs/0909.4061 Finding structure with randomness paper]<br>
[https://research.fb.com/blog/2014/09/fast-randomized-svd/ Facebook Blog post]
[https://research.fb.com/blog/2014/09/fast-randomized-svd/ Facebook Blog post]
==Unsupported==
===FFT===
https://eigen.tuxfamily.org/dox/unsupported/group__FFT__Module.html
This uses either fftw (default), Intel oneMKL, or kissfft (on older versions) under the hood.

Revision as of 20:10, 16 April 2024

Eigen is a template header-only C++ linear algebra library. You can think of it as as numpy for C++.

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 or -march=skylake if distributing to relatively modern (since ~2015) cpus.
    • 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
  • -O3 to enable optimizations

Data to Eigen

You can use Eigen::Map to create an eigen view for your existing data. This works with aligned or unaligned data, row-order or column-order, and different strides.
See Eigen: Interfacing with raw buffers for an example.

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

Unsupported

FFT

https://eigen.tuxfamily.org/dox/unsupported/group__FFT__Module.html This uses either fftw (default), Intel oneMKL, or kissfft (on older versions) under the hood.