aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/reference/libcrystfel/CrystFEL-sections.txt1
-rw-r--r--libcrystfel/src/integer_matrix.c31
-rw-r--r--libcrystfel/src/integer_matrix.h1
3 files changed, 33 insertions, 0 deletions
diff --git a/doc/reference/libcrystfel/CrystFEL-sections.txt b/doc/reference/libcrystfel/CrystFEL-sections.txt
index 16ec0286..f3b5dc59 100644
--- a/doc/reference/libcrystfel/CrystFEL-sections.txt
+++ b/doc/reference/libcrystfel/CrystFEL-sections.txt
@@ -307,6 +307,7 @@ IntegerMatrix
<SUBSECTION>
intmat_new
intmat_copy
+intmat_identity
intmat_free
<SUBSECTION>
intmat_get
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;
+}
diff --git a/libcrystfel/src/integer_matrix.h b/libcrystfel/src/integer_matrix.h
index e1ba2c56..6616b5e8 100644
--- a/libcrystfel/src/integer_matrix.h
+++ b/libcrystfel/src/integer_matrix.h
@@ -47,6 +47,7 @@ extern "C" {
/* Alloc/dealloc */
extern IntegerMatrix *intmat_new(unsigned int rows, unsigned int cols);
extern IntegerMatrix *intmat_copy(IntegerMatrix *m);
+extern IntegerMatrix *intmat_identity(int size);
extern void intmat_free(IntegerMatrix *m);
/* Get/set */