Optimize LSF for size, efficiency (#21443)

This commit is contained in:
Ramiro Polla 2021-03-25 04:56:48 +01:00 committed by GitHub
parent 69c6ffa90b
commit 8bf6b190ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 16 deletions

View file

@ -46,23 +46,23 @@ int finish_incremental_LSF(struct linear_fit_data *lsf) {
if (N == 0.0) if (N == 0.0)
return 1; return 1;
lsf->xbar /= N; const float RN = 1.0f / N,
lsf->ybar /= N; xbar = lsf->xbar * RN,
lsf->zbar /= N; ybar = lsf->ybar * RN,
lsf->x2bar = lsf->x2bar / N - sq(lsf->xbar); zbar = lsf->zbar * RN,
lsf->y2bar = lsf->y2bar / N - sq(lsf->ybar); x2bar = lsf->x2bar * RN - sq(xbar),
lsf->z2bar = lsf->z2bar / N - sq(lsf->zbar); y2bar = lsf->y2bar * RN - sq(ybar),
lsf->xybar = lsf->xybar / N - lsf->xbar * lsf->ybar; xybar = lsf->xybar * RN - xbar * ybar,
lsf->yzbar = lsf->yzbar / N - lsf->ybar * lsf->zbar; yzbar = lsf->yzbar * RN - ybar * zbar,
lsf->xzbar = lsf->xzbar / N - lsf->xbar * lsf->zbar; xzbar = lsf->xzbar * RN - xbar * zbar,
const float DD = lsf->x2bar * lsf->y2bar - sq(lsf->xybar); DD = x2bar * y2bar - sq(xybar);
if (ABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy)) if (ABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy))
return 1; return 1;
lsf->A = (lsf->yzbar * lsf->xybar - lsf->xzbar * lsf->y2bar) / DD; lsf->A = (yzbar * xybar - xzbar * y2bar) / DD;
lsf->B = (lsf->xzbar * lsf->xybar - lsf->yzbar * lsf->x2bar) / DD; lsf->B = (xzbar * xybar - yzbar * x2bar) / DD;
lsf->D = -(lsf->zbar + lsf->A * lsf->xbar + lsf->B * lsf->ybar); lsf->D = -(zbar + lsf->A * xbar + lsf->B * ybar);
return 0; return 0;
} }

View file

@ -37,7 +37,7 @@
struct linear_fit_data { struct linear_fit_data {
float xbar, ybar, zbar, float xbar, ybar, zbar,
x2bar, y2bar, z2bar, x2bar, y2bar,
xybar, xzbar, yzbar, xybar, xzbar, yzbar,
max_absx, max_absy, max_absx, max_absy,
A, B, D, N; A, B, D, N;
@ -56,7 +56,6 @@ inline void incremental_WLSF(struct linear_fit_data *lsf, const float &x, const
lsf->zbar += wz; lsf->zbar += wz;
lsf->x2bar += wx * x; lsf->x2bar += wx * x;
lsf->y2bar += wy * y; lsf->y2bar += wy * y;
lsf->z2bar += wz * z;
lsf->xybar += wx * y; lsf->xybar += wx * y;
lsf->xzbar += wx * z; lsf->xzbar += wx * z;
lsf->yzbar += wy * z; lsf->yzbar += wy * z;
@ -74,7 +73,6 @@ inline void incremental_LSF(struct linear_fit_data *lsf, const float &x, const f
lsf->zbar += z; lsf->zbar += z;
lsf->x2bar += sq(x); lsf->x2bar += sq(x);
lsf->y2bar += sq(y); lsf->y2bar += sq(y);
lsf->z2bar += sq(z);
lsf->xybar += x * y; lsf->xybar += x * y;
lsf->xzbar += x * z; lsf->xzbar += x * z;
lsf->yzbar += y * z; lsf->yzbar += y * z;