projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added the new "about-logo"
[pspp]
/
lib
/
linreg
/
sweep.c
diff --git
a/lib/linreg/sweep.c
b/lib/linreg/sweep.c
index 0f8c223c7aa5b2e55c8619fba8be93fff679abb4..62dda200701ceda43e4040e3128b1b8121b9e279 100644
(file)
--- a/
lib/linreg/sweep.c
+++ b/
lib/linreg/sweep.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2009
, 2011
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@
-69,19
+69,16
@@
int
reg_sweep (gsl_matrix * A, int last_col)
{
int
reg_sweep (gsl_matrix * A, int last_col)
{
- if (A == NULL)
- return GSL_EFAULT;
-
- if (A->size1 != A->size2)
- return GSL_ENOTSQR;
-
- double sweep_element;
- double tmp;
int i;
int j;
int k;
gsl_matrix *B;
int i;
int j;
int k;
gsl_matrix *B;
+ if (A == NULL)
+ return GSL_EFAULT;
+
+ if (A->size1 != A->size2)
+ return GSL_ENOTSQR;
assert (last_col < A->size1);
gsl_matrix_swap_rows (A, A->size1 - 1, last_col);
assert (last_col < A->size1);
gsl_matrix_swap_rows (A, A->size1 - 1, last_col);
@@
-90,11
+87,10
@@
reg_sweep (gsl_matrix * A, int last_col)
B = gsl_matrix_alloc (A->size1, A->size2);
for (k = 0; k < (A->size1 - 1); k++)
{
B = gsl_matrix_alloc (A->size1, A->size2);
for (k = 0; k < (A->size1 - 1); k++)
{
- sweep_element = gsl_matrix_get (A, k, k);
+
const double
sweep_element = gsl_matrix_get (A, k, k);
if (fabs (sweep_element) > GSL_DBL_MIN)
{
if (fabs (sweep_element) > GSL_DBL_MIN)
{
- tmp = -1.0 / sweep_element;
- gsl_matrix_set (B, k, k, tmp);
+ gsl_matrix_set (B, k, k, -1.0 / sweep_element);
/*
Rows before current row k.
*/
/*
Rows before current row k.
*/
@@
-102,28
+98,25
@@
reg_sweep (gsl_matrix * A, int last_col)
{
for (j = i; j < A->size2; j++)
{
{
for (j = i; j < A->size2; j++)
{
- /*
- Use only the upper triangle of A.
- */
+ /* Use only the upper triangle of A. */
+ double tmp;
if (j < k)
{
tmp = gsl_matrix_get (A, i, j) -
gsl_matrix_get (A, i, k)
* gsl_matrix_get (A, j, k) / sweep_element;
if (j < k)
{
tmp = gsl_matrix_get (A, i, j) -
gsl_matrix_get (A, i, k)
* gsl_matrix_get (A, j, k) / sweep_element;
- gsl_matrix_set (B, i, j, tmp);
}
else if (j > k)
{
tmp = gsl_matrix_get (A, i, j) -
gsl_matrix_get (A, i, k)
* gsl_matrix_get (A, k, j) / sweep_element;
}
else if (j > k)
{
tmp = gsl_matrix_get (A, i, j) -
gsl_matrix_get (A, i, k)
* gsl_matrix_get (A, k, j) / sweep_element;
- gsl_matrix_set (B, i, j, tmp);
}
else
{
tmp = gsl_matrix_get (A, i, k) / sweep_element;
}
else
{
tmp = gsl_matrix_get (A, i, k) / sweep_element;
- gsl_matrix_set (B, i, j, tmp);
}
}
+ gsl_matrix_set (B, i, j, tmp);
}
}
/*
}
}
/*
@@
-131,7
+124,7
@@
reg_sweep (gsl_matrix * A, int last_col)
*/
for (j = k + 1; j < A->size1; j++)
{
*/
for (j = k + 1; j < A->size1; j++)
{
- tmp = gsl_matrix_get (A, k, j) / sweep_element;
+
double
tmp = gsl_matrix_get (A, k, j) / sweep_element;
gsl_matrix_set (B, k, j, tmp);
}
/*
gsl_matrix_set (B, k, j, tmp);
}
/*
@@
-141,18
+134,14
@@
reg_sweep (gsl_matrix * A, int last_col)
{
for (j = i; j < A->size2; j++)
{
{
for (j = i; j < A->size2; j++)
{
- tmp = gsl_matrix_get (A, i, j) -
+
double
tmp = gsl_matrix_get (A, i, j) -
gsl_matrix_get (A, k, i)
* gsl_matrix_get (A, k, j) / sweep_element;
gsl_matrix_set (B, i, j, tmp);
}
}
}
gsl_matrix_get (A, k, i)
* gsl_matrix_get (A, k, j) / sweep_element;
gsl_matrix_set (B, i, j, tmp);
}
}
}
- for (i = 0; i < A->size1; i++)
- for (j = i; j < A->size2; j++)
- {
- gsl_matrix_set (A, i, j, gsl_matrix_get (B, i, j));
- }
+ gsl_matrix_memcpy (A, B);
}
gsl_matrix_free (B);
}
gsl_matrix_free (B);