From 24e2744b8b53dde715f59d98f969d44a10530675 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 28 Aug 2019 15:33:46 +0200 Subject: Rationalise matrix mutliplication compare_reindexed_cell_parameters still needs to be updated --- libcrystfel/src/cell-utils.c | 46 ++++-------------------------- libcrystfel/src/integer_matrix.c | 4 +-- libcrystfel/src/integer_matrix.h | 4 +-- libcrystfel/src/rational.c | 61 +++++++++++++++++++++++++++++++++------- libcrystfel/src/rational.h | 11 +++++--- libcrystfel/src/symmetry.c | 10 +++---- 6 files changed, 72 insertions(+), 64 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/cell-utils.c b/libcrystfel/src/cell-utils.c index dbc845bc..de8fe7ae 100644 --- a/libcrystfel/src/cell-utils.c +++ b/libcrystfel/src/cell-utils.c @@ -1612,7 +1612,6 @@ int compare_derivative_cell_parameters(UnitCell *cell_in, UnitCell *reference_in Rational *cand_c; int ncand_a, ncand_b, ncand_c; int ia, ib; - RationalMatrix *MCB; RationalMatrix *CiAMCB; double min_dist = +INFINITY; @@ -1647,8 +1646,6 @@ int compare_derivative_cell_parameters(UnitCell *cell_in, UnitCell *reference_in } M = rtnl_mtx_new(3, 3); - MCB = rtnl_mtx_new(3, 3); - CiAMCB = rtnl_mtx_new(3, 3); for ( ia=0; iacols == B->cols); - assert(ans->rows == A->rows); - assert(A->cols == B->rows); + intmat_size(B, &B_rows, &B_cols); + assert(A->cols == B_rows); + + ans = rtnl_mtx_new(A->rows, B_cols); + if ( ans == NULL ) return NULL; for ( i=0; irows; i++ ) { for ( j=0; jcols; j++ ) { @@ -544,21 +548,27 @@ void rtnl_mtx_mtxmult(const RationalMatrix *A, const RationalMatrix *B, for ( k=0; krows; k++ ) { Rational add; add = rtnl_mul(rtnl_mtx_get(A, i, k), - rtnl_mtx_get(B, k, j)); + rtnl(intmat_get(B, k, j), 1)); sum = rtnl_add(sum, add); } rtnl_mtx_set(ans, i, j, sum); } } + + return ans; } -void rtnl_mtx_intmatmult(const RationalMatrix *A, const IntegerMatrix *B, - RationalMatrix *ans) +RationalMatrix *rtnlmtx_times_rtnlmtx(const RationalMatrix *A, + const RationalMatrix *B) { int i, j; + RationalMatrix *ans; + + assert(A->cols == B->rows); - assert(ans->rows == A->rows); + ans = rtnl_mtx_new(A->rows, B->cols); + if ( ans == NULL ) return NULL; for ( i=0; irows; i++ ) { for ( j=0; jcols; j++ ) { @@ -567,12 +577,43 @@ void rtnl_mtx_intmatmult(const RationalMatrix *A, const IntegerMatrix *B, for ( k=0; krows; k++ ) { Rational add; add = rtnl_mul(rtnl_mtx_get(A, i, k), - rtnl(intmat_get(B, k, j), 1)); + rtnl_mtx_get(B, k, j)); + sum = rtnl_add(sum, add); + } + rtnl_mtx_set(ans, i, j, sum); + } + } + + return ans; +} + + +RationalMatrix *intmat_times_rtnlmtx(const IntegerMatrix *A, const RationalMatrix *B) +{ + int i, j; + RationalMatrix *ans; + unsigned int A_rows, A_cols; + + intmat_size(A, &A_rows, &A_cols); + + ans = rtnl_mtx_new(A_rows, B->cols); + if ( ans == NULL ) return NULL; + + for ( i=0; irows; i++ ) { + for ( j=0; jcols; j++ ) { + int k; + Rational sum = rtnl_zero(); + for ( k=0; kops[i]); + r = intmat_times_intmat(P, s->ops[i]); if ( r == NULL ) { ERROR("Matrix multiplication failed.\n"); return; } - f = intmat_intmat_mult(r, Pi); + f = intmat_times_intmat(r, Pi); if ( f == NULL ) { ERROR("Matrix multiplication failed.\n"); return; @@ -1340,7 +1340,7 @@ static int check_mult(const IntegerMatrix *ans, int val; IntegerMatrix *m; - m = intmat_intmat_mult(a, b); + m = intmat_times_intmat(a, b); assert(m != NULL); val = intmat_equals(ans, m); @@ -1403,7 +1403,7 @@ static int order(const IntegerMatrix *m) IntegerMatrix *anew; - anew = intmat_intmat_mult(m, a); + anew = intmat_times_intmat(m, a); assert(anew != NULL); intmat_free(a); a = anew; -- cgit v1.2.3