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 Blas Header

From Leeroopedia
Knowledge Sources
Domains Physics Simulation, Linear Algebra
Last Updated 2026-02-15 04:00 GMT

Overview

Header file declaring BLAS-like linear algebra utility functions and providing precision-dependent math library macro definitions for MuJoCo.

Description

This header serves two purposes. First, it defines precision-dependent macros that map generic math function names (mju_sqrt, mju_exp, mju_sin, mju_cos, mju_abs, etc.) to either double-precision (sqrt, fabs) or single-precision (sqrtf, fabsf) standard library functions, controlled by the mjUSESINGLE compile flag. Second, it declares the full BLAS-like API for MuJoCo: 3D vector operations (zero, copy, scale, add, subtract, normalize, dot, distance, cross product implied through matrix ops), 3x3 matrix-vector and matrix-matrix multiplications (including transposed variants), 4D quaternion operations (zero, unit, copy, normalize), general n-dimensional vector operations (zero, fill, copy, sum, L1 norm, scale, add, subtract, normalize, norm, dot), matrix-vector operations (mulMatVec, mulMatTVec, mulVecMatVec), and matrix operations (transpose, symmetrize, eye, mulMatMat, mulMatMatT, mulMatTMat, sqrMatTD). Several internal functions also support indexed variants for operating on selected subsets of elements.

Usage

Included by virtually every engine source file that performs numerical computation, providing the foundational arithmetic primitives.

Code Reference

Source Location

Key Functions

// Precision-dependent math macros
#define mju_sqrt    sqrt    // or sqrtf
#define mju_abs     fabs    // or fabsf
#define mju_sin     sin     // or sinf
#define mju_cos     cos     // or cosf

// 3D vector operations
MJAPI void mju_zero3(mjtNum res[3]);
MJAPI void mju_copy3(mjtNum res[3], const mjtNum vec[3]);
MJAPI void mju_scl3(mjtNum res[3], const mjtNum vec[3], mjtNum scl);
MJAPI mjtNum mju_normalize3(mjtNum vec[3]);
MJAPI mjtNum mju_dot3(const mjtNum vec1[3], const mjtNum vec2[3]);
MJAPI void mju_mulMatVec3(mjtNum res[3], const mjtNum mat[9], const mjtNum vec[3]);

// General vector operations
MJAPI void mju_zero(mjtNum* res, int n);
MJAPI void mju_copy(mjtNum* res, const mjtNum* vec, int n);
MJAPI mjtNum mju_dot(const mjtNum* vec1, const mjtNum* vec2, int n);
MJAPI mjtNum mju_norm(const mjtNum* res, int n);

// Matrix operations
MJAPI void mju_mulMatVec(mjtNum* res, const mjtNum* mat, const mjtNum* vec, int nr, int nc);
MJAPI void mju_transpose(mjtNum* res, const mjtNum* mat, int nr, int nc);
MJAPI void mju_mulMatMat(mjtNum* res, const mjtNum* mat1, const mjtNum* mat2, int r1, int c1, int c2);
MJAPI void mju_sqrMatTD(mjtNum* res, const mjtNum* mat, const mjtNum* diag, int nr, int nc);

Import

#include "engine/engine_util_blas.h"

I/O Contract

Inputs

Name Type Required Description
vec, vec1, vec2 mjtNum* Yes Input vectors
mat mjtNum* Yes Input matrix in row-major order
n, nr, nc int Yes Vector length or matrix dimensions
scl mjtNum No Scalar multiplier

Outputs

Name Type Description
res mjtNum* Result vector or matrix
return value mjtNum Scalar result for dot, norm, normalize, sum operations

Related Pages

Page Connections

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