From 4548f166eeb7d29f28793b39ede58cafaa2b64f8 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 15 Oct 2012 18:51:37 +0200 Subject: Add intmat_is_identity() --- libcrystfel/src/integer_matrix.c | 31 +++++++++++++++++++++++++++++++ libcrystfel/src/integer_matrix.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/libcrystfel/src/integer_matrix.c b/libcrystfel/src/integer_matrix.c index f975fa8b..c8849dda 100644 --- a/libcrystfel/src/integer_matrix.c +++ b/libcrystfel/src/integer_matrix.c @@ -375,3 +375,34 @@ void intmat_print(const IntegerMatrix *m) fprintf(stderr, "]\n"); } } + + +/** + * intmat_is_identity + * @m: An %IntegerMatrix + * + * Returns true if @m is an identity matrix. + * + */ +int intmat_is_identity(const IntegerMatrix *m) +{ + int i, j; + + for ( i=0; irows; i++ ) { + for ( j=0; jcols; j++ ) { + + signed int v; + + v = intmat_get(m, i, j); + + if ( i == j ) { + if ( v != 1 ) return 0; + } else { + if ( v != 0 ) return 0; + } + + } + } + + return 1; +} diff --git a/libcrystfel/src/integer_matrix.h b/libcrystfel/src/integer_matrix.h index 1c930720..f413573a 100644 --- a/libcrystfel/src/integer_matrix.h +++ b/libcrystfel/src/integer_matrix.h @@ -65,6 +65,9 @@ extern IntegerMatrix *intmat_inverse(const IntegerMatrix *m); /* Determinant */ extern signed int intmat_det(const IntegerMatrix *m); +/* Is identity? */ +extern int intmat_is_identity(const IntegerMatrix *m); + /* Diagnostics */ extern void intmat_print(const IntegerMatrix *m); -- cgit v1.2.3