Move mju_combineSparseCount into engine_util_sparse.
PiperOrigin-RevId: 561025741 Change-Id: I0bdc48554928fc4545a38a8cea3bdeb593bd7ecd
This commit is contained in:
committed by
Copybara-Service
parent
df1b3515c7
commit
ea5e00cad8
@@ -1351,33 +1351,6 @@ void mj_makeImpedance(const mjModel* m, mjData* d) {
|
||||
|
||||
//------------------------------------- constraint counting ----------------------------------------
|
||||
|
||||
// count the number of non-zeros in the sum of two sparse vectors
|
||||
int mju_combineSparseCount(int a_nnz, int b_nnz, const int* a_ind, const int* b_ind) {
|
||||
int a = 0, b = 0, c_nnz = 0;
|
||||
|
||||
// count c_nnz: nonzero indices common to both a and b
|
||||
while (a < a_nnz && b < b_nnz) {
|
||||
// common index, increment everything
|
||||
if (a_ind[a] == b_ind[b]) {
|
||||
c_nnz++;
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
|
||||
// update smallest index
|
||||
else if (a_ind[a] < b_ind[b]) {
|
||||
a++;
|
||||
} else {
|
||||
b++;
|
||||
}
|
||||
}
|
||||
|
||||
// union minus the intersection
|
||||
return a_nnz + b_nnz - c_nnz;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// count the non-zero columns in the Jacobian difference of two bodies
|
||||
static int mj_jacDifPairCount(const mjModel* m, int* chain,
|
||||
int b1, int b2, int issparse) {
|
||||
|
||||
@@ -93,13 +93,6 @@ void mj_diagApprox(const mjModel* m, mjData* d);
|
||||
// compute efc_R, efc_D, efc_KDIP, adjust diagApprox
|
||||
void mj_makeImpedance(const mjModel* m, mjData* d);
|
||||
|
||||
|
||||
//------------------------- constraint counting
|
||||
|
||||
// count the number of non-zeros in the sum of two sparse vectors
|
||||
MJAPI int mju_combineSparseCount(int a_nnz, int b_nnz, const int* a_ind, const int* b_ind);
|
||||
|
||||
|
||||
//---------------------------- top-level API for constraint construction ---------------------------
|
||||
|
||||
// main driver: call all functions above
|
||||
|
||||
@@ -207,6 +207,33 @@ static int mju_compare(const int* vec1, const int* vec2, int n) {
|
||||
|
||||
|
||||
|
||||
// count the number of non-zeros in the sum of two sparse vectors
|
||||
int mju_combineSparseCount(int a_nnz, int b_nnz, const int* a_ind, const int* b_ind) {
|
||||
int a = 0, b = 0, c_nnz = 0;
|
||||
|
||||
// count c_nnz: nonzero indices common to both a and b
|
||||
while (a < a_nnz && b < b_nnz) {
|
||||
// common index, increment everything
|
||||
if (a_ind[a] == b_ind[b]) {
|
||||
c_nnz++;
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
|
||||
// update smallest index
|
||||
else if (a_ind[a] < b_ind[b]) {
|
||||
a++;
|
||||
} else {
|
||||
b++;
|
||||
}
|
||||
}
|
||||
|
||||
// union minus the intersection
|
||||
return a_nnz + b_nnz - c_nnz;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// combine two sparse vectors: dst = a*dst + b*src, return nnz of result
|
||||
int mju_combineSparse(mjtNum* dst, const mjtNum* src, mjtNum a, mjtNum b,
|
||||
int dst_nnz, int src_nnz, int* dst_ind, const int* src_ind,
|
||||
|
||||
@@ -51,6 +51,9 @@ MJAPI void mju_mulMatVecSparse(mjtNum* res, const mjtNum* mat, const mjtNum* vec
|
||||
MJAPI void mju_compressSparse(mjtNum* mat, int nr, int nc,
|
||||
int* rownnz, int* rowadr, int* colind);
|
||||
|
||||
// count the number of non-zeros in the sum of two sparse vectors
|
||||
MJAPI int mju_combineSparseCount(int a_nnz, int b_nnz, const int* a_ind, const int* b_ind);
|
||||
|
||||
// combine two sparse vectors: dst = a*dst + b*src, return nnz of result
|
||||
int mju_combineSparse(mjtNum* dst, const mjtNum* src, mjtNum a, mjtNum b,
|
||||
int dst_nnz, int src_nnz, int* dst_ind, const int* src_ind,
|
||||
|
||||
Reference in New Issue
Block a user