49 #include <visp3/core/vpTranslationVector.h> 51 template <
typename Type>
bool test(
const std::string &s,
const vpArray2D<Type> &A,
const std::vector<Type> &bench)
53 static unsigned int cpt = 0;
54 std::cout <<
"** Test " << ++cpt << std::endl;
55 std::cout << s <<
"(" << A.
getRows() <<
"," << A.
getCols() <<
") = \n" << A << std::endl;
56 if (bench.size() != A.
size()) {
57 std::cout <<
"Test fails: bad size wrt bench" << std::endl;
60 for (
unsigned int i = 0; i < A.
size(); i++) {
61 if (std::fabs(A.
data[i] - bench[i]) > std::fabs(A.
data[i]) * std::numeric_limits<double>::epsilon()) {
62 std::cout <<
"Test fails: bad content" << std::endl;
75 std::vector<double> bench;
76 if (test(
"A", A, bench) ==
false)
83 std::vector<double> bench(12);
84 for (
unsigned int i = 0; i < 3; i++) {
85 for (
unsigned int j = 0; j < 4; j++) {
86 A[i][j] = (double)(i + j);
87 bench[i * 4 + j] = (double)(i + j);
90 if (test(
"A", A, bench) ==
false)
94 if (test(
"B", B, bench) ==
false)
96 std::cout <<
"Min/Max: " << B.getMinValue() <<
" " << B.getMaxValue() << std::endl;
101 std::vector<double> bench1(12, 2);
102 if (test(
"A", A, bench1) ==
false)
106 std::vector<double> bench2(30, 0);
107 if (test(
"A", A, bench2) ==
false)
111 std::vector<double> bench3(30, -2);
112 if (test(
"A", A, bench3) ==
false)
120 std::vector<float> bench;
121 if (test(
"A", A, bench) ==
false)
128 std::vector<float> bench(12);
129 for (
unsigned int i = 0; i < 3; i++) {
130 for (
unsigned int j = 0; j < 4; j++) {
131 A[i][j] = (float)(i + j);
132 bench[i * 4 + j] = (float)(i + j);
135 if (test(
"A", A, bench) ==
false)
139 if (test(
"B", B, bench) ==
false)
141 std::cout <<
"Min/Max: " << B.getMinValue() <<
" " << B.getMaxValue() << std::endl;
146 std::vector<float> bench1(12, 2);
147 if (test(
"A", A, bench1) ==
false)
151 std::vector<float> bench2(30, 0);
152 if (test(
"A", A, bench2) ==
false)
156 std::vector<float> bench3(30, -2);
157 if (test(
"A", A, bench3) ==
false)
162 std::cout <<
"\nTest Hadamard product" << std::endl;
167 for (
unsigned int i = 0; i < A1.size(); i++) {
176 std::cout <<
"A1:\n" << A1 << std::endl;
177 std::cout <<
"\nA2:\n" << A2 << std::endl;
178 A2 = A1.hadamard(A2);
179 std::cout <<
"\nRes:\n" << A2 << std::endl;
181 std::cout <<
"\nR1:\n" << R1 << std::endl;
182 std::cout <<
"\nR2:\n" << R2 << std::endl;
183 R2 = R1.hadamard(R2);
184 std::cout <<
"\nRes:\n" << R2 << std::endl;
186 std::cout <<
"\nC1:\n" << C1 << std::endl;
187 std::cout <<
"\nC2:\n" << C2 << std::endl;
188 C2 = C1.hadamard(C2);
189 std::cout <<
"\nRes:\n" << C2 << std::endl;
191 std::cout <<
"All tests succeed" << std::endl;
Implementation of row vector and the associated operations.
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true, const bool recopy_=true)
Type * data
Address of the first element of the data array.
Implementation of a generic 2D array used as vase class of matrices and vectors.
unsigned int size() const
Return the number of elements of the 2D array.
unsigned int getCols() const
unsigned int getRows() const
Implementation of column vector and the associated operations.