27 transposed_matrix_(transposed_matrix),
28 variables_info_(variables_info),
30 basis_factorization_(basis_factorization),
31 unit_row_left_inverse_(),
32 non_zero_position_list_(),
33 non_zero_position_set_(),
35 compute_update_row_(true),
42 compute_update_row_ =
true;
47 if (
col >= coefficient_.
size())
return;
48 coefficient_[
col] = 0.0;
52 DCHECK(!compute_update_row_);
53 return unit_row_left_inverse_;
57 RowIndex leaving_row) {
60 &unit_row_left_inverse_);
61 return unit_row_left_inverse_;
64 void UpdateRow::ComputeUnitRowLeftInverse(RowIndex leaving_row) {
67 &unit_row_left_inverse_);
72 unit_row_left_inverse_.
values) -
79 if (!compute_update_row_ && update_row_computed_for_ == leaving_row)
return;
80 compute_update_row_ =
false;
81 update_row_computed_for_ = leaving_row;
82 ComputeUnitRowLeftInverse(leaving_row);
85 if (parameters_.use_transposed_matrix()) {
87 EntryIndex num_row_wise_entries(0);
99 const Fractional drop_tolerance = parameters_.drop_tolerance();
100 unit_row_left_inverse_filtered_non_zeros_.clear();
101 if (unit_row_left_inverse_.
non_zeros.empty()) {
102 const ColIndex size = unit_row_left_inverse_.
values.
size();
103 for (ColIndex
col(0);
col < size; ++
col) {
104 if (std::abs(unit_row_left_inverse_.
values[
col]) > drop_tolerance) {
105 unit_row_left_inverse_filtered_non_zeros_.push_back(
col);
110 for (
const auto e : unit_row_left_inverse_) {
111 if (std::abs(e.coefficient()) > drop_tolerance) {
112 unit_row_left_inverse_filtered_non_zeros_.push_back(e.column());
113 num_row_wise_entries +=
120 const EntryIndex num_col_wise_entries =
126 const double row_wise =
static_cast<double>(num_row_wise_entries.value());
127 if (row_wise < 0.5 *
static_cast<double>(num_col_wise_entries.value())) {
128 if (row_wise < 1.1 *
static_cast<double>(matrix_.
num_cols().value())) {
129 ComputeUpdatesRowWiseHypersparse();
130 num_operations_ += num_row_wise_entries.value();
132 ComputeUpdatesRowWise();
134 num_row_wise_entries.value() + matrix_.
num_rows().value();
137 ComputeUpdatesColumnWise();
139 num_col_wise_entries.value() + matrix_.
num_cols().value();
142 ComputeUpdatesColumnWise();
148 static_cast<double>(non_zero_position_list_.size()) /
149 static_cast<double>(matrix_.
num_cols().value())));
153 const std::string& algorithm) {
154 unit_row_left_inverse_.
values = lhs;
156 if (algorithm ==
"column") {
157 ComputeUpdatesColumnWise();
158 }
else if (algorithm ==
"row") {
159 ComputeUpdatesRowWise();
160 }
else if (algorithm ==
"row_hypersparse") {
161 ComputeUpdatesRowWiseHypersparse();
163 LOG(DFATAL) <<
"Unknown algorithm in ComputeUpdateRowForBenchmark(): '"
171 return non_zero_position_list_;
180 void UpdateRow::ComputeUpdatesRowWise() {
182 const ColIndex num_cols = matrix_.
num_cols();
184 for (ColIndex
col : unit_row_left_inverse_filtered_non_zeros_) {
186 for (
const EntryIndex i : transposed_matrix_.
Column(
col)) {
192 non_zero_position_list_.clear();
193 const Fractional drop_tolerance = parameters_.drop_tolerance();
195 if (std::abs(coefficient_[
col]) > drop_tolerance) {
196 non_zero_position_list_.push_back(
col);
203 void UpdateRow::ComputeUpdatesRowWiseHypersparse() {
205 const ColIndex num_cols = matrix_.
num_cols();
207 coefficient_.
resize(num_cols, 0.0);
208 for (ColIndex
col : unit_row_left_inverse_filtered_non_zeros_) {
210 for (
const EntryIndex i : transposed_matrix_.
Column(
col)) {
213 if (!non_zero_position_set_.
IsSet(pos)) {
218 coefficient_[pos] = v;
219 non_zero_position_set_.
Set(pos);
221 coefficient_[pos] += v;
228 non_zero_position_list_.clear();
229 const Fractional drop_tolerance = parameters_.drop_tolerance();
230 for (
const ColIndex
col : non_zero_position_set_) {
235 if (std::abs(coefficient_[
col]) > drop_tolerance) {
236 non_zero_position_list_.push_back(
col);
245 CHECK(!compute_update_row_);
246 const ColIndex num_cols = matrix_.
num_cols();
247 const Fractional drop_tolerance = parameters_.drop_tolerance();
248 coefficient_.
resize(num_cols, 0.0);
249 non_zero_position_list_.clear();
252 coefficient_[basis_[leaving_row]] = 1.0;
253 non_zero_position_list_.push_back(basis_[leaving_row]);
259 if (std::abs(coeff) > drop_tolerance) {
260 non_zero_position_list_.push_back(
col);
261 coefficient_[
col] = coeff;
266 void UpdateRow::ComputeUpdatesColumnWise() {
269 const ColIndex num_cols = matrix_.
num_cols();
270 const Fractional drop_tolerance = parameters_.drop_tolerance();
271 coefficient_.
resize(num_cols, 0.0);
272 non_zero_position_list_.clear();
281 if (std::abs(coeff) > drop_tolerance) {
282 non_zero_position_list_.push_back(
col);
283 coefficient_[
col] = coeff;