| 209 | // mat is symmetric to roughly halve the number of operations. |
| 210 | |
| 211 | static double xAx( |
| 212 | const VEC& x, // in |
| 213 | const MAT& mat) //in: must be symmetric |
| 214 | { |
| 215 | const int n = NSIZE(x); |
| 216 | CV_Assert(mat.rows == n && mat.cols == n && x.isContinuous()); |
| 217 | const double* px = Buf(x); |
| 218 | double diagsum = 0, sum = 0; |
| 219 | int i = n; |
| 220 | while (i--) |
| 221 | { |
| 222 | const double xi = px[i]; |
| 223 | const double* const rowbuf = mat.ptr<double>(i); |
| 224 | diagsum += rowbuf[i] * SQ(xi); // sum diag elements |
| 225 | for (int j = i+1; j < n; j++) // sum upper right triangle elements |
| 226 | sum += rowbuf[j] * xi * px[j]; |
| 227 | } |
| 228 | return diagsum + 2 * sum; // "2 *" to include lower left triangle elements |
| 229 | } |
| 230 | |
| 231 | // If OpenMP is enabled, multiple instances of this function will be called |
| 232 | // concurrently (each call will have a different value of x and y). Thus this |
no test coverage detected