MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / check_results

Function check_results

compute/example/simple_moving_average.cpp:56–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56bool check_results(const std::vector<float>& values, const std::vector<float>& smoothValues, unsigned int wSize)
57{
58 int size = values.size();
59 if(size != (int)smoothValues.size()) return false;
60
61 int semiWidth = wSize/2;
62
63 bool ret = true;
64 for(int idx = 0 ; idx < size ; ++idx)
65 {
66 int start = (std::max)(idx - semiWidth,0);
67 int end = (std::min)(idx + semiWidth,size-1);
68 float res = 0;
69 for(int j = start ; j <= end ; ++j)
70 {
71 res+= values[j];
72 }
73
74 res /= float(end - start +1);
75
76 if(std::abs(res-smoothValues[idx]) > 1e-3)
77 {
78 std::cout << "idx = " << idx << " -- expected = " << res << " -- result = " << smoothValues[idx] << std::endl;
79 ret = false;
80 }
81 }
82
83 return ret;
84}
85
86// generate a uniform law over [0,10]
87float myRand()

Callers 1

mainFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected