summaryrefslogtreecommitdiffhomepage
path: root/ir/adt
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2015-09-07 09:58:59 +0200
committerMatthias Braun <matze@braunis.de>2015-09-07 19:58:31 +0200
commit0553e2d56e2f8fe403849d267e72b25d080c4d51 (patch)
tree5bd4f8ec18e2d47a2ad05090d1de5d5e51ebe563 /ir/adt
parentd3b482aabe2c23e01e824ebcccd27ccbc4eaf25f (diff)
gaussseidel: Cleanup
Diffstat (limited to 'ir/adt')
-rw-r--r--ir/adt/gaussseidel.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/ir/adt/gaussseidel.c b/ir/adt/gaussseidel.c
index 551e643..b060aae 100644
--- a/ir/adt/gaussseidel.c
+++ b/ir/adt/gaussseidel.c
@@ -1,16 +1,17 @@
+#include "gaussseidel.h"
+
#include <assert.h>
#include <math.h>
#include <string.h>
#include "xmalloc.h"
-#include "gaussseidel.h"
#include "util.h"
-typedef struct col_val_t {
+typedef struct {
double v;
unsigned col_idx;
} col_val_t;
-typedef struct row_col_t {
+typedef struct {
unsigned c_cols;
unsigned n_cols;
double diag;
@@ -48,7 +49,7 @@ static void alloc_rows(gs_matrix_t *m, unsigned c_rows, unsigned c_cols,
}
}
-gs_matrix_t *gs_new_matrix(int n_init_rows, int n_init_cols)
+gs_matrix_t *gs_new_matrix(unsigned n_init_rows, unsigned n_init_cols)
{
gs_matrix_t *res = XMALLOCZ(gs_matrix_t);
alloc_rows(res, n_init_rows, n_init_cols, 0);
@@ -91,7 +92,7 @@ void gs_matrix_set(gs_matrix_t *m, unsigned row, unsigned col, double val)
return;
}
- // Search for correct column
+ /* Search for correct column */
col_val_t *cols = the_row->cols;
unsigned min = 0;
unsigned max = the_row->n_cols;
@@ -104,10 +105,10 @@ void gs_matrix_set(gs_matrix_t *m, unsigned row, unsigned col, double val)
max = MIN(c, max-1);
else
break;
- c = (max+min)/2;
+ c = (min+max)/2;
}
- // Have we found the entry?
+ /* Have we found the entry? */
if (c < the_row->n_cols && the_row->cols[c].col_idx == col) {
the_row->cols[c].v = val;
if (val == 0.0)
@@ -115,23 +116,24 @@ void gs_matrix_set(gs_matrix_t *m, unsigned row, unsigned col, double val)
return;
}
- // We haven't found the entry, so we must create a new one.
- // Is there enough space?
+ /* We haven't found the entry, so we must create a new one.
+ * Is there enough space? */
if (the_row->n_cols <= the_row->c_cols)
alloc_cols(the_row, the_row->c_cols + 16);
- // Shift right-most entries to the right by one
+ /* Shift right-most entries to the right by one */
for (unsigned i = the_row->n_cols; i > c; --i)
the_row->cols[i] = the_row->cols[i-1];
- // Finally insert the new entry
+ /* Finally insert the new entry */
the_row->n_cols++;
the_row->cols[c].col_idx = col;
the_row->cols[c].v = val;
- // Check that the entries are sorted
+ /* Check that the entries are sorted */
assert(c==0 || the_row->cols[c-1].col_idx < the_row->cols[c].col_idx);
- assert(c>=the_row->n_cols-1 || the_row->cols[c].col_idx < the_row->cols[c+1].col_idx);
+ assert(c>=the_row->n_cols-1
+ || the_row->cols[c].col_idx < the_row->cols[c+1].col_idx);
}
double gs_matrix_get(const gs_matrix_t *m, unsigned row, unsigned col)
@@ -141,7 +143,7 @@ double gs_matrix_get(const gs_matrix_t *m, unsigned row, unsigned col)
if (row == col)
return the_row->diag != 0.0 ? 1.0 / the_row->diag : 0.0;
- // Search for correct column
+ /* Search for correct column */
unsigned c;
for (c = 0; c < the_row->n_cols && the_row->cols[c].col_idx < col; ++c) {
}
@@ -177,7 +179,7 @@ double gs_matrix_gauss_seidel(const gs_matrix_t *m, double *x)
double old = x[r];
double nw = - sum * row->diag;
- // nw = old - overdrive * (old + sum * row->diag);
+ /* nw = old - overdrive * (old + sum * row->diag); */
res += fabs(old - nw);
x[r] = nw;
}
@@ -187,10 +189,10 @@ double gs_matrix_gauss_seidel(const gs_matrix_t *m, double *x)
void gs_matrix_dump(const gs_matrix_t *m, FILE *out)
{
- unsigned size = m->c_rows;
- double *elems = XMALLOCN(double, size);
+ unsigned size = m->c_rows;
+ double *elems = XMALLOCN(double, size);
- // The rows which have some content
+ /* The rows which have some content */
for (unsigned r = 0; r < size; ++r) {
row_col_t *row = &m->rows[r];