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

Method createRowwise

highs/util/HighsSparseMatrix.cpp:1051–1098  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1049}
1050
1051void HighsSparseMatrix::createRowwise(const HighsSparseMatrix& matrix) {
1052 assert(matrix.formatOk());
1053 assert(matrix.isColwise());
1054 assert(this->formatOk());
1055
1056 HighsInt num_col = matrix.num_col_;
1057 HighsInt num_row = matrix.num_row_;
1058 HighsInt num_nz = matrix.numNz();
1059 const vector<HighsInt>& a_start = matrix.start_;
1060 const vector<HighsInt>& a_index = matrix.index_;
1061 const vector<double>& a_value = matrix.value_;
1062 vector<HighsInt>& ar_start = this->start_;
1063 vector<HighsInt>& ar_index = this->index_;
1064 vector<double>& ar_value = this->value_;
1065
1066 // Use ar_end to compute lengths, which are then transformed into
1067 // the ends of the inserted entries
1068 std::vector<HighsInt> ar_end;
1069 ar_start.resize(num_row + 1);
1070 ar_end.assign(num_row, 0);
1071 // Count the nonzeros in each row
1072 for (HighsInt iCol = 0; iCol < num_col; iCol++) {
1073 for (HighsInt iEl = a_start[iCol]; iEl < a_start[iCol + 1]; iEl++) {
1074 HighsInt iRow = a_index[iEl];
1075 ar_end[iRow]++;
1076 }
1077 }
1078 // Compute the starts and turn the lengths into ends
1079 ar_start[0] = 0;
1080 for (HighsInt iRow = 0; iRow < num_row; iRow++) {
1081 ar_start[iRow + 1] = ar_start[iRow] + ar_end[iRow];
1082 ar_end[iRow] = ar_start[iRow];
1083 }
1084 ar_index.resize(num_nz);
1085 ar_value.resize(num_nz);
1086 // Insert the entries
1087 for (HighsInt iCol = 0; iCol < num_col; iCol++) {
1088 for (HighsInt iEl = a_start[iCol]; iEl < a_start[iCol + 1]; iEl++) {
1089 HighsInt iRow = a_index[iEl];
1090 HighsInt iToEl = ar_end[iRow]++;
1091 ar_index[iToEl] = iCol;
1092 ar_value[iToEl] = a_value[iEl];
1093 }
1094 }
1095 this->format_ = MatrixFormat::kRowwise;
1096 this->num_col_ = num_col;
1097 this->num_row_ = num_row;
1098}
1099
1100void HighsSparseMatrix::createColwise(const HighsSparseMatrix& matrix) {
1101 assert(matrix.formatOk());

Callers 2

feasibilityJumpMethod · 0.80
initSliceMethod · 0.80

Calls 4

formatOkMethod · 0.95
isColwiseMethod · 0.80
numNzMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected