File: test_qform.c

package info (click to toggle)
bart-cuda 0.8.00-2
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm, sid
  • size: 7,752 kB
  • sloc: ansic: 100,267; python: 717; makefile: 576; sh: 564; cpp: 104
file content (69 lines) | stat: -rw-r--r-- 1,156 bytes parent folder | download | duplicates (3)
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
60
61
62
63
64
65
66
67
68
69
/* Copyright 2022. Martin Uecker.
 * All rights reserved. Use of this source code is governed by
 * a BSD-style license which can be found in the LICENSE file.
 *
 * Authors:
 * 	Martin Uecker
 */


#include <math.h>
#include <stdio.h>

#include "num/qform.h"

#include "utest.h"


static bool test_quadratic_fit(void)
{
	float qf[3] = { 3., -1., 0.4  };

	float angles[10];
	float val[10];

	for (int i = 0; i < 10; i++) {

		angles[i] = 2. * M_PI * i / 10.;
		val[i] = quadratic_form(qf, angles[i]);
	}

	float qf2[3];
	fit_quadratic_form(qf2, 10, angles, val);

	float d = powf(qf2[0] - qf[0], 2.)
		+ powf(qf2[1] - qf[1], 2.)
		+ powf(qf2[2] - qf[2], 2.);

	return (d < 1.E-12);
}

UT_REGISTER_TEST(test_quadratic_fit);


static bool test_harmonic_fit(void)
{
	float qf[3] = { 3., -1., 0.4  };

	float angles[10];
	float val[10];

	for (int i = 0; i < 10; i++) {

		angles[i] = 2. * M_PI * i / 10.;
		val[i] = harmonic(qf, angles[i]);
	}

	float qf2[3];
	fit_harmonic(qf2, 10, angles, val);

	float d = powf(qf2[0] - qf[0], 2.)
		+ powf(qf2[1] - qf[1], 2.)
		+ powf(qf2[2] - qf[2], 2.);

	return (d < 1.E-12);
}

UT_REGISTER_TEST(test_harmonic_fit);