# Which library to use in C++ for fast DCT's?

I need to apply a 1D type-II DCT (Discrete Cosine Transform) to each column of a matrix while normalizing the result in C++. Effectively, I want to multiply my matrix with an orthogonal type-II DCT-matrix (while avoiding the performance cost of matrix multiplication, of course).

Since this seems like an important computational kernel in many applications, isn't there a highly optimized library for this purpose out there? After searching for a bit I can find a couple of implementations, but I don't know if they're good. I was expecting a function somewhere in a well-known library such as Boost or Eigen. After all, in Python everything I need to do is this (using SciPy): dct(x, norm='ortho')

• What do you mean by DCT? Discrete Cosine Transform? I would strongly suggest you always define an acronym when you first use it, just because you know what it means doesn't mean everybody else does – Ian Bush Sep 25 '20 at 16:00
• FFTW (fftw.org) is one of the leading c++ FFT libraries and is pretty easy to use. I would also try Intel's MKL FFT routines (which include wrappers for FFTW), as you may find other related linear algebra utilities to solve your problem. – Charlie S Sep 25 '20 at 16:00
• Here is a related post using FFTW for DCT stackoverflow.com/questions/37530613/… – Charlie S Sep 25 '20 at 16:10
• As @CharlieS mentioned, MKL is frequently used in HPC for FFT computations. – Mansoor Sep 26 '20 at 15:02
• @CharlieS I concur to FFTW being a very sensible choice. A word of caution concerning MKL wrappers: some of them are empty (i.e. the planner would return an empty plan, without warning). Related to this question, this is the case for the multidimensional DCTs (the planner of which is empty in MKL FFTW). source : software.intel.com/content/www/us/en/develop/documentation/… – BenBoulderite Oct 1 '20 at 12:26