@@ -47,10 +47,12 @@ inline ScalarFunctionQuadraticApproximation getRandomCost(int n, int m) {
4747 QPPR = QPPR.transpose () * QPPR;
4848 ScalarFunctionQuadraticApproximation cost;
4949 cost.dfdxx = QPPR.topLeftCorner (n, n);
50- cost.dfdux = QPPR.bottomLeftCorner (m, n);
51- cost.dfduu = QPPR.bottomRightCorner (m, m);
5250 cost.dfdx = vector_t::Random (n);
53- cost.dfdu = vector_t::Random (m);
51+ if (m > 0 ) {
52+ cost.dfdux = QPPR.bottomLeftCorner (m, n);
53+ cost.dfduu = QPPR.bottomRightCorner (m, m);
54+ cost.dfdu = vector_t::Random (m);
55+ }
5456 cost.f = std::rand () / static_cast <scalar_t >(RAND_MAX);
5557 return cost;
5658}
@@ -67,7 +69,9 @@ inline std::unique_ptr<ocs2::StateCost> getOcs2StateCost(const ScalarFunctionQua
6769inline VectorFunctionLinearApproximation getRandomDynamics (int n, int m) {
6870 VectorFunctionLinearApproximation dynamics;
6971 dynamics.dfdx = matrix_t::Random (n, n);
70- dynamics.dfdu = matrix_t::Random (n, m);
72+ if (m > 0 ) {
73+ dynamics.dfdu = matrix_t::Random (n, m);
74+ }
7175 dynamics.f = vector_t::Random (n);
7276 return dynamics;
7377}
@@ -80,7 +84,9 @@ inline std::unique_ptr<ocs2::LinearSystemDynamics> getOcs2Dynamics(const VectorF
8084inline VectorFunctionLinearApproximation getRandomConstraints (int n, int m, int nc) {
8185 VectorFunctionLinearApproximation constraints;
8286 constraints.dfdx = matrix_t::Random (nc, n);
83- constraints.dfdu = matrix_t::Random (nc, m);
87+ if (m > 0 ) {
88+ constraints.dfdu = matrix_t::Random (nc, m);
89+ }
8490 constraints.f = vector_t::Random (nc);
8591 return constraints;
8692}
0 commit comments