Beispiel #1
0
void SparseMatrix::sortRowsByIncreasingPivots() {
  SparseMatrix ordered;
  const auto rowCount = this->rowCount();

  std::vector<RowIndex> rows(rowCount);
  for (RowIndex row = 0; row < rowCount; ++row)
    rows[row] = row;

  const auto lexLess = [&](const RowIndex a, const RowIndex b) -> bool {
    auto aIt = rowBegin(a);
    auto bIt = rowBegin(b);
    const auto aEnd = rowEnd(a);
    const auto bEnd = rowEnd(b);
    for (; aIt != aEnd && bIt != bEnd; ++aIt, ++bIt) {
      if (*aIt < *bIt)
        return true;
      if (*aIt > *bIt)
        return false;
      ++aIt;
      ++bIt;
    }
    return aIt == aEnd && bIt != bEnd;
  };
  std::sort(rows.begin(), rows.end(), lexLess);

  // construct ordered with pivot columns in increasing order
  ordered.clear();
  for (size_t i = 0; i < rowCount; ++i)
    ordered.appendRow(*this, rows[i]);
  *this = std::move(ordered);
}