summaryrefslogtreecommitdiff
path: root/src/update_factor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/update_factor.c')
-rw-r--r--src/update_factor.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/update_factor.c b/src/update_factor.c
new file mode 100644
index 0000000..6b8e05e
--- /dev/null
+++ b/src/update_factor.c
@@ -0,0 +1,44 @@
+
+#include "fracture.h"
+
+bool update_factor(cholmod_factor *factor, unsigned int v1, unsigned int v2,
+ cholmod_common *c) {
+ int n = factor->n;
+ assert(v1 < n);
+ assert(v2 < n);
+
+ cholmod_sparse *update_mat =
+ CHOL_F(allocate_sparse)(n, n, 2, true, true, 0, CHOLMOD_REAL, c);
+
+ unsigned int v3, v4;
+ v3 = v1 < v2 ? v1 : v2;
+ v4 = v1 > v2 ? v1 : v2;
+
+ for (int i = 0; i < n; i++) {
+ if (i <= v3)
+ ((CHOL_INT *)update_mat->p)[i] = 0;
+ else
+ ((CHOL_INT *)update_mat->p)[i] = 2;
+ }
+ ((CHOL_INT *)update_mat->p)[n] = 2;
+ ((CHOL_INT *)update_mat->i)[0] = v3;
+ ((CHOL_INT *)update_mat->i)[1] = v4;
+ ((double *)update_mat->x)[0] = 1;
+ ((double *)update_mat->x)[1] = -1;
+
+ // assert(CHOL_F(check_sparse)(update_mat, c));
+
+ cholmod_sparse *perm_update_mat = CHOL_F(submatrix)(
+ update_mat, factor->Perm, factor->n, NULL, -1, true, true, c);
+
+ // assert(CHOL_F(check_sparse)(perm_update_mat, c));
+
+ CHOL_F(updown)(false, perm_update_mat, factor, c);
+
+ // assert(CHOL_F(check_factor)(factor, c));
+
+ CHOL_F(free_sparse)(&perm_update_mat, c);
+ CHOL_F(free_sparse)(&update_mat, c);
+
+ return true;
+}