Fix type-related issues in dependent code. Remove hardcoded mjUSEDOUBLE. Add mjUSESINGLE compiler flag.
This CL does not change the default build behavior of MuJoCo. To use single-precision floating-point, build MuJoCo with `-DmjUSESINGLE`. PiperOrigin-RevId: 644782648 Change-Id: Ie815df9916798ca8054306437b39a33f84ce9e08
This commit is contained in:
committed by
Copybara-Service
parent
7bd7065e0e
commit
3f3b39bbb1
@@ -534,6 +534,14 @@ shown in the table below. Their names are in the format ``mjKEY_XXX``. They corr
|
||||
Macros
|
||||
^^^^^^
|
||||
|
||||
|
||||
.. _mjUSESINGLE:
|
||||
|
||||
mjUSESINGLE
|
||||
~~~~~~~~~~~
|
||||
|
||||
Compile-time flag, see :ref:`mjtNum`.
|
||||
|
||||
.. _mjDISABLED:
|
||||
|
||||
mjDISABLED
|
||||
|
||||
@@ -54,24 +54,28 @@ The two types below are defined in `mjtnum.h <https://github.com/google-deepmind
|
||||
mjtNum
|
||||
^^^^^^
|
||||
|
||||
This is the floating-point type used throughout the simulator. If the symbol ``mjUSEDOUBLE`` is defined in
|
||||
``mjmodel.h``, this type is defined as ``double``, otherwise it is defined as ``float``. Currently only the
|
||||
double-precision version of MuJoCo is distributed, although the entire code base works with single-precision as well.
|
||||
We may release the single-precision version in the future for efficiency reasons, but the double-precision version
|
||||
will always be available. Thus it is safe to write user code assuming double precision. However, our preference is to
|
||||
write code that works with either single or double precision. To this end we provide math utility functions that are
|
||||
always defined with the correct floating-point type.
|
||||
This is the floating-point type used throughout the simulator. When using the default build configuration, ``mjtNum`` is
|
||||
defined as ``double``. If the symbol ``mjUSESINGLE`` is defined, ``mjtNum`` is defined as ``float``.
|
||||
|
||||
Note that changing ``mjUSEDOUBLE`` in ``mjtnum.h`` will not change how the library was compiled, and instead will
|
||||
Currently only the double-precision version of MuJoCo is distributed, although the entire code base works with
|
||||
single-precision as well. We may release the single-precision version in the future, but the
|
||||
double-precision version will always be available. Thus it is safe to write user code assuming double precision.
|
||||
However, our preference is to write code that works with either single or double precision. To this end we provide math
|
||||
utility functions that are always defined with the correct floating-point type.
|
||||
|
||||
Note that changing ``mjUSESINGLE`` in ``mjtnum.h`` will not change how the library was compiled, and instead will
|
||||
result in numerous link errors. In general, the header files distributed with precompiled MuJoCo should never be
|
||||
changed by the user.
|
||||
|
||||
.. code-block:: C
|
||||
|
||||
#ifdef mjUSEDOUBLE
|
||||
typedef double mjtNum;
|
||||
// floating point data type and minval
|
||||
#ifndef mjUSESINGLE
|
||||
typedef double mjtNum;
|
||||
#define mjMINVAL 1E-15 // minimum value in any denominator
|
||||
#else
|
||||
typedef float mjtNum;
|
||||
typedef float mjtNum;
|
||||
#define mjMINVAL 1E-15f
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
+11
-5
@@ -25,12 +25,18 @@ General
|
||||
5. Added support for ``ball`` joints in the URDF parser ("spherical" in URDF).
|
||||
6. Deprecated :ref:`mju_rotVecMat` and :ref:`mju_rotVecMatT` in favor of :ref:`mju_mulMatVec3` and
|
||||
:ref:`mju_mulMatTVec3`. These functions names and argument ordering are more consistent with the rest of the API.
|
||||
7. Replaced ``mjUSEDOUBLE`` which was previously hard-coded in
|
||||
`mjtnum.h <https://github.com/google-deepmind/mujoco/blob/main/include/mujoco/mjtnum.h>`__
|
||||
with the build-time flag ``mjUSESINGLE``. If this symbol is not defined, MuJoCo will use double-precision floating
|
||||
point, as usual. If ``mjUSESINGLE`` is defined, MuJoCo will use single-precision floating point. See :ref:`mjtNum`.
|
||||
|
||||
Relatedly, fixed various type errors that prevented building with single-precision.
|
||||
|
||||
MJX
|
||||
~~~
|
||||
7. Added support for :ref:`elliptic friction cones<option-cone>`.
|
||||
8. Fixed a bug that resulted in less-optimal linesearch solutions for some difficult constraint settings.
|
||||
9. Fixed a bug in the Newton solver that sometimes resulted in less-optimal gradients.
|
||||
8. Added support for :ref:`elliptic friction cones<option-cone>`.
|
||||
9. Fixed a bug that resulted in less-optimal linesearch solutions for some difficult constraint settings.
|
||||
10. Fixed a bug in the Newton solver that sometimes resulted in less-optimal gradients.
|
||||
|
||||
|
||||
.. youtube:: P83tKA1iz2Y
|
||||
@@ -39,8 +45,8 @@ MJX
|
||||
|
||||
Simulate
|
||||
^^^^^^^^
|
||||
10. Added improved tutorial video.
|
||||
11. Improved the Brownian noise generator.
|
||||
11. Added improved tutorial video.
|
||||
12. Improved the Brownian noise generator.
|
||||
|
||||
|br| |br| |br| |br|
|
||||
|
||||
|
||||
Reference in New Issue
Block a user