-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest4.cc
More file actions
52 lines (45 loc) · 1.27 KB
/
test4.cc
File metadata and controls
52 lines (45 loc) · 1.27 KB
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
#include "main.h"
#include <algorithm>
#include <random>
#include <vector>
// Make sure output of naive versions and fast versions are identical
template<typename T>
void test4 (double mean, double variance)
{
const size_t M = 16;
const size_t N = 16;
const size_t K = 3;
vector<T> x (M * N);
// draw random values from a normal distribution
default_random_engine e;
std::normal_distribution<> n (mean, variance);
auto f = [&] { return n (e); };
generate (begin (x), end (x), f);
// compute average
vector<T> y1 = slow_average (x, M, N, K);
vector<T> y2 = fast_average (x, M, N, K);
verify (y1 == y2);
// compute variance
y1 = slow_variance (x, M, N, K);
y2 = fast_variance (x, M, N, K);
verify (y1 == y2);
// compute stddev
y1 = slow_stddev (x, M, N, K);
y2 = fast_stddev (x, M, N, K);
verify (y1 == y2);
// compute rms contrast
y1 = slow_rms_contrast (x, M, N, K);
y2 = fast_rms_contrast (x, M, N, K);
verify (y1 == y2);
}
void process ()
{
test4<char> (0, 10);
test4<unsigned char> (100, 10);
test4<short> (0, 10);
test4<unsigned short> (100, 10);
test4<int> (0, 10);
test4<unsigned int> (100, 10);
test4<long> (0, 10);
test4<unsigned long> (100, 10);
}