Skip to content

Commit

Permalink
simplify finite check, update metriqc
Browse files Browse the repository at this point in the history
  • Loading branch information
tilsche committed Apr 18, 2019
1 parent 07e4fb4 commit 076679a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/metricq
Submodule metricq updated 1 files
+1 −1 src/chrono.cpp
28 changes: 13 additions & 15 deletions src/timesync/fft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ using complex_type = std::complex<double>;

static_assert(sizeof(complex_type) == sizeof(fftw_complex), "You're fucked.");

inline bool my_isfinite(complex_type z)
inline void check_finite(complex_type z)
{
return std::isfinite(z.real()) && std::isfinite(z.imag());
if (!(std::isfinite(z.real()) && std::isfinite(z.imag())))
{
throw std::runtime_error("Infinite complex value");
}
}

inline bool my_isfinite(double a)
inline void check_finite(double a)
{
return std::isfinite(a);
if (!std::isfinite(a))
{
throw std::runtime_error("Infinite value");
}
}

template <typename T>
Expand Down Expand Up @@ -109,24 +115,16 @@ class FFTBase
return out_ + out_size();
}

bool isfinite()
void check_finite()
{
for (auto it = in_begin(); it != in_end(); ++it)
{
if (!my_isfinite(*it))
{
return false;
}
::check_finite(*it);
}

for (auto it = out_begin(); it != out_end(); ++it)
{
if (!my_isfinite(*it))
{
return false;
}
::check_finite(*it);
}
return true;
}

protected:
Expand Down
20 changes: 4 additions & 16 deletions src/timesync/shifter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ class Shifter
assert(std::distance(right_begin, right_end) == size_);

fft_(left_begin, left_end);
if (!fft_.isfinite())
{
throw std::runtime_error("left is not finite");
}
fft_.check_finite();
assert(std::distance(fft_.out_begin(), fft_.out_end()) ==
type_size<complex_type>(extended_size_));

std::copy(fft_.out_begin(), fft_.out_end(), tmp_.begin());

fft_(right_begin, right_end);
if (!fft_.isfinite())
{
throw std::runtime_error("right is not finite");
}
fft_.check_finite();
assert(std::distance(fft_.out_begin(), fft_.out_end()) ==
type_size<complex_type>(extended_size_));

Expand All @@ -43,19 +37,13 @@ class Shifter
// complex conjugate
other.imag(-other.imag());
tmp_[i] *= other;
if (!my_isfinite(tmp_[i]))
{
throw std::runtime_error("product is not finite");
}
check_finite(tmp_[i]);
}

ifft_(tmp_.begin(), tmp_.end());
assert(std::distance(ifft_.out_begin(), ifft_.out_end()) == extended_size_);

if (!ifft_.isfinite())
{
throw std::runtime_error("cross-correlation is not finite");
}
ifft_.check_finite();

auto it = std::max_element(ifft_.out_begin(), ifft_.out_end(), [](auto a, auto b) {
if (!std::isfinite(a) || !std::isfinite(b))
Expand Down

0 comments on commit 076679a

Please sign in to comment.