Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Mujoco Engine Util Sparse

From Leeroopedia
Revision as of 12:45, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Google_deepmind_Mujoco_Engine_Util_Sparse.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Physics Simulation, Sparse Linear Algebra
Last Updated 2026-02-15 04:00 GMT

Overview

Implements sparse matrix and vector operations for MuJoCo's physics engine, using compressed sparse row (CSR) format with optional AVX SIMD acceleration.

Description

This file provides a comprehensive set of sparse linear algebra operations used in MuJoCo's constraint solver and dynamics pipeline. Key operations include sparse dot products (single-sparse and both-sparse variants), sparse matrix-vector multiplication with supernode support, dense-to-sparse and sparse-to-dense format conversions, sparse matrix addition and combination, sparse matrix transposition, supernode construction for performance optimization, and sparse M'*diag*M computation. The implementation dispatches to AVX-optimized versions when available. The sparse format uses CSR representation with rownnz (non-zeros per row), rowadr (row start addresses), and colind (column indices) arrays.

Usage

These functions are invoked during constraint Jacobian assembly, mass matrix operations, sparse Cholesky factorization, and anywhere the engine operates on large sparse matrices arising from the system topology.

Code Reference

Source Location

Key Functions

// Sparse dot products
void mju_dotSparseX3(mjtNum* res0, mjtNum* res1, mjtNum* res2,
                     const mjtNum* vec10, const mjtNum* vec11, const mjtNum* vec12,
                     const mjtNum* vec2, int nnz1, const int* ind1);
mjtNum mju_dotSparse2(const mjtNum* vec1, const int* ind1, int nnz1,
                      const mjtNum* vec2, const int* ind2, int nnz2);

// Format conversion
int mju_dense2sparse(mjtNum* res, const mjtNum* mat, int nr, int nc,
                     int* rownnz, int* rowadr, int* colind, int nnz);
void mju_sparse2dense(mjtNum* res, const mjtNum* mat, int nr, int nc,
                      const int* rownnz, const int* rowadr, const int* colind);

// Sparse matrix-vector
void mju_mulMatVecSparse(mjtNum* res, const mjtNum* mat, const mjtNum* vec,
                         int nr, const int* rownnz, const int* rowadr,
                         const int* colind, const int* rowsuper);

// Sparse matrix operations
void mju_transposeSparse(mjtNum* res, const mjtNum* mat, int nr, int nc, ...);
void mju_sqrMatTDSparse(mjtNum* res, const mjtNum* mat, const mjtNum* matT,
                        const mjtNum* diag, int nr, int nc, ...);
int mju_compressSparse(mjtNum* mat, int nr, int nc,
                       int* rownnz, int* rowadr, int* colind, mjtNum minval);

Import

#include "engine/engine_util_sparse.h"

I/O Contract

Inputs

Name Type Required Description
mat mjtNum* Yes Sparse matrix values in CSR format
vec mjtNum* Yes Dense vector for matrix-vector operations
nr, nc int Yes Number of rows and columns
rownnz int* Yes Number of non-zeros per row
rowadr int* Yes Starting address of each row in colind/mat arrays
colind int* Yes Column indices of non-zero elements
rowsuper int* No Supernode sizes for optimized matrix-vector multiply

Outputs

Name Type Description
res mjtNum* Result vector or matrix
return value int/mjtNum Number of non-zeros, or scalar dot product result

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment