27 static inline int finite(
double d) {
return _finite(d); }
32 this->maximum_scalar_measure_number = maximum_scalar_measure_number;
34 M_copy = cvCreateMat(maximum_scalar_measure_number, state_size, CV_64F);
35 M1 =
new double[maximum_scalar_measure_number];
36 M2 =
new double[maximum_scalar_measure_number];
37 b_copy =
new double[maximum_scalar_measure_number];
45 if (M_copy) cvReleaseMat(&M_copy);
50 if (maximum_scalar_measure_number > M_copy->rows ||
51 state_size > M_copy->cols) {
52 cvReleaseMat(&M_copy);
57 this->maximum_scalar_measure_number = maximum_scalar_measure_number;
58 M_copy = cvCreateMat(maximum_scalar_measure_number, state_size, CV_64F);
59 M1 =
new double[maximum_scalar_measure_number];
60 M2 =
new double[maximum_scalar_measure_number];
61 b_copy =
new double[maximum_scalar_measure_number];
67 #ifndef SORRY_VINCENT_Y_A_UN_BUG
68 return cvSolve(M, b, X, CV_LU) != 0;
72 int Mnc = M_copy->cols;
74 assert(M_copy->rows == maximum_scalar_measure_number);
75 assert(M->cols == M_copy->cols);
76 assert(M->rows <= M_copy->rows);
78 cvGetSubRect(M_copy, &subM, cvRect(0,0,M->cols, M->rows));
92 assert(nc <= maximum_scalar_measure_number);
93 assert(nr <= maximum_scalar_measure_number);
96 double * pM = M_copy->data.db;
98 bool singular =
false;
100 for(
int k = 0; k < nc; k++)
102 double * ppMik = ppMkk;
103 double eta = fabs(*ppMik);
104 for(
int i = k + 1; i < nr; i++)
106 double elt = fabs(*ppMik);
107 if (eta < elt) eta = elt;
119 double inv_eta = 1. / eta;
120 double * ppMik = ppMkk;
121 for(
int i = k; i < nr; i++)
124 sum += *ppMik * *ppMik;
127 double sigma = sqrt(sum);
131 M1[k] = sigma * *ppMkk;
132 M2[k] = -eta * sigma;
133 for(
int j = k + 1; j < nc; j++)
136 double * ppMik = ppMkk;
138 for(
int i = k; i < nr; i++)
140 sum += *ppMik * ppMik[Djk];
143 double tau = sum / M1[k];
145 for(
int i = k; i < nr; i++)
147 ppMik[Djk] -= tau * *ppMik;
155 assert(M_copy->rows == maximum_scalar_measure_number);
158 for(
int i = 0; i < nr; i++)
159 b_copy[i] = b->data.db[i];
161 for(
int j = 0; j < nc; j++)
164 double * ppMij = ppMjj;
165 for(
int i = j; i < nr; i++)
167 tau += *ppMij * b_copy[i];
172 for(
int i = j; i < nr; i++)
174 b_copy[i] -= tau * *ppMij;
180 assert(M_copy->rows == maximum_scalar_measure_number);
183 double * p_X = X->data.db;
184 p_X[nc - 1] = b_copy[nc - 1] / M2[nc - 1];
185 if (!finite(p_X[nc-1]))
return false;
186 for(
int i = nc - 2; i >= 0; i--)
189 double * ppMij = pM + i * Mnc + (i + 1);
191 for(
int j = i + 1; j < nc; j++)
193 sum += *ppMij * p_X[j];
196 p_X[i] = (b_copy[i] - sum) / M2[i];
197 if (!finite(p_X[i]))
return false;
199 assert(M_copy->rows == maximum_scalar_measure_number);