Switch mj_solveM2 to use CSR representation.
PiperOrigin-RevId: 717639495 Change-Id: I59eee0f23606481480ec5acb8a3bba2c14b2ea2f
This commit is contained in:
committed by
Copybara-Service
parent
baf1c43b3c
commit
a5ab7a9515
@@ -1668,9 +1668,10 @@ void mj_solveLDs(mjtNum* restrict x, const mjtNum* qLDs, const mjtNum* qLDiagInv
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int adr = rowadr[i];
|
int d;
|
||||||
int d = rownnz[i] - 1;
|
if ((d = rownnz[i] - 1) > 0) {
|
||||||
if (d > 0) {
|
int adr = rowadr[i];
|
||||||
|
|
||||||
// one vector
|
// one vector
|
||||||
if (n == 1) {
|
if (n == 1) {
|
||||||
x[i] -= mju_dotSparse(qLDs+adr, x, d, colind+adr, /*flg_unc1=*/0);
|
x[i] -= mju_dotSparse(qLDs+adr, x, d, colind+adr, /*flg_unc1=*/0);
|
||||||
@@ -1769,41 +1770,53 @@ void mj_solveM_island(const mjModel* m, const mjData* d, mjtNum* restrict x, int
|
|||||||
void mj_solveM2(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y,
|
void mj_solveM2(const mjModel* m, mjData* d, mjtNum* x, const mjtNum* y,
|
||||||
const mjtNum* sqrtInvD, int n) {
|
const mjtNum* sqrtInvD, int n) {
|
||||||
// local copies of key variables
|
// local copies of key variables
|
||||||
mjtNum* qLD = d->qLD;
|
int nv = m->nv, nC = m->nC;
|
||||||
int* dof_Madr = m->dof_Madr;
|
const int* rownnz = d->C_rownnz;
|
||||||
int* dof_parentid = m->dof_parentid;
|
const int* rowadr = d->C_rowadr;
|
||||||
int nv = m->nv;
|
const int* colind = d->C_colind;
|
||||||
|
const int* diagnum = m->dof_simplenum;
|
||||||
|
|
||||||
// x = y
|
// x = y
|
||||||
mju_copy(x, y, n * nv);
|
mju_copy(x, y, n * nv);
|
||||||
|
|
||||||
// loop over the n input vectors
|
// temporary: make local CSR version of qLD
|
||||||
for (int ivec=0; ivec < n; ivec++) {
|
mj_markStack(d);
|
||||||
int offset = ivec*nv;
|
mjtNum* qLD = mjSTACKALLOC(d, nC, mjtNum);
|
||||||
|
for (int i=0; i < nC; i++) {
|
||||||
|
qLD[i] = d->qLD[d->mapM2C[i]];
|
||||||
|
}
|
||||||
|
|
||||||
// x <- inv(L') * x; skip simple, exploit sparsity of input vector
|
// x <- L^-T x
|
||||||
for (int i=nv-1; i >= 0; i--) {
|
for (int i=nv-1; i > 0; i--) {
|
||||||
mjtNum tmp;
|
// skip diagonal rows
|
||||||
if (!m->dof_simplenum[i] && (tmp = x[i+offset])) {
|
if (diagnum[i]) {
|
||||||
// init
|
continue;
|
||||||
int Madr_ij = dof_Madr[i]+1;
|
}
|
||||||
int j = dof_parentid[i];
|
|
||||||
|
|
||||||
// traverse ancestors backwards
|
// prepare row i column address range
|
||||||
while (j >= 0) {
|
int start = rowadr[i];
|
||||||
x[j+offset] -= qLD[Madr_ij++] * tmp; // x(j) -= L(i,j) * x(i)
|
int end = start + rownnz[i] - 1;
|
||||||
|
|
||||||
// advance to parent
|
// process all vectors
|
||||||
j = dof_parentid[j];
|
for (int offset=0; offset < n*nv; offset+=nv) {
|
||||||
|
mjtNum x_i;
|
||||||
|
if ((x_i = x[i+offset])) {
|
||||||
|
for (int adr=start; adr < end; adr++) {
|
||||||
|
x[offset + colind[adr]] -= qLD[adr] * x_i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// x <- sqrt(inv(D)) * x
|
// x <- D^-1/2 x
|
||||||
for (int i=0; i < nv; i++) {
|
for (int i=0; i < nv; i++) {
|
||||||
x[i+offset] *= sqrtInvD[i]; // x(i) /= sqrt(L(i,i))
|
mjtNum invD_i = sqrtInvD[i];
|
||||||
|
for (int offset=0; offset < n*nv; offset+=nv) {
|
||||||
|
x[i+offset] *= invD_i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mj_freeStack(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user