Migrate mjModel size fields from int to mjtSize.

This change updates all size-related members within the `mjModel` struct from `int` to `mjtSize`. This allows MuJoCo to handle models with a larger number of elements. Corresponding changes were made to macros, function signatures, and I/O routines to accommodate the new `mjtSize` type.

PiperOrigin-RevId: 860144595
Change-Id: I701c6d607715d240766b6210a9773cd9e4258c59
This commit is contained in:
Yuval Tassa
2026-01-23 09:40:42 -08:00
committed by Copybara-Service
parent 4a64017a5f
commit 30b903b6c0
24 changed files with 832 additions and 802 deletions
+1 -1
View File
@@ -261,7 +261,7 @@ MJDATA_VIEW_GROUPS
if constexpr (std::string_view(#dim) == std::string_view("1")) { \
return {}; \
} else { \
return {n}; \
return {(int)n}; \
} \
}() \
MUJOCO_DIAG_UNIGNORE_UNUSED_LAMBDA_CAPTURE
+86 -86
View File
@@ -849,432 +849,432 @@ STRUCTS: Mapping[str, StructDecl] = dict([
fields=(
StructFieldDecl(
name='nq',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of generalized coordinates = dim(qpos)',
),
StructFieldDecl(
name='nv',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of degrees of freedom = dim(qvel)',
),
StructFieldDecl(
name='nu',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of actuators/controls = dim(ctrl)',
),
StructFieldDecl(
name='na',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of activation states = dim(act)',
),
StructFieldDecl(
name='nbody',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of bodies',
),
StructFieldDecl(
name='nbvh',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of total bounding volumes in all bodies',
),
StructFieldDecl(
name='nbvhstatic',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of static bounding volumes (aabb stored in mjModel)', # pylint: disable=line-too-long
),
StructFieldDecl(
name='nbvhdynamic',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of dynamic bounding volumes (aabb stored in mjData)', # pylint: disable=line-too-long
),
StructFieldDecl(
name='noct',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of total octree cells in all meshes',
),
StructFieldDecl(
name='njnt',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of joints',
),
StructFieldDecl(
name='ntree',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of kinematic trees under world body',
),
StructFieldDecl(
name='nM',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse inertia matrix',
),
StructFieldDecl(
name='nB',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse body-dof matrix',
),
StructFieldDecl(
name='nC',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse reduced dof-dof matrix',
),
StructFieldDecl(
name='nD',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse dof-dof matrix',
),
StructFieldDecl(
name='ngeom',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of geoms',
),
StructFieldDecl(
name='nsite',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of sites',
),
StructFieldDecl(
name='ncam',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of cameras',
),
StructFieldDecl(
name='nlight',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of lights',
),
StructFieldDecl(
name='nflex',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of flexes',
),
StructFieldDecl(
name='nflexnode',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of dofs in all flexes',
),
StructFieldDecl(
name='nflexvert',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of vertices in all flexes',
),
StructFieldDecl(
name='nflexedge',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of edges in all flexes',
),
StructFieldDecl(
name='nflexelem',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of elements in all flexes',
),
StructFieldDecl(
name='nflexelemdata',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of element vertex ids in all flexes',
),
StructFieldDecl(
name='nflexelemedge',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of element edge ids in all flexes',
),
StructFieldDecl(
name='nflexshelldata',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of shell fragment vertex ids in all flexes',
),
StructFieldDecl(
name='nflexevpair',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of element-vertex pairs in all flexes',
),
StructFieldDecl(
name='nflextexcoord',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of vertices with texture coordinates',
),
StructFieldDecl(
name='nJfe',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse flexedge Jacobian matrix',
),
StructFieldDecl(
name='nJfv',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse flexvert Jacobian matrix',
),
StructFieldDecl(
name='nmesh',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of meshes',
),
StructFieldDecl(
name='nmeshvert',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of vertices in all meshes',
),
StructFieldDecl(
name='nmeshnormal',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of normals in all meshes',
),
StructFieldDecl(
name='nmeshtexcoord',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of texcoords in all meshes',
),
StructFieldDecl(
name='nmeshface',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of triangular faces in all meshes',
),
StructFieldDecl(
name='nmeshgraph',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of ints in mesh auxiliary data',
),
StructFieldDecl(
name='nmeshpoly',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of polygons in all meshes',
),
StructFieldDecl(
name='nmeshpolyvert',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of vertices in all polygons',
),
StructFieldDecl(
name='nmeshpolymap',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of polygons in vertex map',
),
StructFieldDecl(
name='nskin',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of skins',
),
StructFieldDecl(
name='nskinvert',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of vertices in all skins',
),
StructFieldDecl(
name='nskintexvert',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of vertices with texcoords in all skins',
),
StructFieldDecl(
name='nskinface',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of triangular faces in all skins',
),
StructFieldDecl(
name='nskinbone',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of bones in all skins',
),
StructFieldDecl(
name='nskinbonevert',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of vertices in all skin bones',
),
StructFieldDecl(
name='nhfield',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of heightfields',
),
StructFieldDecl(
name='nhfielddata',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of data points in all heightfields',
),
StructFieldDecl(
name='ntex',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of textures',
),
StructFieldDecl(
name='ntexdata',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of bytes in texture rgb data',
),
StructFieldDecl(
name='nmat',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of materials',
),
StructFieldDecl(
name='npair',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of predefined geom pairs',
),
StructFieldDecl(
name='nexclude',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of excluded geom pairs',
),
StructFieldDecl(
name='neq',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of equality constraints',
),
StructFieldDecl(
name='ntendon',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of tendons',
),
StructFieldDecl(
name='nwrap',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of wrap objects in all tendon paths',
),
StructFieldDecl(
name='nsensor',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of sensors',
),
StructFieldDecl(
name='nnumeric',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of numeric custom fields',
),
StructFieldDecl(
name='nnumericdata',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in all numeric fields',
),
StructFieldDecl(
name='ntext',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of text custom fields',
),
StructFieldDecl(
name='ntextdata',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtBytes in all text fields',
),
StructFieldDecl(
name='ntuple',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of tuple custom fields',
),
StructFieldDecl(
name='ntupledata',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of objects in all tuple fields',
),
StructFieldDecl(
name='nkey',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of keyframes',
),
StructFieldDecl(
name='nmocap',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mocap bodies',
),
StructFieldDecl(
name='nplugin',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of plugin instances',
),
StructFieldDecl(
name='npluginattr',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of chars in all plugin config attributes',
),
StructFieldDecl(
name='nuser_body',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in body_user',
),
StructFieldDecl(
name='nuser_jnt',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in jnt_user',
),
StructFieldDecl(
name='nuser_geom',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in geom_user',
),
StructFieldDecl(
name='nuser_site',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in site_user',
),
StructFieldDecl(
name='nuser_cam',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in cam_user',
),
StructFieldDecl(
name='nuser_tendon',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in tendon_user',
),
StructFieldDecl(
name='nuser_actuator',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in actuator_user',
),
StructFieldDecl(
name='nuser_sensor',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in sensor_user',
),
StructFieldDecl(
name='nnames',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of chars in all names',
),
StructFieldDecl(
name='npaths',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of chars in all paths',
),
StructFieldDecl(
name='nnames_map',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of slots in the names hash map',
),
StructFieldDecl(
name='nJmom',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse actuator_moment matrix',
),
StructFieldDecl(
name='ngravcomp',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of bodies with nonzero gravcomp',
),
StructFieldDecl(
name='nemax',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of potential equality-constraint rows',
),
StructFieldDecl(
name='njmax',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of available rows in constraint Jacobian (legacy)',
),
StructFieldDecl(
name='nconmax',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of potential contacts in contact list (legacy)',
),
StructFieldDecl(
name='nuserdata',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums reserved for the user',
),
StructFieldDecl(
name='nsensordata',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in sensor data vector',
),
StructFieldDecl(
name='npluginstate',
type=ValueType(name='int'),
type=ValueType(name='mjtSize'),
doc='number of mjtNums in plugin state vector',
),
StructFieldDecl(
+11 -7
View File
@@ -56,9 +56,13 @@ namespace {
// (dim0, dim1).
#define X_ARRAY_SHAPE(dim0, dim1) XArrayShapeImpl(#dim1)((dim0), (dim1))
std::vector<int> XArrayShapeImpl1D(int dim0, int dim1) { return {dim0}; }
std::vector<mjtSize> XArrayShapeImpl1D(mjtSize dim0, mjtSize dim1) {
return {dim0};
}
std::vector<int> XArrayShapeImpl2D(int dim0, int dim1) { return {dim0, dim1}; }
std::vector<mjtSize> XArrayShapeImpl2D(mjtSize dim0, mjtSize dim1) {
return {dim0, dim1};
}
constexpr auto XArrayShapeImpl(const std::string_view dim1_str) {
if (dim1_str == "1") {
@@ -401,20 +405,20 @@ This is useful for example when the MJB is not available as a file on disk.)"));
#define X(var) \
mjModel.def_property_readonly( \
#var, [](const MjModelWrapper& m) { return m.get()->var; });
MJMODEL_INTS
MJMODEL_SIZES
#undef X
mjModel.def_property_readonly("_sizes", [](const MjModelWrapper& m) {
int nint = 0;
#define X(var) ++nint;
MJMODEL_INTS
MJMODEL_SIZES
#undef X
py::array_t<std::int64_t> sizes(nint);
{
int i = 0;
auto data = sizes.mutable_unchecked();
#define X(var) data[i++] = m.get()->var;
MJMODEL_INTS
MJMODEL_SIZES
#undef X
}
py::detail::array_proxy(sizes.ptr())->flags &=
@@ -425,7 +429,7 @@ This is useful for example when the MJB is not available as a file on disk.)"));
mjModel.def_property_readonly_static("_size_fields", [](py::object) {
std::vector<std::string> fields;
#define X(var) fields.push_back(#var);
MJMODEL_INTS
MJMODEL_SIZES
#undef X
return py::tuple(py::cast(fields));
});
@@ -433,7 +437,7 @@ This is useful for example when the MJB is not available as a file on disk.)"));
mjModel.def_property_readonly_static("_all_fields", [](py::object) {
std::vector<std::string> fields;
#define X(var) fields.push_back(#var);
MJMODEL_INTS
MJMODEL_SIZES
#undef X
#define X(type, name, nr, nc) fields.push_back(#name);
MJMODEL_POINTERS
+2 -2
View File
@@ -1006,7 +1006,7 @@ using _impl::MjSolverStatList;
template <typename T, typename Shape>
std::enable_if_t<std::is_arithmetic_v<T>, pybind11::array_t<T>>
static InitPyArray(Shape&& shape, T* buf, pybind11::handle owner) {
int size = 1;
mjtSize size = 1;
for (const auto& i : shape) {
size *= i;
}
@@ -1043,7 +1043,7 @@ template <typename T, typename Shape>
std::enable_if_t<!std::is_arithmetic_v<T> && !is_mj_struct_list_v<T>,
pybind11::tuple>
static InitPyArray(Shape&& shape, T* buf, pybind11::handle owner) {
int size = 1;
mjtSize size = 1;
for (const auto& i : shape) {
size *= i;
}
+6 -2
View File
@@ -60,9 +60,13 @@ namespace {
// (dim0, dim1).
#define X_ARRAY_SHAPE(dim0, dim1) XArrayShapeImpl(#dim1)((dim0), (dim1))
std::vector<int> XArrayShapeImpl1D(int dim0, int dim1) { return {dim0}; }
std::vector<mjtSize> XArrayShapeImpl1D(mjtSize dim0, mjtSize dim1) {
return {dim0};
}
std::vector<int> XArrayShapeImpl2D(int dim0, int dim1) { return {dim0, dim1}; }
std::vector<mjtSize> XArrayShapeImpl2D(mjtSize dim0, mjtSize dim1) {
return {dim0, dim1};
}
constexpr auto XArrayShapeImpl(const std::string_view dim1_str) {
if (dim1_str == "1") {