Skip to content
Snippets Groups Projects
Commit 00301596 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

assert in FT

parent 015b32e0
No related branches found
No related tags found
1 merge request!456manual corrections following clang-tidy, ctd
......@@ -136,4 +136,4 @@ Checks: '*,
'
# note the closing quotation mark
\ No newline at end of file
# keep the closing quotation mark
\ No newline at end of file
......@@ -14,11 +14,9 @@
// ************************************************************************************************
#include "Base/Math/FourierTransform.h"
#include "Base/Util/Assert.h"
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <stdexcept>
FourierTransform::FourierTransform() = default;
......@@ -64,15 +62,17 @@ void FourierTransform::fft(const double2d_t& source, double2d_t& result)
double* ptr = ws.out_fftw;
result.clear();
const size_t nh = ws.h_fftw;
// Resize the array for holding the FT output to correct dimensions
result.resize(static_cast<size_t>(ws.h_fftw),
result.resize(nh,
std::vector<double>(static_cast<size_t>(ws.w_fftw)));
// Storing FT output
for (size_t i = 0; i < static_cast<size_t>(ws.h_fftw); i++) {
size_t k = static_cast<size_t>(ws.h_fftw) - i;
for (size_t i = 0; i < nh; i++) {
size_t k = nh - i;
if (i == 0)
k -= static_cast<size_t>(ws.h_fftw);
k -= nh;
for (size_t j = 0; j < static_cast<size_t>(ws.w_fftw / 2 + 1); j++) {
result[i][j] = *ptr;
size_t l = static_cast<size_t>(ws.w_fftw) - j;
......@@ -105,10 +105,9 @@ void FourierTransform::fftshift(double2d_t& result) const
std::rotate(result.begin(), result.begin() + static_cast<int>(row_shift), result.end());
// Second, shifting the cols
for (size_t i = 0; i < static_cast<size_t>(ws.h_fftw); i++) {
for (size_t i = 0; i < static_cast<size_t>(ws.h_fftw); i++)
std::rotate(result[i].begin(), result[i].begin() + static_cast<int>(col_shift),
result[i].end());
}
}
/* ************************************************************************* */
......@@ -123,9 +122,7 @@ void FourierTransform::fft(const double1d_t& source, double1d_t& result)
double2d_t result2d;
fft(source2d, result2d);
if (result2d.size() != 1)
throw std::runtime_error("FourierTransform::fft -> Panic in 1d");
ASSERT(result2d.size() == 1);
result = result2d[0];
}
......@@ -149,12 +146,8 @@ void FourierTransform::fftshift(double1d_t& result) const
/* ************************************************************************************ */
void FourierTransform::init(int h_src, int w_src)
{
if (!h_src || !w_src) {
std::ostringstream os;
os << "FourierTransform::init() -> Panic! Wrong dimensions " << h_src << " " << w_src
<< std::endl;
throw std::runtime_error(os.str());
}
ASSERT(h_src);
ASSERT(w_src);
ws.clear();
ws.h_src = h_src;
......@@ -173,9 +166,7 @@ void FourierTransform::init(int h_src, int w_src)
// ws.p_forw_src = fftw_plan_dft_r2c_2d(ws.h_fftw, ws.w_fftw, ws.in_src,
// static_cast<double*>(ws.out_src), FFTW_ESTIMATE);
if (ws.p_forw_src == nullptr)
throw std::runtime_error(
"FourierTransform::init() -> Error! Can't initialise p_forw_src plan.");
ASSERT(ws.p_forw_src);
}
/* ************************************************************************* */
......@@ -184,9 +175,8 @@ void FourierTransform::init(int h_src, int w_src)
void FourierTransform::fftw_forward_FT(const double2d_t& src)
{
if (ws.h_fftw <= 0 || ws.w_fftw <= 0)
throw std::runtime_error(
"FourierTransform::fftw_forward_FT() -> Panic! Initialization is missed.");
ASSERT(ws.h_fftw > 0);
ASSERT(ws.w_fftw > 0);
double *ptr, *ptr_end;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment