diff options
author | Thomas White <taw@physics.org> | 2019-03-09 11:37:34 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2019-03-11 16:49:37 +0100 |
commit | 252f4073f0041027b5e9e6773fe892ffe465ed23 (patch) | |
tree | 5143d2b86c6ef0f7ea93c93149ffad7f015e71d3 /libcrystfel | |
parent | e94501d025e8d6b4f4e446004e80a1badfbba30f (diff) |
Single point of truth for matrix memory layout
Diffstat (limited to 'libcrystfel')
-rw-r--r-- | libcrystfel/src/cell.c | 32 | ||||
-rw-r--r-- | libcrystfel/src/rational.c | 4 |
2 files changed, 16 insertions, 20 deletions
diff --git a/libcrystfel/src/cell.c b/libcrystfel/src/cell.c index 32e45856..130a24b1 100644 --- a/libcrystfel/src/cell.c +++ b/libcrystfel/src/cell.c @@ -910,6 +910,7 @@ UnitCell *cell_transform_rational(UnitCell *cell, RationalMatrix *m) UnitCell *out; gsl_matrix *tm; char ncen; + int i, j; if ( m == NULL ) return NULL; @@ -918,15 +919,12 @@ UnitCell *cell_transform_rational(UnitCell *cell, RationalMatrix *m) return NULL; } - gsl_matrix_set(tm, 0, 0, rtnl_as_double(rtnl_mtx_get(m, 0, 0))); - gsl_matrix_set(tm, 0, 1, rtnl_as_double(rtnl_mtx_get(m, 0, 1))); - gsl_matrix_set(tm, 0, 2, rtnl_as_double(rtnl_mtx_get(m, 0, 2))); - gsl_matrix_set(tm, 1, 0, rtnl_as_double(rtnl_mtx_get(m, 1, 0))); - gsl_matrix_set(tm, 1, 1, rtnl_as_double(rtnl_mtx_get(m, 1, 1))); - gsl_matrix_set(tm, 1, 2, rtnl_as_double(rtnl_mtx_get(m, 1, 2))); - gsl_matrix_set(tm, 2, 0, rtnl_as_double(rtnl_mtx_get(m, 2, 0))); - gsl_matrix_set(tm, 2, 1, rtnl_as_double(rtnl_mtx_get(m, 2, 1))); - gsl_matrix_set(tm, 2, 2, rtnl_as_double(rtnl_mtx_get(m, 2, 2))); + for ( i=0; i<3; i++ ) { + for ( j=0; j<3; j++ ) { + gsl_matrix_set(tm, i, j, + rtnl_as_double(rtnl_mtx_get(m, i, j))); + } + } out = cell_transform_gsl_direct(cell, tm); gsl_matrix_free(tm); @@ -983,6 +981,7 @@ UnitCell *cell_transform_rational_inverse(UnitCell *cell, RationalMatrix *m) gsl_matrix *inv; gsl_permutation *perm; int s; + int i, j; if ( m == NULL ) return NULL; @@ -991,15 +990,12 @@ UnitCell *cell_transform_rational_inverse(UnitCell *cell, RationalMatrix *m) return NULL; } - gsl_matrix_set(tm, 0, 0, rtnl_as_double(rtnl_mtx_get(m, 0, 0))); - gsl_matrix_set(tm, 0, 1, rtnl_as_double(rtnl_mtx_get(m, 0, 1))); - gsl_matrix_set(tm, 0, 2, rtnl_as_double(rtnl_mtx_get(m, 0, 2))); - gsl_matrix_set(tm, 1, 0, rtnl_as_double(rtnl_mtx_get(m, 1, 0))); - gsl_matrix_set(tm, 1, 1, rtnl_as_double(rtnl_mtx_get(m, 1, 1))); - gsl_matrix_set(tm, 1, 2, rtnl_as_double(rtnl_mtx_get(m, 1, 2))); - gsl_matrix_set(tm, 2, 0, rtnl_as_double(rtnl_mtx_get(m, 2, 0))); - gsl_matrix_set(tm, 2, 1, rtnl_as_double(rtnl_mtx_get(m, 2, 1))); - gsl_matrix_set(tm, 2, 2, rtnl_as_double(rtnl_mtx_get(m, 2, 2))); + for ( i=0; i<3; i++ ) { + for ( j=0; j<3; j++ ) { + gsl_matrix_set(tm, i, j, + rtnl_as_double(rtnl_mtx_get(m, i, j))); + } + } perm = gsl_permutation_alloc(3); if ( perm == NULL ) { diff --git a/libcrystfel/src/rational.c b/libcrystfel/src/rational.c index 4f02c8b1..5f17b0ea 100644 --- a/libcrystfel/src/rational.c +++ b/libcrystfel/src/rational.c @@ -367,7 +367,7 @@ RationalMatrix *rtnl_mtx_from_intmat(const IntegerMatrix *m) for ( i=0; i<rows; i++ ) { for ( j=0; j<cols; j++ ) { - n->v[j+cols*i] = rtnl(intmat_get(m, i, j), 1); + rtnl_mtx_set(n, i, j, rtnl(intmat_get(m, i, j), 1)); } } @@ -537,7 +537,7 @@ void rtnl_mtx_print(const RationalMatrix *m) fprintf(stderr, "[ "); for ( j=0; j<m->cols; j++ ) { - char *v = rtnl_format(m->v[j+m->cols*i]); + char *v = rtnl_format(rtnl_mtx_get(m, i, j)); fprintf(stderr, "%4s ", v); free(v); } |