diff options
author | Thomas White <taw@physics.org> | 2019-03-05 14:16:26 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2019-03-11 16:49:37 +0100 |
commit | 68061d0e3c42f61fa7664e0f0996cade13057391 (patch) | |
tree | 19c3b22a3e81b41a85f6053e8e8bb2cc7edc8f42 /libcrystfel | |
parent | 3e850c6c2ed2a3dbc0fe0be27d36c0d1e6b57614 (diff) |
Add rtnl_mtx_identity()
Diffstat (limited to 'libcrystfel')
-rw-r--r-- | libcrystfel/src/rational.c | 16 | ||||
-rw-r--r-- | libcrystfel/src/rational.h | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/libcrystfel/src/rational.c b/libcrystfel/src/rational.c index 0f2bcaee..58178559 100644 --- a/libcrystfel/src/rational.c +++ b/libcrystfel/src/rational.c @@ -292,6 +292,7 @@ struct _rationalmatrix RationalMatrix *rtnl_mtx_new(unsigned int rows, unsigned int cols) { RationalMatrix *m; + int i; m = malloc(sizeof(RationalMatrix)); if ( m == NULL ) return NULL; @@ -305,6 +306,21 @@ RationalMatrix *rtnl_mtx_new(unsigned int rows, unsigned int cols) m->rows = rows; m->cols = cols; + for ( i=0; i<m->rows*m->cols; i++ ) { + m->v[i] = rtnl_zero(); + } + + return m; +} + + +RationalMatrix *rtnl_mtx_identity(int rows) +{ + int i; + RationalMatrix *m = rtnl_mtx_new(rows, rows); + for ( i=0; i<rows; i++ ) { + rtnl_mtx_set(m, i, i, rtnl(1,1)); + } return m; } diff --git a/libcrystfel/src/rational.h b/libcrystfel/src/rational.h index 7983f56f..8590e920 100644 --- a/libcrystfel/src/rational.h +++ b/libcrystfel/src/rational.h @@ -86,6 +86,7 @@ extern RationalMatrix *rtnl_mtx_copy(const RationalMatrix *m); extern Rational rtnl_mtx_get(const RationalMatrix *m, int i, int j); extern void rtnl_mtx_set(const RationalMatrix *m, int i, int j, Rational v); extern RationalMatrix *rtnl_mtx_from_intmat(const IntegerMatrix *m); +extern RationalMatrix *rtnl_mtx_identity(int rows); extern IntegerMatrix *intmat_from_rtnl_mtx(const RationalMatrix *m); extern void rtnl_mtx_free(RationalMatrix *mtx); extern void rtnl_mtx_mult(const RationalMatrix *m, const Rational *vec, |