Add nnz argument for size of allocated memory to mju_dense2sparse and check if this number is too small for number of non-zeros.

PiperOrigin-RevId: 690545825
Change-Id: I0e31cb907a1151cb2e4766d5f0cdfecb5629a2a6
This commit is contained in:
Taylor Howell
2024-10-28 03:46:00 -07:00
committed by Copybara-Service
parent 1c424644dd
commit a36f2cccb6
4 changed files with 63 additions and 15 deletions
+3 -2
View File
@@ -34,8 +34,9 @@ MJAPI mjtNum mju_dotSparse2(const mjtNum* vec1, const mjtNum* vec2, int nnz1, co
int nnz2, const int* ind2, int flg_unc2);
// convert matrix from dense to sparse
MJAPI void mju_dense2sparse(mjtNum* res, const mjtNum* mat, int nr, int nc,
int* rownnz, int* rowadr, int* colind);
// nnz is size of res and colind, return 1 if too small, 0 otherwise
MJAPI int mju_dense2sparse(mjtNum* res, const mjtNum* mat, int nr, int nc,
int* rownnz, int* rowadr, int* colind, int nnz);
// convert matrix from sparse to dense
MJAPI void mju_sparse2dense(mjtNum* res, const mjtNum* mat, int nr, int nc,