43 #include <visp3/core/vpMath.h>
44 #include <visp3/core/vpRowVector.h>
46 #ifdef ENABLE_VISP_NAMESPACE
50 bool test(
const std::string &s,
const vpRowVector &v,
const std::vector<double> &bench)
52 static unsigned int cpt = 0;
53 std::cout <<
"** Test " << ++cpt << std::endl;
54 std::cout << s <<
"(" << v.
getRows() <<
"," << v.
getCols() <<
") = [" << v <<
"]" << std::endl;
55 if (bench.size() != v.
size()) {
56 std::cout <<
"Test fails: bad size wrt bench" << std::endl;
59 for (
unsigned int i = 0; i < v.
size(); i++) {
60 if (std::fabs(v[i] - bench[i]) > std::fabs(v[i]) * std::numeric_limits<double>::epsilon()) {
61 std::cout <<
"Test fails: bad content" << std::endl;
78 std::vector<double> bench1(4, 3);
79 if (test(
"v", v, bench1) ==
false)
81 std::vector<double> bench2(4, 3. / 6);
83 if (test(
"v", v, bench2) ==
false)
87 std::vector<double> bench3(5, 0);
88 if (test(
"v", v, bench3) ==
false)
94 std::vector<double> bench1(4);
95 for (
unsigned int i = 0; i < v.
size(); i++) {
97 bench1[i] = (double)i;
99 if (test(
"v", v, bench1) ==
false)
104 std::vector<double> bench2;
107 if (test(
"w", w, bench2) ==
false)
110 std::vector<double> bench3;
116 for (
size_t i = 0; i < 4; i++)
120 if (test(
"r2", r2, bench3) ==
false)
125 std::vector<double> bench(4);
126 for (
unsigned int i = 0; i < M.getCols(); i++) {
134 if (test(
"v", v, bench) ==
false)
137 if (test(
"w", w, bench) ==
false)
140 if (test(
"z1", z1, bench) ==
false)
143 if (test(
"z2", z2, bench) ==
false)
151 std::vector<double> bench1;
159 if (test(
"w", w, bench1) ==
false)
163 if (test(
"x", x, bench1) ==
false)
166 std::vector<float> bench2;
171 if (test(
"y1", y1, bench1) ==
false)
174 if (test(
"y2", y2, bench1) ==
false)
180 std::vector<double> bench(3, -1);
182 if (test(
"r2", r2, bench) ==
false)
186 if (test(
"r2", r2, bench) ==
false)
189 std::vector<double> bench3(7, 1);
190 bench3[3] = bench3[4] = bench3[5] = -1;
192 if (test(
"r3", r3, bench3) ==
false)
196 if (test(
"r1", r1, bench3) ==
false)
203 std::vector<double> bench(3, 6);
204 if (test(
"r", r, bench) ==
false)
207 if (test(
"r1", r1, bench) ==
false)
214 std::vector<double> bench(3, -2);
215 if (test(
"r", r, bench) ==
false)
218 if (test(
"r1", r1, bench) ==
false)
226 std::vector<double> bench(5, 5);
227 if (test(
"r", r, bench) ==
false)
245 std::cout <<
"** Test mean" << std::endl;
248 std::cout <<
"Test fails: bad mean " << res << std::endl;
252 std::cout <<
"** Test stdev" << std::endl;
255 std::cout <<
"Test fails: bad stdev " << res << std::endl;
259 std::cout <<
"** Test stdev(bessel)" << std::endl;
262 std::cout <<
"Test fails: bad stdev(bessel) " << res << std::endl;
266 std::cout <<
"** Test median" << std::endl;
269 std::cout <<
"Test fails: bad median " << res << std::endl;
274 std::cout <<
"** Test median (odd)" << std::endl;
278 std::cout <<
"Test fails: bad median (odd) " << res << std::endl;
281 std::cout <<
"r: [" << r <<
"]" << std::endl;
282 r.
print(std::cout, 8,
"r");
286 std::cout <<
"** Test conversion to/from std::vector" << std::endl;
287 std::vector<double> std_vector(5);
288 for (
size_t i = 0; i < std_vector.size(); i++) {
289 std_vector[i] = (double)i;
292 if (test(
"v", v, std_vector) ==
false)
297 if (test(
"v", v, std_vector) ==
false)
300 std::cout <<
"All tests succeed" << std::endl;
unsigned int getCols() const
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
static bool equal(double x, double y, double threshold=0.001)
Implementation of a matrix and operations on matrices.
Implementation of row vector and the associated operations.
void resize(unsigned int i, bool flagNullify=true)
static double mean(const vpRowVector &v)
void init(const vpRowVector &v, unsigned int c, unsigned int ncols)
vpRowVector & normalize()
static double median(const vpRowVector &v)
std::vector< double > toStdVector() const
static double stdev(const vpRowVector &v, bool useBesselCorrection=false)
vpRowVector extract(unsigned int c, unsigned int rowsize) const
int print(std::ostream &s, unsigned int length, char const *intro=0) const