FNFT
fnft__misc.h
Go to the documentation of this file.
1 /*
2 * This file is part of FNFT.
3 *
4 * FNFT is free software; you can redistribute it and/or
5 * modify it under the terms of the version 2 of the GNU General
6 * Public License as published by the Free Software Foundation.
7 *
8 * FNFT is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Contributors:
17 * Sander Wahls (TU Delft) 2017-2018.
18 * Shrinivas Chimmalgi (TU Delft) 2019-2020.
19 */
20 
27 #ifndef FNFT__MISC_H
28 #define FNFT__MISC_H
29 
30 #include "fnft.h"
31 #include <string.h>
32 
42 void fnft__misc_print_buf(const FNFT_INT len, FNFT_COMPLEX const * const buf,
43  char const * const varname);
44 
57  FNFT_COMPLEX const * const vec_numer, FNFT_COMPLEX const * const vec_exact);
58 
71  FNFT_COMPLEX const * const vecA, const FNFT_UINT lenB,
72  FNFT_COMPLEX const * const vecB);
73 
83 
97  const FNFT_REAL a, const FNFT_REAL b);
98 
123  FNFT_COMPLEX * const rearrange_as_well,
124  FNFT_REAL const * const bounding_box);
125 
126 
140  const FNFT_REAL tol_im);
141 
159  FNFT_COMPLEX * const rearrange_as_well,
160  FNFT_REAL const * const bounding_box);
161 
175  FNFT_REAL tol);
176 
199  FNFT_UINT * const Dsub_ptr, FNFT_COMPLEX ** qsub_ptr,
200  FNFT_UINT * const first_last_index);
201 
211 
220 
241 FNFT_INT fnft__misc_resample(const FNFT_UINT D, const FNFT_REAL eps_t, FNFT_COMPLEX const * const q,
242  const FNFT_REAL delta, FNFT_COMPLEX *const q_new);
243 
257 static inline void fnft__misc_mat_mult_proto(const FNFT_UINT N, FNFT_COMPLEX * const U,
258  FNFT_COMPLEX *const T, FNFT_COMPLEX *const TM){
259  FNFT_UINT c1, c2, c3;
260  FNFT_COMPLEX sum = 0;
261  for (c1 = 0; c1 < N; c1++) {
262  for (c2 = 0; c2 < N; c2++) {
263  for (c3 = 0; c3 < N; c3++) {
264  sum = sum + U[c1*N+c3]*T[c3*N+c2];
265  }
266  TM[c1*N+c2] = sum;
267  sum = 0;
268  }
269  }
270 
271  return;
272 }
273 
285 static inline void fnft__misc_mat_mult_2x2(FNFT_COMPLEX * const U,
286  FNFT_COMPLEX *const T){
287 
288  FNFT_COMPLEX TM[4] = { 0 };
289  fnft__misc_mat_mult_proto(2, U, T, &TM[0]);
290  memcpy(T,TM,4*sizeof(FNFT_COMPLEX));
291 
292  return;
293 }
294 
306 static inline void fnft__misc_mat_mult_4x4(FNFT_COMPLEX * const U,
307  FNFT_COMPLEX *const T){
308 
309  FNFT_COMPLEX TM[16] = { 0 };
310  fnft__misc_mat_mult_proto(4, U, T, &TM[0]);
311  memcpy(T,TM,16*sizeof(FNFT_COMPLEX));
312 
313  return;
314 }
315 
327 static inline FNFT_REAL fnft__misc_legendre_poly(const FNFT_UINT n, const FNFT_REAL x){
328  FNFT_UINT i;
329  FNFT_REAL P, P_1, P_2;
330  if (n == 0)
331  P = 1;
332  else if (n == 1)
333  P = x;
334  else{
335  P_1 = x;
336  P_2 = 1;
337  for (i = 2; i <= n; i++) {
338  P = (2.0*i-1)*x*P_1/i -(i-1.0)*P_2/i;
339  P_2 = P_1;
340  P_1 = P;
341  }
342  }
343  return P;
344 }
345 
346 #ifdef FNFT_ENABLE_SHORT_NAMES
347 #define misc_print_buf(...) fnft__misc_print_buf(__VA_ARGS__)
348 #define misc_rel_err(...) fnft__misc_rel_err(__VA_ARGS__)
349 #define misc_hausdorff_dist(...) fnft__misc_hausdorff_dist(__VA_ARGS__)
350 #define misc_sech(...) fnft__misc_sech(__VA_ARGS__)
351 #define misc_l2norm2(...) fnft__misc_l2norm2(__VA_ARGS__)
352 #define misc_filter(...) fnft__misc_filter(__VA_ARGS__)
353 #define misc_filter_inv(...) fnft__misc_filter_inv(__VA_ARGS__)
354 #define misc_filter_nonreal(...) fnft__misc_filter_nonreal(__VA_ARGS__)
355 #define misc_merge(...) fnft__misc_merge(__VA_ARGS__)
356 #define misc_downsample(...) fnft__misc_downsample(__VA_ARGS__)
357 #define misc_CSINC(...) fnft__misc_CSINC(__VA_ARGS__)
358 #define misc_nextpowerof2(...) fnft__misc_nextpowerof2(__VA_ARGS__)
359 #define misc_resample(...) fnft__misc_resample(__VA_ARGS__)
360 #define misc_mat_mult_proto(...) fnft__misc_mat_mult_proto(__VA_ARGS__)
361 #define misc_mat_mult_2x2(...) fnft__misc_mat_mult_2x2(__VA_ARGS__)
362 #define misc_mat_mult_4x4(...) fnft__misc_mat_mult_4x4(__VA_ARGS__)
363 #define misc_legendre_poly(...) fnft__misc_legendre_poly(__VA_ARGS__)
364 
365 #endif
366 
367 #endif
FNFT_INT
int32_t FNFT_INT
Definition: fnft_numtypes.h:56
FNFT_UINT
size_t FNFT_UINT
Definition: fnft_numtypes.h:62
fnft__misc_rel_err
FNFT_REAL fnft__misc_rel_err(const FNFT_INT len, FNFT_COMPLEX const *const vec_numer, FNFT_COMPLEX const *const vec_exact)
Relative l1 error between two vectors.
fnft__misc_nextpowerof2
FNFT_UINT fnft__misc_nextpowerof2(const FNFT_UINT number)
Closest larger or equal number that is a power of two.
fnft__misc_resample
FNFT_INT fnft__misc_resample(const FNFT_UINT D, const FNFT_REAL eps_t, FNFT_COMPLEX const *const q, const FNFT_REAL delta, FNFT_COMPLEX *const q_new)
Resamples an array.
fnft__misc_mat_mult_proto
static void fnft__misc_mat_mult_proto(const FNFT_UINT N, FNFT_COMPLEX *const U, FNFT_COMPLEX *const T, FNFT_COMPLEX *const TM)
Multiples two square matrices of size N.
Definition: fnft__misc.h:257
fnft__misc_downsample
FNFT_INT fnft__misc_downsample(const FNFT_UINT D, FNFT_COMPLEX const *const q, FNFT_UINT *const Dsub_ptr, FNFT_COMPLEX **qsub_ptr, FNFT_UINT *const first_last_index)
Downsamples an array.
fnft__misc_sech
FNFT_COMPLEX fnft__misc_sech(FNFT_COMPLEX Z)
Hyperbolic secant.
fnft__misc_hausdorff_dist
FNFT_REAL fnft__misc_hausdorff_dist(const FNFT_UINT lenA, FNFT_COMPLEX const *const vecA, const FNFT_UINT lenB, FNFT_COMPLEX const *const vecB)
Hausdorff distance between two vectors.
fnft__misc_l2norm2
FNFT_REAL fnft__misc_l2norm2(const FNFT_UINT N, FNFT_COMPLEX const *const Z, const FNFT_REAL a, const FNFT_REAL b)
Squared l2 norm.
fnft__misc_filter_nonreal
FNFT_INT fnft__misc_filter_nonreal(FNFT_UINT *N_ptr, FNFT_COMPLEX *const vals, const FNFT_REAL tol_im)
Filter array based on specified tolerance.
FNFT_COMPLEX
double complex FNFT_COMPLEX
Definition: fnft_numtypes.h:47
fnft__misc_legendre_poly
static FNFT_REAL fnft__misc_legendre_poly(const FNFT_UINT n, const FNFT_REAL x)
This routine returns the nth degree Legendre polynomial at x.
Definition: fnft__misc.h:327
fnft__misc_merge
FNFT_INT fnft__misc_merge(FNFT_UINT *N_ptr, FNFT_COMPLEX *const vals, FNFT_REAL tol)
Merges elements in an array with distance lower than tol.
FNFT_REAL
double FNFT_REAL
Definition: fnft_numtypes.h:40
fnft__misc_filter
FNFT_INT fnft__misc_filter(FNFT_UINT *const N, FNFT_COMPLEX *const vals, FNFT_COMPLEX *const rearrange_as_well, FNFT_REAL const *const bounding_box)
Filters array by retaining elements inside a bounding box.
fnft__misc_print_buf
void fnft__misc_print_buf(const FNFT_INT len, FNFT_COMPLEX const *const buf, char const *const varname)
Helper function for debugging. Prints an array in MATLAB style.
fnft__misc_mat_mult_4x4
static void fnft__misc_mat_mult_4x4(FNFT_COMPLEX *const U, FNFT_COMPLEX *const T)
Multiples two square matrices of size 4.
Definition: fnft__misc.h:306
fnft__misc_filter_inv
FNFT_INT fnft__misc_filter_inv(FNFT_UINT *const N_ptr, FNFT_COMPLEX *const vals, FNFT_COMPLEX *const rearrange_as_well, FNFT_REAL const *const bounding_box)
Filters array by retaining elements outside a bounding box.
fnft__misc_mat_mult_2x2
static void fnft__misc_mat_mult_2x2(FNFT_COMPLEX *const U, FNFT_COMPLEX *const T)
Multiples two square matrices of size 2.
Definition: fnft__misc.h:285
fnft__misc_CSINC
FNFT_COMPLEX fnft__misc_CSINC(FNFT_COMPLEX x)
Sinc function for complex arguments.