48 #include <visp3/core/vpMath.h> 49 #include <visp3/core/vpRowVector.h> 51 bool test(
const std::string &s,
const vpRowVector &v,
const std::vector<double> &bench)
53 static unsigned int cpt = 0;
54 std::cout <<
"** Test " << ++cpt << std::endl;
55 std::cout << s <<
"(" << v.
getRows() <<
"," << v.
getCols() <<
") = [" << v <<
"]" << std::endl;
56 if (bench.size() != v.
size()) {
57 std::cout <<
"Test fails: bad size wrt bench" << std::endl;
60 for (
unsigned int i = 0; i < v.
size(); i++) {
61 if (std::fabs(v[i] - bench[i]) > std::fabs(v[i]) * std::numeric_limits<double>::epsilon()) {
62 std::cout <<
"Test fails: bad content" << std::endl;
79 std::vector<double> bench1(4, 3);
80 if (test(
"v", v, bench1) ==
false)
82 std::vector<double> bench2(4, 3. / 6);
84 if (test(
"v", v, bench2) ==
false)
88 std::vector<double> bench3(5, 0);
89 if (test(
"v", v, bench3) ==
false)
95 std::vector<double> bench1(4);
96 for (
unsigned int i = 0; i < v.
size(); i++) {
98 bench1[i] = (double)i;
100 if (test(
"v", v, bench1) ==
false)
105 std::vector<double> bench2;
108 if (test(
"w", w, bench2) ==
false)
111 std::vector<double> bench3;
117 for (
size_t i = 0; i < 4; i++)
121 if (test(
"r2", r2, bench3) ==
false)
126 std::vector<double> bench(4);
127 for (
unsigned int i = 0; i < M.getCols(); i++) {
131 if (test(
"M", M, bench) ==
false)
135 if (test(
"v", v, bench) ==
false)
138 if (test(
"w", w, bench) ==
false)
141 if (test(
"z1", z1, bench) ==
false)
144 if (test(
"z2", z2, bench) ==
false)
152 std::vector<double> bench1;
160 if (test(
"w", w, bench1) ==
false)
164 if (test(
"x", x, bench1) ==
false)
167 std::vector<float> bench2;
172 if (test(
"y1", y1, bench1) ==
false)
175 if (test(
"y2", y2, bench1) ==
false)
181 std::vector<double> bench(3, -1);
183 if (test(
"r2", r2, bench) ==
false)
187 if (test(
"r2", r2, bench) ==
false)
190 std::vector<double> bench3(7, 1);
191 bench3[3] = bench3[4] = bench3[5] = -1;
193 if (test(
"r3", r3, bench3) ==
false)
197 if (test(
"r1", r1, bench3) ==
false)
204 std::vector<double> bench(3, 6);
205 if (test(
"r", r, bench) ==
false)
208 if (test(
"r1", r1, bench) ==
false)
215 std::vector<double> bench(3, -2);
216 if (test(
"r", r, bench) ==
false)
219 if (test(
"r1", r1, bench) ==
false)
227 std::vector<double> bench(5, 5);
228 if (test(
"r", r, bench) ==
false)
246 std::cout <<
"** Test mean" << std::endl;
249 std::cout <<
"Test fails: bad mean " << res << std::endl;
253 std::cout <<
"** Test stdev" << std::endl;
256 std::cout <<
"Test fails: bad stdev " << res << std::endl;
260 std::cout <<
"** Test stdev(bessel)" << std::endl;
263 std::cout <<
"Test fails: bad stdev(bessel) " << res << std::endl;
267 std::cout <<
"** Test median" << std::endl;
270 std::cout <<
"Test fails: bad median " << res << std::endl;
275 std::cout <<
"** Test median (odd)" << std::endl;
279 std::cout <<
"Test fails: bad median (odd) " << res << std::endl;
282 std::cout <<
"r: [" << r <<
"]" << std::endl;
283 r.
print(std::cout, 8,
"r");
287 std::cout <<
"** Test conversion to/from std::vector" << std::endl;
288 std::vector<double> std_vector(5);
289 for (
size_t i = 0; i < std_vector.size(); i++) {
290 std_vector[i] = (double) i;
293 if (test(
"v", v, std_vector) ==
false)
298 if (test(
"v", v, std_vector) ==
false)
301 std::cout <<
"All tests succeed" << std::endl;
Implementation of a matrix and operations on matrices.
vpRowVector & normalize()
static double median(const vpRowVector &v)
void init(const vpRowVector &v, unsigned int c, unsigned int ncols)
Implementation of row vector and the associated operations.
std::vector< double > toStdVector()
static bool equal(double x, double y, double s=0.001)
vpRowVector extract(unsigned int c, unsigned int rowsize) const
static double mean(const vpRowVector &v)
static double stdev(const vpRowVector &v, const bool useBesselCorrection=false)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getCols() const
unsigned int getRows() const
void resize(const unsigned int i, const bool flagNullify=true)
int print(std::ostream &s, unsigned int length, char const *intro=0) const