Skip to content

Commit 7291200

Browse files
authored
[_dq_quadprog_solver.py] Addressing bug when called via cpp.
Empty matrices are sent by the `cpp` side and these were not being processed correctly.
1 parent 538b6a9 commit 7291200

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

dqrobotics/solvers/_dq_quadprog_solver.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ def solve_quadratic_program(self, H, f, A, b, Aeq, beq):
6262
:param beq: the m x 1 value for the inequality constraints.
6363
:return: the optimal x
6464
"""
65+
# Calls from dqrobotics-cpp will trigger these conditions if empty matrices/vectors are arguments.
66+
if A.shape == (0, 0):
67+
A = None
68+
if b.shape == 0:
69+
b = None
70+
if Aeq.shape == (0, 0):
71+
Aeq = None
72+
if beq.shape == 0:
73+
beq = None
74+
6575
if A is None and b is None and Aeq is None and beq is None:
6676
raise ValueError("A, b, Aeq, beq, cannot all be None.")
6777
if (A is None and b is not None) or (b is None and A is not None):
@@ -73,12 +83,9 @@ def solve_quadratic_program(self, H, f, A, b, Aeq, beq):
7383
## Aeq.x <= beq + delta
7484
## Aeq.x >= beq - delta ==> -Aeq.x <= -beq + delta
7585
if Aeq is not None: # beq is None already checked by the ValueError
76-
if Aeq.shape == (0, 0) or beq.shape == 0:
77-
pass
78-
else:
79-
Aeq = np.vstack([Aeq, -Aeq])
80-
beq = beq.reshape(-1)
81-
beq = np.concatenate([beq + self.equality_constraints_tolerance, -beq + self.equality_constraints_tolerance])
86+
Aeq = np.vstack([Aeq, -Aeq])
87+
beq = beq.reshape(-1)
88+
beq = np.concatenate([beq + self.equality_constraints_tolerance, -beq + self.equality_constraints_tolerance])
8289

8390
# Use (A,b), (Aeq,beq), or both.
8491
if Aeq is None:
@@ -91,11 +98,6 @@ def solve_quadratic_program(self, H, f, A, b, Aeq, beq):
9198
A_internal = np.vstack([A, Aeq])
9299
b_internal = np.concatenate([b.reshape(-1), beq])
93100

94-
# Calls from DQRobotics CPP will trigger this condition
95-
if A_internal.shape == (0, 0) or b_internal.shape == 0:
96-
A_internal = np.zeros((1, H.shape[0]))
97-
b_internal = np.zeros(1)
98-
99101
(x, f, xu, iterations, lagrangian, iact) = quadprog.solve_qp(G=H,
100102
a=-f,
101103
C=-np.transpose(A_internal),

0 commit comments

Comments
 (0)