Skip to content

Commit 6eeebb7

Browse files
committed
cleaner build parameter dict
1 parent ba3af1e commit 6eeebb7

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

  • cvxpy/reductions/solvers/nlp_solvers/diff_engine

cvxpy/reductions/solvers/nlp_solvers/diff_engine/helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def build_var_dict(inverse_data):
9292
def build_param_dict(problem, inverse_data):
9393
"""Build {param_id: C parameter capsule} mapping from InverseData."""
9494
n_vars = inverse_data.x_length
95+
param_by_id = {p.id: p for p in problem.parameters()}
9596
param_dict = {}
9697
for param_id, offset in inverse_data.param_id_map.items():
9798
# this is needed to not get key errors with Constants.
@@ -100,7 +101,7 @@ def build_param_dict(problem, inverse_data):
100101
d1, d2 = normalize_shape(inverse_data.param_shapes[param_id])
101102
# TODO this is a bit hacky, potentially we can just store the initial
102103
# values in the InverseData, but we need to discuss with others.
103-
param = next(p for p in problem.parameters() if p.id == param_id)
104+
param = param_by_id[param_id]
104105
p = to_dense_float(param.value)
105106
param_dict[param_id] = _diffengine.make_parameter(
106107
d1, d2, offset, n_vars, p.flatten(order='F'))

0 commit comments

Comments
 (0)