File: test_fft.c

package info (click to toggle)
bart 0.9.00-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,040 kB
  • sloc: ansic: 116,116; python: 1,329; sh: 726; makefile: 639; javascript: 589; cpp: 106
file content (59 lines) | stat: -rw-r--r-- 1,735 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Copyright 2022. Uecker Lab. University Medical Center Göttingen.
 * All rights reserved. Use of this source code is governed by
 * a BSD-style license which can be found in the LICENSE file.
 *
 * Authors: Moritz Blumenthal
 */

#include <complex.h>

#include "misc/debug.h"
#include "num/multind.h"
#include "num/flpmath.h"
#include "num/fft.h"
#include "num/rand.h"

#include "utest.h"

static bool test_fftmod_optimize(int N, const long dims[N], unsigned long flags, bool inv)
{
	
	complex float* ptr1 = md_alloc(N, dims, CFL_SIZE);
	md_gaussian_rand(N, dims, ptr1);

	complex float* ptr2 = md_alloc(N, dims, CFL_SIZE);
	md_copy(N, dims, ptr2, ptr1, CFL_SIZE);

	(inv ? ifftmod : fftmod)(N, dims, flags, ptr1, ptr1);

	for (int i = 0; i < N; i++)
		(inv ? ifftmod : fftmod)(N, dims, flags & MD_BIT(i), ptr2, ptr2);
	
	float err = md_znrmse(N, dims, ptr1, ptr2);

	md_free(ptr1);
	md_free(ptr2);

	UT_ASSERT(err < UT_TOL);
}


static bool test_fftmod1(void) { return test_fftmod_optimize(4, MD_DIMS(16, 16, 1, 4), 7, false); }
static bool test_fftmod2(void) { return test_fftmod_optimize(4, MD_DIMS(16, 16, 4, 4), 7, false); }
static bool test_fftmod3(void) { return test_fftmod_optimize(4, MD_DIMS(16, 17, 4, 4), 7, false); }

static bool test_ifftmod1(void) { return test_fftmod_optimize(4, MD_DIMS(16, 16, 1, 4), 7, true); }
static bool test_ifftmod2(void) { return test_fftmod_optimize(4, MD_DIMS(16, 16, 4, 4), 7, true); }
static bool test_ifftmod3(void) { return test_fftmod_optimize(4, MD_DIMS(16, 17, 4, 4), 7, true); }




UT_REGISTER_TEST(test_fftmod1);
UT_REGISTER_TEST(test_fftmod2);
UT_REGISTER_TEST(test_fftmod3);

UT_REGISTER_TEST(test_ifftmod1);
UT_REGISTER_TEST(test_ifftmod2);
UT_REGISTER_TEST(test_ifftmod3);