[goffice] quad: make dot_product official.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] quad: make dot_product official.
- Date: Thu, 20 May 2010 22:54:34 +0000 (UTC)
commit 8339e2d19f5a35545533935ab8cefcdab7114675
Author: Morten Welinder <terra gnome org>
Date: Thu May 20 18:54:19 2010 -0400
quad: make dot_product official.
ChangeLog | 5 ++++
goffice/math/go-quad.c | 16 ++++++++++++-
goffice/math/go-quad.h | 9 ++++++-
goffice/math/go-regression.c | 47 +++++++++++++----------------------------
4 files changed, 41 insertions(+), 36 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c60cb0c..ca9935d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-05-20 Morten Welinder <terra gnome org>
+
+ * goffice/math/go-quad.c (go_quad_dot_product): New function.
+ (go_quad_init): Drop third argument. All callers changed.
+
2010-05-17 Morten Welinder <terra gnome org>
* goffice/math/go-rangefunc.c (go_range_devsq): Do the long-double
diff --git a/goffice/math/go-quad.c b/goffice/math/go-quad.c
index 1ec65ff..8d76934 100644
--- a/goffice/math/go-quad.c
+++ b/goffice/math/go-quad.c
@@ -131,10 +131,10 @@ SUFFIX(go_quad_end) (void *state)
}
void
-SUFFIX(go_quad_init) (QUAD *res, DOUBLE h, DOUBLE l)
+SUFFIX(go_quad_init) (QUAD *res, DOUBLE h)
{
res->h = h;
- res->l = l;
+ res->l = 0;
}
DOUBLE
@@ -216,3 +216,15 @@ SUFFIX(go_quad_sqrt) (QUAD *res, const QUAD *a)
} else
res->h = res->l = 0;
}
+
+void
+SUFFIX(go_quad_dot_product) (QUAD *res, const QUAD *a, const QUAD *b, int n)
+{
+ int i;
+ SUFFIX(go_quad_init) (res, 0);
+ for (i = 0; i < n; i++) {
+ QUAD d;
+ SUFFIX(go_quad_mul) (&d, &a[i], &b[i]);
+ SUFFIX(go_quad_add) (res, res, &d);
+ }
+}
diff --git a/goffice/math/go-quad.h b/goffice/math/go-quad.h
index 4dc6763..afa612b 100644
--- a/goffice/math/go-quad.h
+++ b/goffice/math/go-quad.h
@@ -14,7 +14,7 @@ gboolean go_quad_functional (void);
void *go_quad_start (void);
void go_quad_end (void *state);
-void go_quad_init (GOQuad *res, double h, double l);
+void go_quad_init (GOQuad *res, double h);
double go_quad_value (const GOQuad *a);
void go_quad_add (GOQuad *res, const GOQuad *a, const GOQuad *b);
@@ -25,6 +25,8 @@ void go_quad_sqrt (GOQuad *res, const GOQuad *a);
void go_quad_mul12 (GOQuad *res, double x, double y);
+void go_quad_dot_product (GOQuad *res, const GOQuad *a, const GOQuad *b, int n);
+
#ifdef GOFFICE_WITH_LONG_DOUBLE
typedef struct {
long double h;
@@ -35,7 +37,7 @@ gboolean go_quad_functionall (void);
void *go_quad_startl (void);
void go_quad_endl (void *state);
-void go_quad_initl (GOQuadl *res, long double h, long double l);
+void go_quad_initl (GOQuadl *res, long double h);
long double go_quad_valuel (const GOQuadl *a);
void go_quad_addl (GOQuadl *res, const GOQuadl *a, const GOQuadl *b);
@@ -45,6 +47,9 @@ void go_quad_divl (GOQuadl *res, const GOQuadl *a, const GOQuadl *b);
void go_quad_sqrtl (GOQuadl *res, const GOQuadl *a);
void go_quad_mul12l (GOQuadl *res, long double x, long double y);
+
+void go_quad_dot_productl (GOQuadl *res,
+ const GOQuadl *a, const GOQuadl *b, int n);
#endif
G_END_DECLS
diff --git a/goffice/math/go-regression.c b/goffice/math/go-regression.c
index d46c253..ba24479 100644
--- a/goffice/math/go-regression.c
+++ b/goffice/math/go-regression.c
@@ -194,18 +194,6 @@ copy_stats (go_regression_stat_t *s1,
/* ------------------------------------------------------------------------- */
-static void
-SUFFIX(dot_product) (const QUAD *x, const QUAD *y, int n, QUAD *dp)
-{
- int i;
- SUFFIX(go_quad_init) (dp, 0, 0);
- for (i = 0; i < n; i++) {
- QUAD d;
- SUFFIX(go_quad_mul) (&d, &x[i], &y[i]);
- SUFFIX(go_quad_add) (dp, dp, &d);
- }
-}
-
static GORegressionResult
SUFFIX(QR) (CONSTMATRIX A, QMATRIX Q, QMATRIX R, int m, int n)
{
@@ -213,13 +201,13 @@ SUFFIX(QR) (CONSTMATRIX A, QMATRIX Q, QMATRIX R, int m, int n)
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
- SUFFIX(go_quad_init) (&Q[i][j], A[i][j], 0);
+ SUFFIX(go_quad_init) (&Q[i][j], A[i][j]);
for (k = 0; k < m; k++) {
QUAD L;
int i;
- SUFFIX(dot_product) (Q[k], Q[k], n, &L);
+ SUFFIX(go_quad_dot_product) (&L, Q[k], Q[k], n);
SUFFIX(go_quad_sqrt) (&L, &L);
#if 0
PRINT_MATRIX (Q, m, n);
@@ -236,9 +224,9 @@ SUFFIX(QR) (CONSTMATRIX A, QMATRIX Q, QMATRIX R, int m, int n)
QUAD ip;
int j;
- SUFFIX(go_quad_init) (&R[k][i], 0, 0);
+ SUFFIX(go_quad_init) (&R[k][i], 0);
- SUFFIX(dot_product) (Q[k], Q[i], n, &ip);
+ SUFFIX(go_quad_dot_product) (&ip, Q[k], Q[i], n);
R[i][k] = ip;
for (j = 0; j < n; j++) {
@@ -260,16 +248,16 @@ SUFFIX(calc_residual) (CONSTMATRIX A, const DOUBLE *b, int dim, int n,
{
int i, j;
- SUFFIX(go_quad_init) (N2, 0, 0);
+ SUFFIX(go_quad_init) (N2, 0);
for (i = 0; i < n; i++) {
QUAD d;
- SUFFIX(go_quad_init) (&d, b[i], 0);
+ SUFFIX(go_quad_init) (&d, b[i]);
for (j = 0; j < dim; j++) {
QUAD Aji, e;
- SUFFIX(go_quad_init) (&Aji, A[j][i], 0);
+ SUFFIX(go_quad_init) (&Aji, A[j][i]);
SUFFIX(go_quad_mul) (&e, &Aji, &y[j]);
SUFFIX(go_quad_sub) (&d, &d, &e);
}
@@ -307,13 +295,8 @@ SUFFIX(refine) (CONSTMATRIX A, const DOUBLE *b, int dim, int n,
for (i = dim - 1; i >= 0; i--) {
QUAD acc;
- SUFFIX(go_quad_init) (&acc, 0, 0);
+ SUFFIX(go_quad_dot_product) (&acc, Q[i], residual, n);
- for (j = 0; j < n; j++) {
- QUAD qr;
- SUFFIX(go_quad_mul) (&qr, &Q[i][j], &residual[j]);
- SUFFIX(go_quad_add) (&acc, &acc, &qr);
- }
for (j = i + 1; j < dim; j++) {
QUAD Rd;
SUFFIX(go_quad_mul) (&Rd, &R[j][i], &delta[j]);
@@ -602,7 +585,7 @@ SUFFIX(go_matrix_invert) (MATRIX A, int n)
QUAD d = Q[i][k];
for (j = i + 1; j < n; j++) {
QUAD p;
- SUFFIX(go_quad_init) (&p, A[k][j], 0);
+ SUFFIX(go_quad_init) (&p, A[k][j]);
SUFFIX(go_quad_mul) (&p, &R[j][i], &p);
SUFFIX(go_quad_sub) (&d, &d, &p);
}
@@ -716,10 +699,10 @@ SUFFIX(general_linear_regression) (CONSTMATRIX xss, int xdim,
for (i = xdim - 1; i >= 0; i--) {
QUAD acc;
- SUFFIX(go_quad_init) (&acc, 0, 0);
+ SUFFIX(go_quad_init) (&acc, 0);
for (j = 0; j < n; j++) {
QUAD p;
- SUFFIX(go_quad_init) (&p, ys[j], 0);
+ SUFFIX(go_quad_init) (&p, ys[j]);
SUFFIX(go_quad_mul) (&p, &p, &Q[i][j]);
SUFFIX(go_quad_add) (&acc, &acc, &p);
}
@@ -739,7 +722,7 @@ SUFFIX(general_linear_regression) (CONSTMATRIX xss, int xdim,
/* Round to plain precision. */
for (i = 0; i < xdim; i++) {
result[i] = SUFFIX(go_quad_value) (&qresult[i]);
- SUFFIX(go_quad_init) (&qresult[i], result[i], 0);
+ SUFFIX(go_quad_init) (&qresult[i], result[i]);
}
}
@@ -778,10 +761,10 @@ SUFFIX(general_linear_regression) (CONSTMATRIX xss, int xdim,
stat_->adj_sqr_r = 1 - stat_->ss_resid * (n - 1) /
((n - xdim) * stat_->ss_total);
if (n == xdim)
- SUFFIX(go_quad_init) (&N2, 0, 0);
+ SUFFIX(go_quad_init) (&N2, 0);
else {
QUAD d;
- SUFFIX(go_quad_init) (&d, n - xdim, 0);
+ SUFFIX(go_quad_init) (&d, n - xdim);
SUFFIX(go_quad_div) (&N2, &N2, &d);
}
stat_->var = SUFFIX(go_quad_value) (&N2);
@@ -792,7 +775,7 @@ SUFFIX(general_linear_regression) (CONSTMATRIX xss, int xdim,
/* Solve R^T z = e_k */
for (i = 0; i < xdim; i++) {
QUAD d;
- SUFFIX(go_quad_init) (&d, i == k ? 1 : 0, 0);
+ SUFFIX(go_quad_init) (&d, i == k ? 1 : 0);
for (j = 0; j < i; j++) {
QUAD p;
SUFFIX(go_quad_mul) (&p, &R[i][j], &inv[j]);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]