Refactor sparse Cholesky factorization into symbolic and numeric phases.
The new symbolic function is a generalization of the function it replaces. In this CL it takes two unused temp arrays. The actual change in behavior happens in the followup.
New benchmark test output below ("L" is 2 humanoids and 100 free objects, "XL" is 100 humanoids). Note that `symbolic` is only ever called once per Newton iteration, while `numeric` is sometimes called multiple times (when the rank-1 update fails), hence timing them separately is valuable.
```
Benchmark Time(ns) CPU(ns) Iterations
--------------------------------------------------------------
BM_old_L_mean 84382 84703 19547 11.807k items/s
BM_symbolic_L_mean 16345 16381 88414 61.055k items/s
BM_numeric_L_mean 10986 10994 120000 90.999k items/s
BM_old_XL_mean 1241208 1244212 1200 803.924 items/s
BM_symbolic_XL_mean 130917 131042 12720 7.631k items/s
BM_numeric_XL_mean 77004 76767 21116 13.029k items/s
```
PiperOrigin-RevId: 846704054
Change-Id: Ib0c365724d63bf2b81606ca5353756a6496c3a26
This commit is contained in:
committed by
Copybara-Service
parent
d1fd11bccd
commit
45b0153067
@@ -1558,16 +1558,14 @@ static void MakeHessian(mjData* d, mjCGContext* ctx) {
|
||||
HT_rownnz, HT_rowadr, HT_colind, NULL,
|
||||
ctx->H_rownnz, ctx->H_rowadr, ctx->H_colind);
|
||||
|
||||
// count total and row non-zeros of reverse-Cholesky factor L
|
||||
ctx->nL = mju_cholFactorCount(ctx->L_rownnz, HT_rownnz, HT_rowadr, HT_colind, nv, d);
|
||||
// count total and row non-zeros of reverse-Cholesky factors L and LT
|
||||
int* LT_rownnz_temp = mjSTACKALLOC(d, nv, int);
|
||||
int* LT_rowadr_temp = mjSTACKALLOC(d, nv, int);
|
||||
ctx->nL = mju_cholFactorSymbolic(NULL, ctx->L_rownnz, ctx->L_rowadr, NULL,
|
||||
LT_rownnz_temp, LT_rowadr_temp, NULL,
|
||||
HT_rownnz, HT_rowadr, HT_colind, nv, d);
|
||||
mj_freeStack(d);
|
||||
|
||||
// compute L row addresses: rowadr = cumsum(rownnz)
|
||||
ctx->L_rowadr[0] = 0;
|
||||
for (int r=1; r < nv; r++) {
|
||||
ctx->L_rowadr[r] = ctx->L_rowadr[r-1] + ctx->L_rownnz[r-1];
|
||||
}
|
||||
|
||||
// allocate L_colind, L, Lcone
|
||||
ctx->L_colind = mjSTACKALLOC(d, ctx->nL, int);
|
||||
ctx->L = mjSTACKALLOC(d, ctx->nL, mjtNum);
|
||||
|
||||
Reference in New Issue
Block a user