Skip to content

Commit

Permalink
fix: storing constraints as numpy array
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachlan Grose committed Feb 15, 2022
1 parent 388e21f commit 6c75379
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions LoopStructural/interpolators/discrete_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,19 +278,14 @@ def add_equality_constraints(self, node_idx, values, name="undefined"):
idc = gi[node_idx]
outside = ~(idc == -1)
self.equal_constraints[name] = {
"A": np.ones(idc[outside].shape[0]).tolist(),
"B": values[outside].tolist(),
"col": idc[outside].tolist(),
"A": np.ones(idc[outside].shape[0]),
"B": values[outside],
"col": idc[outside],
# "w": w,
"row": np.arange(self.eq_const_c, self.eq_const_c + idc[outside].shape[0]),
}
self.eq_const_c += idc[outside].shape[0]
# ,'C':np.ones(idc[outside].shape[0]).tolist(),}
# self.eq_const_C.extend(np.ones(idc[outside].shape[0]).tolist())
# self.eq_const_col.extend(idc[outside].tolist())
# self.eq_const_row.extend((np.arange(0, idc[outside].shape[0])))
# self.eq_const_d.extend(values[outside].tolist())
# self.eq_const_c_ += idc[outside].shape[0]


def add_non_linear_constraints(self, nonlinear_constraint):
self.non_linear_constraints.append(nonlinear_constraint)
Expand Down Expand Up @@ -441,10 +436,9 @@ def build_matrix(self, square=True, damp=0.0, ie=False):
# lagrange multipliers#
nc = 0
for c in self.equal_constraints.values():
aa = (c["A"]).flatten()
b.extend((c["B"]).tolist())
mask = aa == 0
a.extend(aa[~mask].tolist())
a.extend(c["A"]).flatten()[~mask].tolist())
rows.extend(c["row"].flatten()[~mask].tolist())
cols.extend(c["col"].flatten()[~mask].tolist())
C = coo_matrix(
Expand Down

0 comments on commit 6c75379

Please sign in to comment.