google-deepmind / mujoco_mpc

Real-time behaviour synthesis with MuJoCo, using Predictive Control
https://github.com/deepmind/mujoco_mpc
Apache License 2.0
982 stars 148 forks source link

Question about A, B C and D matrices ordering in memory? #277

Closed DMackRus closed 8 months ago

DMackRus commented 8 months ago

Hello,

I am trying to fix some bugs in my code and want to make sure one of my assumptions is correct.

I think that the A, B, C and D matrices are ordered in memory column-wise rather than row-wise? I.e lets say you have a 4x4 A matrix The elements would be ordered like

0 4 9 13 1 5 10 14 2 6 11 15 3 7 12 16

Is this correct?

thowell commented 8 months ago

My previous response was incorrect. The matrices manipulated by MuJoCo routines are row-major (C convention) and the A, B, C, D matrices computed here are similarly row-major.

yuvaltassa commented 8 months ago

As a side note, there is a currently unexposed function "mjd_stepFD" which does use column-major, but then everything is transposed, in case you want column-major for some reason (though transpose is very cheap.)