Skip to content

Commit

Permalink
NFC: cleaning up comments
Browse files Browse the repository at this point in the history
  • Loading branch information
emma58 committed Jul 2, 2024
1 parent 18c848c commit 6548f29
Showing 1 changed file with 1 addition and 58 deletions.
59 changes: 1 addition & 58 deletions pyomo/repn/plugins/standard_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,6 @@ def write(self, model):
offset, linear_index, linear_data, _, _ = (
template_visitor.expand_expression(obj, obj.template_expr())
)
# <<<<<<< HEAD
# N = len(repn.linear)
# obj_data.append(self._to_vector(repn.linear))
# obj_offset.append(repn.constant)
# =======
N = len(linear_index)
obj_index.append(map(var_order.__getitem__, linear_index))
obj_data.append(linear_data)
Expand All @@ -374,8 +369,6 @@ def write(self, model):
repn = visitor.walk_expression(obj.expr)
N = len(repn.linear)
obj_index.append(map(var_order.__getitem__, repn.linear))
# ESJ TODO: This miiiight need a _to_vector call but I think it
# doesn't anymore?
obj_data.append(repn.linear.values())
obj_offset.append(repn.constant)

Expand All @@ -386,12 +379,8 @@ def write(self, model):
)

obj_nnz += N
# >>>>>>> templatized-writer
if set_sense is not None and set_sense != obj.sense:
# ESJ TODO: This is gonna need _to_vector I think
obj_data[-1] = -self._to_vector(
obj_data[-1], N, float
) # -np.fromiter(obj_data[-1], float, N)
obj_data[-1] = -self._to_vector(obj_data[-1], N, float)
obj_offset[-1] *= -1
obj_index_ptr.append(obj_index_ptr[-1] + N)
if with_debug_timing:
Expand Down Expand Up @@ -460,12 +449,6 @@ def write(self, model):
)

if mixed_form:
# <<<<<<< HEAD
# N = len(repn.linear)
# _data = self._to_vector(repn.linear)
# _index = np.fromiter(map(var_order.__getitem__, repn.linear), float, N)
# if ub == lb:
# =======
if lb == ub:
con_nnz += N
# >>>>>>> templatized-writer
Expand Down Expand Up @@ -519,12 +502,6 @@ def write(self, model):
con_index.append(linear_index)
con_index_ptr.append(con_nnz)
else:
# <<<<<<< HEAD
# N = len(repn.linear)
# _data = self._to_vector(repn.linear)
# _index = np.fromiter(map(var_order.__getitem__, repn.linear), float, N)
# =======
# >>>>>>> templatized-writer
if ub is not None:
if lb is not None:
linear_index = list(linear_index)
Expand Down Expand Up @@ -552,68 +529,34 @@ def write(self, model):
nCol = len(columns)
# Convert the compiled data to scipy sparse matrices
if obj_data:
# <<<<<<< HEAD
# obj_data = np.concatenate(obj_data)
# obj_index = np.concatenate(obj_index)
# c = self._csc_matrix_from_csr(
# obj_data, obj_index, obj_index_ptr, len(obj_index_ptr) - 1, len(columns)
# )
# if rows:
# con_data = np.concatenate(con_data)
# con_index = np.concatenate(con_index)
# A = self._csc_matrix_from_csr(
# con_data, con_index, con_index_ptr, len(rows), len(columns)
# )
# =======
# ESJ TODO: This is gonna need _to_vector...
obj_data = self._to_vector(
itertools.chain.from_iterable(obj_data), obj_nnz, np.float64
)
# obj_data = np.fromiter(
# itertools.chain.from_iterable(obj_data), np.float64, obj_nnz
# )
# obj_data = list(itertools.chain(*obj_data))
obj_index = np.fromiter(
itertools.chain.from_iterable(obj_index), np.int32, obj_nnz
)
# obj_index = list(itertools.chain(*obj_index))
obj_index_ptr = np.array(obj_index_ptr, dtype=np.int32)
c = self._csr_matrix(
obj_data, obj_index, obj_index_ptr, len(obj_index_ptr) - 1, nCol
)
# c = scipy.sparse.csr_array(
# (obj_data, obj_index, obj_index_ptr), [len(obj_index_ptr) - 1, nCol]
# )
c = c.tocsc()
c.sum_duplicates()
c.eliminate_zeros()
if rows:
con_data = self._to_vector(
itertools.chain.from_iterable(con_data), con_nnz, np.float64
)
# con_data = np.fromiter(
# itertools.chain.from_iterable(con_data), np.float64, con_nnz
# )
# con_data = list(itertools.chain(*con_data))
# con_index = np.fromiter(
# itertools.chain.from_iterable(con_index), np.int32, con_nnz
# )
con_index = self._to_vector(
itertools.chain.from_iterable(con_index), con_nnz, np.int32
)
# con_index = list(itertools.chain(*con_index))
con_index_ptr = np.array(con_index_ptr, dtype=np.int32)
A = self._csr_matrix(con_data, con_index, con_index_ptr, len(rows), nCol)
# A = scipy.sparse.csr_array(
# (con_data, con_index, con_index_ptr), [len(rows), nCol]
# )
A = A.tocsc()
A.sum_duplicates()
A.eliminate_zeros()

if with_debug_timing:
timer.toc('Formed matrices', level=logging.DEBUG)
# >>>>>>> templatized-writer

# Some variables in the var_map may not actually appear in the
# objective or constraints (e.g., added from col_order, or
Expand Down

0 comments on commit 6548f29

Please sign in to comment.