MCPcopy Create free account
hub / github.com/ERGO-Code/HiGHS / ensureRowwise

Method ensureRowwise

highs/util/HighsSparseMatrix.cpp:176–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176void HighsSparseMatrix::ensureRowwise() {
177 assert(this->formatOk());
178 if (this->isRowwise()) return;
179 HighsInt num_col = this->num_col_;
180 HighsInt num_row = this->num_row_;
181 HighsInt num_nz = this->numNz();
182 assert(num_nz >= 0);
183 assert((HighsInt)this->index_.size() >= num_nz);
184 assert((HighsInt)this->value_.size() >= num_nz);
185 if (num_nz == 0) {
186 // Empty matrix, so just ensure that there are enough zero starts
187 // for the new orientation
188 this->start_.assign(num_row + 1, 0);
189 this->index_.clear();
190 this->value_.clear();
191 } else {
192 // Matrix is non-empty, so transpose it
193 //
194 // Take a copy of the current matrix - that is colwise - so that
195 // the current matrix is filled rowwise
196 vector<HighsInt> Astart = this->start_;
197 vector<HighsInt> Aindex = this->index_;
198 vector<double> Avalue = this->value_;
199 this->start_.resize(num_row + 1);
200 this->index_.resize(num_nz);
201 this->value_.resize(num_nz);
202 vector<HighsInt> ARlength;
203 ARlength.assign(num_row, 0);
204 for (HighsInt iEl = Astart[0]; iEl < num_nz; iEl++) ARlength[Aindex[iEl]]++;
205 this->start_[0] = 0;
206 for (HighsInt iRow = 0; iRow < num_row; iRow++)
207 this->start_[iRow + 1] = this->start_[iRow] + ARlength[iRow];
208 for (HighsInt iCol = 0; iCol < num_col; iCol++) {
209 for (HighsInt iEl = Astart[iCol]; iEl < Astart[iCol + 1]; iEl++) {
210 HighsInt iRow = Aindex[iEl];
211 HighsInt iRow_el = this->start_[iRow];
212 this->index_[iRow_el] = iCol;
213 this->value_[iRow_el] = Avalue[iEl];
214 this->start_[iRow]++;
215 }
216 }
217 this->start_[0] = 0;
218 for (HighsInt iRow = 0; iRow < num_row; iRow++)
219 this->start_[iRow + 1] = this->start_[iRow] + ARlength[iRow];
220 assert(this->start_[num_row] == num_nz);
221 }
222 this->format_ = MatrixFormat::kRowwise;
223 assert((HighsInt)this->start_.size() >= num_row + 1);
224 num_nz = this->numNz();
225 assert(num_nz >= 0);
226 assert((HighsInt)this->index_.size() >= num_nz);
227 assert((HighsInt)this->value_.size() >= num_nz);
228}
229
230void HighsSparseMatrix::addVec(const HighsInt num_nz, const HighsInt* index,
231 const double* value, const double multiple) {

Callers 3

setFormatMethod · 0.95
addRowsMethod · 0.95
equivalentMethod · 0.45

Calls 6

formatOkMethod · 0.95
isRowwiseMethod · 0.95
numNzMethod · 0.95
sizeMethod · 0.45
clearMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected