Skip to content

Commit

Permalink
export lp_data from google3
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Sep 18, 2024
1 parent 98d0a3a commit fd00bf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions ortools/lp_data/sparse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "absl/log/check.h"
#include "absl/strings/str_format.h"
#include "absl/types/span.h"
#include "ortools/lp_data/lp_types.h"
#include "ortools/lp_data/permutation.h"
#include "ortools/lp_data/sparse_column.h"
Expand Down Expand Up @@ -592,7 +593,7 @@ ColIndex CompactSparseMatrix::AddDenseColumnPrefix(
}

ColIndex CompactSparseMatrix::AddDenseColumnWithNonZeros(
const DenseColumn& dense_column, const std::vector<RowIndex>& non_zeros) {
const DenseColumn& dense_column, absl::Span<const RowIndex> non_zeros) {
if (non_zeros.empty()) return AddDenseColumn(dense_column);
for (const RowIndex row : non_zeros) {
const Fractional value = dense_column[row];
Expand Down Expand Up @@ -1459,17 +1460,20 @@ void TriangularMatrix::ComputeRowsToConsiderInSortedOrder(
}

stored_.Resize(num_rows_);
for (const RowIndex row : *non_zero_rows) stored_.Set(row);
Bitset64<RowIndex>::View stored = stored_.view();
for (const RowIndex row : *non_zero_rows) {
stored.Set(row);
}

const auto entry_rows = rows_.view();
for (int i = 0; i < non_zero_rows->size(); ++i) {
const RowIndex row = (*non_zero_rows)[i];
for (const EntryIndex index : Column(RowToColIndex(row))) {
++num_ops;
const RowIndex entry_row = entry_rows[index];
if (!stored_[entry_row]) {
if (!stored[entry_row]) {
non_zero_rows->push_back(entry_row);
stored_.Set(entry_row);
stored.Set(entry_row);
}
}
if (num_ops > num_ops_threshold) break;
Expand All @@ -1480,7 +1484,9 @@ void TriangularMatrix::ComputeRowsToConsiderInSortedOrder(
non_zero_rows->clear();
} else {
std::sort(non_zero_rows->begin(), non_zero_rows->end());
for (const RowIndex row : *non_zero_rows) stored_.ClearBucket(row);
for (const RowIndex row : *non_zero_rows) {
stored_.ClearBucket(row);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ortools/lp_data/sparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class CompactSparseMatrix {
// Same as AddDenseColumn(), but uses the given non_zeros pattern of input.
// If non_zeros is empty, this actually calls AddDenseColumn().
ColIndex AddDenseColumnWithNonZeros(const DenseColumn& dense_column,
const std::vector<RowIndex>& non_zeros);
absl::Span<const RowIndex> non_zeros);

// Adds a dense column for which we know the non-zero positions and clears it.
// Note that this function supports duplicate indices in non_zeros. The
Expand Down

0 comments on commit fd00bf8

Please sign in to comment.