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 Header

From Leeroopedia
Revision as of 12:45, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Google_deepmind_Mujoco_Engine_Util_Sparse_Header.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

Header file declaring sparse matrix and vector operation interfaces for MuJoCo, including both external API functions and performance-critical inlined operations.

Description

This header declares the public API and internal inline functions for MuJoCo's sparse linear algebra subsystem. It includes declarations for sparse dot products, dense-to-sparse and sparse-to-dense conversions, sparse matrix-vector multiplication (with transposed and symmetric variants), sparse matrix addition and compression, supernode construction, transpose, and sparse M'*diag*M computation. Notably, several performance-critical functions are defined as static inline directly in this header, including mju_dotSparse (sparse dot product with AVX dispatch), mju_compare (integer vector comparison), mj_mergeSorted (sorted integer merge), mju_addToSclScl (scaled vector accumulation), and mju_combineSparse (sparse vector linear combination). This design avoids function call overhead for these frequently called operations.

Usage

Included by any engine source file that needs to perform sparse matrix or vector operations, particularly the solver, factorization, and constraint assembly modules.

Code Reference

Source Location

Key Functions

// Declared API functions
MJAPI mjtNum mju_dotSparse2(const mjtNum* vec1, const int* ind1, int nnz1,
                            const mjtNum* vec2, const int* ind2, int nnz2);
MJAPI int mju_dense2sparse(mjtNum* res, const mjtNum* mat, int nr, int nc,
                           int* rownnz, int* rowadr, int* colind, int nnz);
MJAPI 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);
MJAPI void mju_transposeSparse(mjtNum* res, const mjtNum* mat, int nr, int nc, ...);

// Inlined functions (defined in header)
static inline mjtNum mju_dotSparse(const mjtNum* vec1, const mjtNum* vec2,
                                   int nnz1, const int* ind1);
static inline int mju_compare(const int* vec1, const int* vec2, int n);
static inline int mj_mergeSorted(int* merge, const int* chain1, int n1,
                                 const int* chain2, int n2);
static inline void mju_addToSclScl(mjtNum* res, const mjtNum* vec,
                                   mjtNum scl1, mjtNum scl2, int n);
static inline 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,
                                    mjtNum* buf, int* buf_ind);

Import

#include "engine/engine_util_sparse.h"

I/O Contract

Inputs

Name Type Required Description
vec1, vec2 mjtNum* Yes Sparse or dense vectors for operations
mat mjtNum* Yes Sparse matrix values in CSR format
rownnz, rowadr, colind int* Yes CSR sparse structure arrays
nr, nc int Yes Matrix dimensions (rows, columns)

Outputs

Name Type Description
res, dst mjtNum* Output vector or matrix
return value mjtNum or int Dot product result, or number of non-zeros

Related Pages

Page Connections

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