Skip to content

Commit

Permalink
Merging the the fix for the 0-matrix case because I'm not crazy
Browse files Browse the repository at this point in the history
  • Loading branch information
emma58 committed Jul 8, 2024
2 parents b0f9182 + 7605eb2 commit f016a6b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions pyomo/repn/plugins/standard_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,18 +573,22 @@ def write(self, model):
return info

def _create_csc(self, data, index, index_ptr, nnz, nCol):
# ESJ TODO: I don't understand why, but even the standard form tests
# don't pass with these two lines uncommented... I'm not sure what
# changed here compared to the templatized-writer branch...
# if not nnz:
# return self._csc_matrix(data, index, index_ptr, nnz, nCol)

data = self._to_vector(
itertools.chain.from_iterable(data), nnz, np.float64
)
index = self._to_vector(
itertools.chain.from_iterable(index), nnz, np.int32
)
if not nnz:
# The empty CSC has no (or few) rows and a large number of
# columns and no nonzeros: it is faster / easier to create
# the empty CSR on the python side and convert it to CSC on
# the C (numpy) side, as opposed to ceating the large [0] *
# (nCol + 1) array on the Python side and transfer it to C
# (numpy)
return self._csr_matrix(data, index, index_ptr, len(index_ptr) - 1, nCol).tocsc()
# return scipy.sparse.csr_array(
# (data, index, index_ptr), [len(index_ptr) - 1, nCol]
# ).tocsc()

data = self._to_vector(itertools.chain.from_iterable(data), nnz, np.float64)
# data = list(itertools.chain(*data))
index = self._to_vector(itertools.chain.from_iterable(index), nnz, np.int32)
# index = list(itertools.chain(*index))
index_ptr = np.array(index_ptr, dtype=np.int32)
A = self._csr_matrix(data, index, index_ptr, len(index_ptr) - 1, nCol)
A = A.tocsc()
Expand Down

0 comments on commit f016a6b

Please sign in to comment.