Skip to content

Commit

Permalink
fix max fft size fiasco (#281)
Browse files Browse the repository at this point in the history
* fix max fft size fiasco
* Remove redundant(?) function
* FFT: Consistent noexcept in move for FFTSeutp -> FFT
  • Loading branch information
weefuzzy authored Oct 12, 2024
1 parent d44b5ea commit 3ceddcd
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions include/algorithms/util/FFT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ under the European Union’s Horizon 2020 research and innovation programme
#include "../../data/FluidMemory.hpp"
#include <Eigen/Core>
#include <fft/fft.hpp>
#include <optional>

namespace fluid {
namespace algorithm {
Expand All @@ -38,8 +39,8 @@ class FFTSetup
FFTSetup(FFTSetup const&) = delete;
FFTSetup& operator=(FFTSetup const&) = delete;

FFTSetup(FFTSetup&& other) { *this = std::move(other); };
FFTSetup& operator=(FFTSetup&& other)
FFTSetup(FFTSetup&& other) noexcept { *this = std::move(other); };
FFTSetup& operator=(FFTSetup&& other) noexcept
{
using std::swap;
swap(mMaxSize, other.mMaxSize);
Expand All @@ -62,13 +63,13 @@ class FFT
public:
using MapXcd = Eigen::Map<Eigen::ArrayXcd>;

static void setup() { getFFTSetup(); }

FFT() = delete;

FFT(index size, Allocator& alloc = FluidDefaultAllocator()) noexcept
: mMaxSize(size), mSize(size), mFrameSize(size / 2 + 1),
mLog2Size(static_cast<index>(std::log2(size))), mSetup(getFFTSetup()),
mLog2Size(static_cast<index>(std::log2(size))),
mSetup(getFFTSetup(*this, size)),
mRealBuffer(asUnsigned(mFrameSize), alloc),
mImagBuffer(asUnsigned(mFrameSize), alloc),
mOutputBuffer(asUnsigned(mFrameSize), alloc)
Expand Down Expand Up @@ -106,11 +107,18 @@ class FFT
return {mOutputBuffer.data(), mFrameSize};
}

private:
std::optional<impl::FFTSetup> mLocalSetup;
protected:
static htl::setup_type<double> getFFTSetup()
{
static const impl::FFTSetup static_setup(65536);
return static_setup();
static constexpr index default_max = 65536;
static htl::setup_type<double> getFFTSetup(FFT& _this, index size)
{
static const impl::FFTSetup static_setup(default_max);
if(size <= default_max) return static_setup();
else {
_this.mLocalSetup = std::optional<impl::FFTSetup>(size);
return _this.mLocalSetup->operator()();
}
}

index mMaxSize{16384};
Expand All @@ -127,6 +135,7 @@ class FFT
rt::vector<std::complex<double>> mOutputBuffer;
};


class IFFT : public FFT
{

Expand Down

0 comments on commit 3ceddcd

Please sign in to comment.