Tests/testDFT.cpp
/**
 * @param high_precision if true, use sin/cos with extra precision.
 *                       Generally, this is a good idea.
 */
@param high_precision if true, use sin/cos with extra precision.
Generally, this is a good idea.
@param high_precision if true use sin / cos with extra precision . Generally this is a good idea .
void create_dft_matrix(Complex::Array2D &arr, bool high_precision = true) {
  REQUIRE(arr.rows() > 0);
  REQUIRE(arr.rows() % 16 == 0);
  int const Dim = arr.rows();
  REQUIRE(Dim == arr.columns());
  float const precision = high_precision?1.5e-3f:6.0e-2f;
  auto check_acceptable_precision = [precision, Dim] (int r, int c, complex const &tmp) {
    double angle_lib = (2*M_PI*((float) (-r*c)) / Dim);
    complex tmp_lib((float) std::cos(angle_lib), (float) std::sin(angle_lib)); 
    INFO("r: " << r << ", c: " << c);
    INFO("tmp_lib: " << tmp_lib.dump() << ", tmp: " << tmp.dump());
    REQUIRE(abs(tmp_lib.re() - tmp.re()) < precision);
    REQUIRE(abs(tmp_lib.im() - tmp.im()) < precision);
  };
  for (int r = 0; r < Dim; ++r) {
    for (int c = 0; c < Dim; ++c) {
      float angle = ((float) (-r*c))/((float) Dim); 
      complex tmp(functions::cos(angle, high_precision), functions::sin(angle, high_precision));
      check_acceptable_precision(r, c, tmp);
      arr[r][c] = tmp;
    }
  }
}
void create_dft_matrix ( Complex :: Array2D & arr , bool high_precision = true ) { REQUIRE ( arr . rows ( ) > 0 ) ; REQUIRE ( arr . rows ( ) % 16 == 0 ) ; int const Dim = arr . rows ( ) ; REQUIRE ( Dim == arr . columns ( ) ) ; float const precision = high_precision ? 1.5e-3f : 6.0e-2f ; auto check_acceptable_precision = [ precision , Dim ] ( int r , int c , complex const & tmp ) { double angle_lib = ( 2 * M_PI * ( ( float ) ( - r * c ) ) / Dim ) ; complex tmp_lib ( ( float ) std :: cos ( angle_lib ) , ( float ) std :: sin ( angle_lib ) ) ; INFO ( " " << r << " " << c ) ; INFO ( " " << tmp_lib . dump ( ) << " " << tmp . dump ( ) ) ; REQUIRE ( abs ( tmp_lib . re ( ) - tmp . re ( ) ) < precision ) ; REQUIRE ( abs ( tmp_lib . im ( ) - tmp . im ( ) ) < precision ) ; } ; for ( int r = 0 ; r < Dim ; ++ r ) { for ( int c = 0 ; c < Dim ; ++ c ) { float angle = ( ( float ) ( - r * c ) ) / ( ( float ) Dim ) ; complex tmp ( functions :: cos ( angle , high_precision ) , functions :: sin ( angle , high_precision ) ) ; check_acceptable_precision ( r , c , tmp ) ; arr [ r ] [ c ] = tmp ; } } }
@param high_precision if true, use sin/cos with extra precision.
@param high_precision if true use sin / cos with extra precision .
// Check if precision of value is within an acceptable range // V3D lib function is compared against the CPU lib value //std::cout << tmp.dump(); // Use the V3DLib scalar value, this compares well with the GPU sin/cos