diff options
author | Thomas White <taw@physics.org> | 2014-10-17 17:19:55 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2014-10-23 17:02:32 +0200 |
commit | b65ff35322544fcb0ad7494987145e9c8aa75d5c (patch) | |
tree | 4aeb84c15786f746f0abe82338c60956f73f92b0 /libcrystfel/src/integer_matrix.c | |
parent | cb08ffbe0adeed6502db70f3380059800464726d (diff) |
Add intmat_identity()
Diffstat (limited to 'libcrystfel/src/integer_matrix.c')
-rw-r--r-- | libcrystfel/src/integer_matrix.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libcrystfel/src/integer_matrix.c b/libcrystfel/src/integer_matrix.c index 018f0ca6..c31072b4 100644 --- a/libcrystfel/src/integer_matrix.c +++ b/libcrystfel/src/integer_matrix.c @@ -501,3 +501,34 @@ int intmat_equals(const IntegerMatrix *a, const IntegerMatrix *b) return 1; } + + +/** + * intmat_identity + * @size: The size of the (square) matrix + * + * Returns: an identity %IntegerMatrix with side length @size, or NULL on error. + * + */ +IntegerMatrix *intmat_identity(int size) +{ + IntegerMatrix *m; + int i, j; + + m = intmat_new(size, size); + if ( m == NULL ) return NULL; + + for ( i=0; i<size; i++ ) { + for ( j=0; j<size; j++ ) { + + if ( i == j ) { + intmat_set(m, i, j, 1); + } else { + intmat_set(m, i, j, 0); + } + + } + } + + return m; +} |