46#include <visp3/core/vpTranslationVector.h>
48template <
typename Type>
bool test(
const std::string &s,
const vpArray2D<Type> &A,
const std::vector<Type> &bench)
50 static unsigned int cpt = 0;
51 std::cout <<
"** Test " << ++cpt << std::endl;
52 std::cout << s <<
"(" << A.
getRows() <<
"," << A.
getCols() <<
") = \n" << A << std::endl;
53 if (bench.size() != A.
size()) {
54 std::cout <<
"Test fails: bad size wrt bench" << std::endl;
57 for (
unsigned int i = 0; i < A.
size(); i++) {
58 if (std::fabs(A.
data[i] - bench[i]) > std::fabs(A.
data[i]) * std::numeric_limits<double>::epsilon()) {
59 std::cout <<
"Test fails: bad content" << std::endl;
72 std::vector<double> bench;
73 if (test(
"A", A, bench) ==
false)
80 std::vector<double> bench(12);
81 for (
unsigned int i = 0; i < 3; i++) {
82 for (
unsigned int j = 0; j < 4; j++) {
83 A[i][j] = (double)(i + j);
84 bench[i * 4 + j] = (double)(i + j);
87 if (test(
"A", A, bench) ==
false)
91 if (test(
"B", B, bench) ==
false)
93 std::cout <<
"Min/Max: " << B.getMinValue() <<
" " << B.getMaxValue() << std::endl;
98 std::vector<double> bench1(12, 2);
99 if (test(
"A", A, bench1) ==
false)
103 std::vector<double> bench2(30, 0);
104 if (test(
"A", A, bench2) ==
false)
108 std::vector<double> bench3(30, -2);
109 if (test(
"A", A, bench3) ==
false)
117 std::vector<float> bench;
118 if (test(
"A", A, bench) ==
false)
125 std::vector<float> bench(12);
126 for (
unsigned int i = 0; i < 3; i++) {
127 for (
unsigned int j = 0; j < 4; j++) {
128 A[i][j] = (float)(i + j);
129 bench[i * 4 + j] = (float)(i + j);
132 if (test(
"A", A, bench) ==
false)
136 if (test(
"B", B, bench) ==
false)
138 std::cout <<
"Min/Max: " << B.getMinValue() <<
" " << B.getMaxValue() << std::endl;
143 std::vector<float> bench1(12, 2);
144 if (test(
"A", A, bench1) ==
false)
148 std::vector<float> bench2(30, 0);
149 if (test(
"A", A, bench2) ==
false)
153 std::vector<float> bench3(30, -2);
154 if (test(
"A", A, bench3) ==
false)
159 std::cout <<
"\nTest Hadamard product" << std::endl;
164 for (
unsigned int i = 0; i < A1.size(); i++) {
173 std::cout <<
"A1:\n" << A1 << std::endl;
174 std::cout <<
"\nA2:\n" << A2 << std::endl;
175 A2 = A1.hadamard(A2);
176 std::cout <<
"\nRes:\n" << A2 << std::endl;
178 std::cout <<
"\nR1:\n" << R1 << std::endl;
179 std::cout <<
"\nR2:\n" << R2 << std::endl;
180 R2 = R1.hadamard(R2);
181 std::cout <<
"\nRes:\n" << R2 << std::endl;
183 std::cout <<
"\nC1:\n" << C1 << std::endl;
184 std::cout <<
"\nC2:\n" << C2 << std::endl;
185 C2 = C1.hadamard(C2);
186 std::cout <<
"\nRes:\n" << C2 << std::endl;
188 std::cout <<
"All tests succeed" << std::endl;
Implementation of a generic 2D array used as base class for matrices and vectors.
unsigned int getCols() const
Type * data
Address of the first element of the data array.
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getRows() const
Implementation of column vector and the associated operations.
Implementation of row vector and the associated operations.