Improve comments in mju_cholFactorNNZ, clarify that this function reads from the upper triangle of the source matrix.
PiperOrigin-RevId: 686113654 Change-Id: I029f9279d177f4cb9ff60396a26d64821aee3a6c
This commit is contained in:
committed by
Copybara-Service
parent
096853e192
commit
0ffaeb4d56
@@ -857,8 +857,9 @@ void mju_sqrMatTDSparse(mjtNum* res, const mjtNum* mat, const mjtNum* matT,
|
||||
mj_freeStack(d);
|
||||
}
|
||||
|
||||
// compute row non-zeros of reverse-Cholesky factor L, return total
|
||||
// compute row non-zeros of reverse-Cholesky factor L, return total non-zeros
|
||||
// based on ldl_symbolic from 'Algorithm 8xx: a concise sparse Cholesky factorization package'
|
||||
// note: reads pattern from upper triangle
|
||||
int mju_cholFactorNNZ(int* L_rownnz, const int* rownnz, const int* rowadr, const int* colind,
|
||||
int n, mjData* d) {
|
||||
mj_markStack(d);
|
||||
@@ -870,18 +871,21 @@ int mju_cholFactorNNZ(int* L_rownnz, const int* rownnz, const int* rowadr, const
|
||||
parent[r] = -1;
|
||||
flag[r] = r;
|
||||
L_rownnz[r] = 1; // start with 1 for diagonal
|
||||
|
||||
// loop over non-zero columns
|
||||
int start = rowadr[r];
|
||||
int end = start + rownnz[r];
|
||||
// loop over non-zero columns
|
||||
for (int p = start; p < end; p++) {
|
||||
int i = colind[p];
|
||||
for (int c = start; c < end; c++) {
|
||||
int i = colind[c];
|
||||
if (i > r) {
|
||||
// follow path from i to root of elimination tree, stop at flagged node
|
||||
// traverse from i to ancestor, stop when row is flagged
|
||||
while (flag[i] != r) {
|
||||
// find parent of i if not yet determined
|
||||
// if not yet set, set parent to current row
|
||||
if (parent[i] == -1) {
|
||||
parent[i] = r;
|
||||
}
|
||||
|
||||
// increment non-zeros, flag row i, advance to parent
|
||||
L_rownnz[i]++;
|
||||
flag[i] = r;
|
||||
i = parent[i];
|
||||
@@ -892,12 +896,11 @@ int mju_cholFactorNNZ(int* L_rownnz, const int* rownnz, const int* rowadr, const
|
||||
|
||||
mj_freeStack(d);
|
||||
|
||||
// accumulate sum
|
||||
int sum = 0;
|
||||
// sum up all row non-zeros
|
||||
int nnz = 0;
|
||||
for (int r = 0; r < n; r++) {
|
||||
sum += L_rownnz[r];
|
||||
nnz += L_rownnz[r];
|
||||
}
|
||||
|
||||
// return total non-zeros
|
||||
return sum;
|
||||
return nnz;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user