Coder Social home page Coder Social logo

efftw's Introduction

Eigen-FFTW

This repository is brand new and under heavy development!

E-FFTW is a modern C++20 wrapper library around FFTW for Eigen.

  • Supports 1D and 2D FFTs
  • Single header file: #include "efftw/efftw.hpp"

Including

include(FetchContent)

FetchContent_Declare(
  efftw
  GIT_REPOSITORY https://github.com/stephenberry/efftw
  GIT_TAG main
  GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(efftw)

target_link_libraries(${PROJECT_NAME} PRIVATE efftw::efftw)

Note: FFTW and Eigen dependencies are not included or installed by linking to efftw::efftw

Example

#include "efftw/efftw.hpp"

int main()
{
   // init_threads must be called before the library is used
   efftw::init_threads(4); // set FFTW to use 4 threads

   // build a complex matrix
   Eigen::MatrixXcd mat(N, N);

   std::mt19937_64 g{}; // random number generator
   std::uniform_real_distribution<double> dist{0.0, 1.0};

   for (size_t r = 0; r < N; ++r) {
      for (size_t c = 0; c < N; ++c) {
         mat(r, c) = { dist(g), dist(g) };
      }
   }
   
   efftw::f2 fft{mat}; // FFTW planning on construction (may be reused)
   fft(); // compute the FFT of mat in place
}

API

using namespace efftw;
// classes
f1{vec} // 1D forward FFT (not normalized)
f2{mat} // 2D forward FFT
i1{vec} // 1D inverse FFT (1/(rows) normalization)
i2{mat} // 2D inverse FFT (1/(rows * cols) normalization)

// functions
shift1(vec) // 1D forward FFT shift
shift2(mat) // 2D forward FFT shift
inv_shift1(vec) // 1D inverse FFT shift
inv_shift2(mat) // 2D inverse FFT shift

Important!

E-FFTW classes take references to Eigen types. Do not delete the matrix or resize it without rebuilding the EFFTW class.

The E-FFTW classes maintain the FFTW plan, which is deleted in the E-FFTW class destructors. The classes are used to keep the plan alive and allow the same matrix memory to be used multiple times. It is inefficient to rebuild the plan, but the plan needs to be rebuilt if the size of the matrix or vector changes.

Alias Type Deduction

// For clang, alias type deduction is not yet supported, so you will need to write:
efftw::f2<decltype(mat)> fft{mat};

efftw's People

Contributors

stephenberry avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.