Closed rushahead closed 1 year ago
Yes all matrices in the C interface are expected to be in column-major, unless another format is explicitly used in the routine naming, as e.g. here https://github.com/giaf/hpipm/blob/master/ocp_qp/x_ocp_qp.c#L610 where row-major is expected. Furthermore, in case of symmetric matrices (as e.g. the Hessian matrix), only the lower triangular part of the symmetric matrix is accessed, and the upper triangular part is disregarded.
So in your example above, in the HPIPM case, when you store the H matrix in column-major, the Hessian used internally looks like
double Hc[] = {0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,20,0,0,0,
0,0,0,20,0,0,
0,0,0,0,40, -40,
0,0,0,0, -40,40};
while when you store the matrix in row-major (i.e. you pass the transposed of your matrix H above), the Hessian used internally looks like
double Hr[] = {0,0,0,0,0,0,
0,0,0,0,0,0,
0,0,20,0,0,0,
0,0,0,20,0,0,
0,0,0,0,40, 0,
0,0,0,0, 0,40};
i.e. without the off-diagonal terms.
You can double check that the solutions returned by HPIPM and that you report above are indeed correct and consistent with this Hessian matrices by using another tool as e.g. qp
in octave.
I am not familiar with the OSQP interface but there may be similar assumptions on e.g. only the upper or lower triangular part of the symmetric Hessian matrix H being accessed.
Hello. I am using HPIPM now and just wanna to make sure if all matrices must be in column major? and matrix H seems not.
For example. I solve a problem with OSQP.
results are : [2.36370683e-08 1.49054196e+00 9.99999979e-01 2.22162614e+00 4.99999850e-01 1.94325252e+00] but if I use HPIPM to solve it can't get same resolution.
results are : [0.00000 1.56482 1.00000 2.44444 0.50000 2.38889] By the way, I don't use H with column-major, then I could get same result.
It's confusing to me. Could anyone help me with this ? Thanks in advance.