summaryrefslogtreecommitdiff
path: root/lib/factor_update.c
blob: ceaa01a19dde65de0ffb91291287fb7c92f43a42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

#include "fracture.h"

void factor_update(cholmod_factor *factor, uint_t v1, uint_t v2,
                   cholmod_common *c) {
  uint_t n = factor->n;

  cholmod_sparse *update_mat =
      CHOL_F(allocate_sparse)(n, n, 2, true, true, 0, CHOLMOD_REAL, c);

  uint_t s1, s2;
  s1 = v1 < v2 ? v1 : v2;
  s2 = v1 > v2 ? v1 : v2;

  int_t *pp = (int_t *)update_mat->p;
  int_t *ii = (int_t *)update_mat->i;
  double *xx = (double *)update_mat->x;

  for (uint_t i = 0; i <= s1; i++) {
    pp[i] = 0;
  }

  for (uint_t i = s1 + 1; i <= n; i++) {
    pp[i] = 2;
  }

  ii[0] = s1;
  ii[1] = s2;
  xx[0] = 1;
  xx[1] = -1;

  cholmod_sparse *perm_update_mat = CHOL_F(submatrix)(
      update_mat, factor->Perm, factor->n, NULL, -1, true, true, c);

  CHOL_F(updown)(false, perm_update_mat, factor, c);

  CHOL_F(free_sparse)(&perm_update_mat, c);
  CHOL_F(free_sparse)(&update_mat, c);
}

void factor_update2(cholmod_factor *factor, uint_t v, cholmod_common *c) {
  uint_t n = factor->n;

  cholmod_sparse *update_mat =
      CHOL_F(allocate_sparse)(n, n, 1, true, true, 0, CHOLMOD_REAL, c);

  int_t *pp = (int_t *)update_mat->p;
  int_t *ii = (int_t *)update_mat->i;
  double *xx = (double *)update_mat->x;

  for (uint_t i = 0; i <= v; i++) {
    pp[i] = 0;
  }

  for (uint_t i = v + 1; i <= n; i++) {
    pp[i] = 1;
  }

  ii[0] = v;
  xx[0] = 1;

  cholmod_sparse *perm_update_mat = CHOL_F(submatrix)(
      update_mat, factor->Perm, factor->n, NULL, -1, true, true, c);

  CHOL_F(updown)(false, perm_update_mat, factor, c);

  CHOL_F(free_sparse)(&perm_update_mat, c);
  CHOL_F(free_sparse)(&update_mat, c);
}