Skip to content

Commit 12e1a2f

Browse files
committed
Start adding factorisation
1 parent c6ef443 commit 12e1a2f

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
using Int = int;
3+
4+
namespace hipo {
5+
Int denseFactTiny(Int n, Int k, double* A, double* B) {
6+
// ===========================================================================
7+
// Partial dense factorisation for supernodes with small size and front.
8+
// Assumes that both n and n-k are smaller than the block size.
9+
// Matrix A is in format FH
10+
// Matrix B is in format FH
11+
// BLAS calls: none
12+
// ===========================================================================
13+
14+
if (n < 0 || k < 0 || !A || (k < n && !B)) return 1;
15+
if (n == 0) return 0;
16+
17+
const Int ldb = n - k;
18+
19+
// factorisation of top kxk block
20+
for (Int row = 0; row < k; ++row) {
21+
for (Int col = 0; col < row; ++col) {
22+
// off-diagonal
23+
for (Int l = 0; l < col; ++l) {
24+
A[col + row * k] -= A[l + row * k] * A[l + col * k] * A[l + l * k];
25+
}
26+
double temp = A[col + row * k];
27+
A[col + row * k] /= A[col + col * k];
28+
29+
// contribution to diagonal
30+
A[row + row * k] -= A[col + row * k] * temp;
31+
}
32+
}
33+
34+
for (Int row = k; row < n; ++row) {
35+
// update rows below
36+
for (Int col = 0; col < k; ++col) {
37+
for (Int l = 0; l < col; ++l) {
38+
A[col + row * k] -= A[l + row * k] * A[l + col * k] * A[l + l * k];
39+
}
40+
A[col + row * k] /= A[col + col * k];
41+
}
42+
43+
// update schur complement
44+
const Int rowB = row - k;
45+
for (Int col = k; col <= row; ++col) {
46+
const Int colB = col - k;
47+
for (Int l = 0; l < k; ++l) {
48+
B[colB + rowB * ldb] -= A[l + row * k] * A[l + col * k] * A[l + l * k];
49+
}
50+
}
51+
}
52+
53+
// store the reciprocal of the pivot
54+
for (Int row = k; row < n; ++row) {
55+
// A[row + k * row] = 1.0 / A[row + k * row];
56+
}
57+
}
58+
59+
} // namespace hipo

0 commit comments

Comments
 (0)