Skip to content

Commit

Permalink
fix SGP A matrix generation for (dis)appearing exponents (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
bqpd committed Mar 7, 2020
1 parent b6fd017 commit e117a34
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions gpkit/constraints/sgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,18 @@ def gp(self, x0=None, *, cleanx0=False):
self._gp.exps[m_idx + i] = exp
self._gp.cs[m_idx + i] = c
for var, x in exp.items():
row_idx = a_idxs.pop() # modify a particular A entry
self._gp.A.row[row_idx] = m_idx + i
self._gp.A.col[row_idx] = self._gp.varidxs[var]
self._gp.A.data[row_idx] = x
try: # modify a particular A entry
row_idx = a_idxs.pop()
self._gp.A.row[row_idx] = m_idx + i
self._gp.A.col[row_idx] = self._gp.varidxs[var]
self._gp.A.data[row_idx] = x
except IndexError: # numbers of exps increased
self.a_idxs[p_idx].append(len(self._gp.A.row))
self._gp.A.row.append(m_idx + i)
self._gp.A.col.append(self._gp.varidxs[var])
self._gp.A.data.append(x)
for row_idx in a_idxs: # number of exps decreased
self._gp.A.row[row_idx] = 0 # zero out this entry
self._gp.A.col[row_idx] = 0
self._gp.A.data[row_idx] = 0
return self._gp

0 comments on commit e117a34

Please sign in to comment.