From 252f4073f0041027b5e9e6773fe892ffe465ed23 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 9 Mar 2019 11:37:34 +0100 Subject: Single point of truth for matrix memory layout --- libcrystfel/src/cell.c | 32 ++++++++++++++------------------ libcrystfel/src/rational.c | 4 ++-- 2 files changed, 16 insertions(+), 20 deletions(-) (limited to 'libcrystfel') 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; iv[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; jcols; 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); } -- cgit v1.2.3