3 #include <cmr/config.h>
4 #include <cmr/export.h>
6 #include <boost/numeric/ublas/matrix.hpp>
16 template <
typename Iterator>
27 : _begin(other._begin), _end(other._end)
91 : _matrix(matrix), _major(major), _minor(0)
95 while (_minor < _matrix.numColumns() && _matrix.get(_major, _minor) == 0)
100 while (_minor < _matrix.numRows() && _matrix.get(_minor, _major) == 0)
106 : _matrix(matrix), _major(major)
111 _minor = _matrix.numColumns();
113 _minor = _matrix.numRows();
121 while (_minor < _matrix.numColumns() && _matrix.get(_major, _minor) == 0)
126 while (_minor < _matrix.numRows() && _matrix.get(_minor, _major) == 0)
135 assert(_major < _matrix.numRows());
136 assert(_minor < _matrix.numColumns());
137 return Nonzero(_major, _minor, _matrix.get(_major, _minor));
141 assert(_minor < _matrix.numRows());
142 assert(_major < _matrix.numColumns());
143 return Nonzero(_minor, _major, _matrix.get(_minor, _major));
149 assert(&_matrix == &other._matrix);
150 assert(_major == other._major);
151 return _minor != other._minor;
156 std::size_t _major, _minor;
179 other._data =
nullptr;
181 other._numColumns = 0;
188 template <
typename V2>
194 for (std::size_t i = 0; i < size; ++i)
207 other._data =
nullptr;
209 other._numColumns = 0;
217 template <
typename V2>
224 for (std::size_t i = 0; i < size; ++i)
235 if (
_data !=
nullptr)
248 for (std::size_t i = 0; i < size; ++i)
285 template <
typename V2>
301 std::size_t count = 0;
302 for (std::size_t i = begin; i < end; ++i)
316 std::size_t begin = column;
318 std::size_t count = 0;
319 for (std::size_t i = begin; i < end; i +=
_numColumns)
384 std::vector<std::pair<Index, Index>>
range;
426 range = std::move(other.range);
427 entries = std::move(other.entries);
458 range.resize(numMinor);
459 for (
auto& r :
range)
464 for (
Index j = transposedData.
range[i].first; j < transposedData.
range[i].second; ++j)
481 for (
Index transposedMajor = 0; transposedMajor <
Index(transposedData.
range.size());
484 for (
Index j = transposedData.
range[transposedMajor].first;
485 j < transposedData.
range[transposedMajor].second; ++j)
487 auto transposedEntry = transposedData.
entries[j];
488 entries[
range[transposedEntry.first].first] = std::make_pair(transposedMajor,
489 transposedEntry.second);
490 ++
range[transposedEntry.first].first;
511 throw std::runtime_error(
512 "Inconsistent SparseMatrix::Data: range.first contains index out of range.");
514 throw std::runtime_error(
515 "Inconsistent SparseMatrix::Data: range.second contains index out of range.");
517 throw std::runtime_error(
518 "Inconsistent SparseMatrix::Data: range.first > range.beyond.");
522 if (
entries[i].first >= numMinor)
523 throw std::runtime_error(
"Inconsistent SparseMatrix::Data: minor entry exceeds bound.");
525 throw std::runtime_error(
"Inconsistent SparseMatrix::Data: zero entry found.");
533 std::stringstream ss;
534 ss <<
"Inconsistent SparseMatrix::Data: minor entries of major " << i
535 <<
" contain duplicate indices " << (j-1) <<
"->" <<
entries[j-1].first <<
" and "
536 << j <<
"->" <<
entries[j].first <<
".";
537 throw std::runtime_error(ss.str());
541 std::stringstream ss;
542 ss <<
"Inconsistent SparseMatrix::Data: minor entries of major " << i
543 <<
" are not sorted for indices " << (j-1) <<
"->" <<
entries[j-1].first <<
" and "
544 << j <<
"->" <<
entries[j].first <<
".";
545 throw std::runtime_error(ss.str());
575 std::size_t lower =
range[major].first;
576 std::size_t upper =
range[major].second;
578 while (lower < upper)
580 mid = (lower + upper) / 2;
581 if (
entries[mid].first < minor)
583 else if (
entries[mid].first > minor)
593 for (std::size_t i =
range[major].first; i <
range[major].second; ++i)
600 return std::numeric_limits<std::size_t>::max();
612 for (std::size_t i = 0; i <
entries.size(); ++i)
614 auto compare = [] (
const std::pair<Index, Value>& a,
615 const std::pair<Index, Value>& b)
617 return a.first < b.first;
636 : _data(Row ? matrix._rowData : matrix._columnData), _major(major),
637 _index(_data.range[major].first)
643 : _data(Row ? matrix._rowData : matrix._columnData), _major(major),
644 _index(_data.range[major].second)
654 : _data(other._data), _major(other._major), _index(other._index)
679 assert(_index <= _data.
range[_major].second);
688 assert(&_data == &other._data);
689 return _major != other._major || _index != other._index;
719 : _rowData(std::move(other._rowData)), _columnData(std::move(other._columnData)), _zero(0)
730 _rowData = std::move(other._rowData);
731 _columnData = std::move(other._columnData);
755 Index* beyond,
Index* entryMinors,
Value* entryValues,
bool mayContainZeros =
true,
756 bool isSorted =
false)
759 set(majorRow, numMajor, numMinor, numEntries, first, beyond, entryMinors, entryValues,
760 mayContainZeros, isSorted);
776 set(majorRow, data, numMinor, majorIsSorted);
791 set(majorRow, data, numMinor);
806 set(rowData, columnData);
821 set(std::move(rowData), std::move(columnData));
844 const Index* beyond,
const Index* entryMinors,
const Value* entryValues,
845 bool mayContainZeros =
true,
bool isSorted =
false)
850 _rowData.
range.resize(numMajor);
851 for (
auto& range : _rowData.
range)
854 for (
Index i = 0; i < numMajor; ++i)
856 _rowData.
range[i].first = current;
858 if (beyond !=
nullptr)
860 else if (i + 1 < numMajor)
864 for (
Index j = first[i]; j < b; ++j)
866 if (entryValues[j] != 0)
869 _rowData.
range[i].second = current;
873 _rowData.
entries.resize(current);
875 for (
Index i = 0; i < numMajor; ++i)
878 if (beyond !=
nullptr)
880 else if (i + 1 < numMajor)
884 for (
Index j = first[i]; j < b; ++j)
886 if (entryValues[j] != 0)
888 _rowData.
entries[current] = std::make_pair(entryMinors[j], entryValues[j]);
897 _rowData.
range.resize(numMajor);
898 if (beyond !=
nullptr)
900 for (
Index i = 0; i < numMajor; ++i)
901 _rowData.
range[i] = std::make_pair(first[i], beyond[i]);
905 for (
Index i = 0; i + 1 < numMajor; ++i)
906 _rowData.
range[i] = std::make_pair(first[i], first[i+1]);
907 _rowData.
range.back() = std::make_pair(first[numMajor - 1],
Index(numEntries));
909 _rowData.
entries.resize(numEntries);
910 for (
Index i = 0; i < numEntries; ++i)
911 _rowData.
entries[i] = std::make_pair(entryMinors[i], entryValues[i]);
920 _rowData.
swap(_columnData);
948 _rowData.
swap(_columnData);
967 _rowData = std::move(data);
970 _rowData.
swap(_columnData);
1014 _rowData = std::move(rowData);
1015 _columnData = std::move(columnData);
1016 #if !defined(NDEBUG)
1033 return _rowData.
range.size();
1042 return _columnData.
range.size();
1077 std::size_t columnIndex = _rowData.
find(row, column);
1078 if (columnIndex < std::numeric_limits<std::size_t>::max())
1079 return _rowData.
entries[columnIndex].second;
1083 std::size_t rowIndex = _columnData.
find(column, row);
1084 if (rowIndex < std::numeric_limits<std::size_t>::max())
1085 return _columnData.
entries[rowIndex].second;
1097 return _rowData.
entries.size();
1106 return _rowData.
range[row].second - _rowData.
range[row].first;
1115 return _columnData.
range[column].second - _columnData.
range[column].first;
1169 auto compare = [](
const NZ& a,
const NZ& b)
1172 return a.row < b.row;
1173 if (a.column != b.column)
1174 return a.column < b.column;
1175 return a.value < b.value;
1179 std::vector<NZ> rowNonzeros;
1182 for (
Index j = _rowData.
range[i].first; j < _rowData.
range[i].second; ++j)
1184 NZ nz = { i, _rowData.
entries[j].first, _rowData.
entries[j].second };
1185 rowNonzeros.push_back(nz);
1188 std::sort(rowNonzeros.begin(), rowNonzeros.end(), compare);
1191 std::vector<NZ> columnNonzeros;
1194 for (
Index j = _columnData.
range[i].first; j < _columnData.
range[i].second; ++j)
1196 NZ nz = { _columnData.
entries[j].first, i, _columnData.
entries[j].second };
1197 columnNonzeros.push_back(nz);
1200 std::sort(columnNonzeros.begin(), columnNonzeros.end(), compare);
1202 for (std::size_t i = 0; i < rowNonzeros.size(); ++i)
1204 if (rowNonzeros[i].row != columnNonzeros[i].row
1205 || rowNonzeros[i].column != columnNonzeros[i].column
1206 || rowNonzeros[i].value != columnNonzeros[i].value)
1208 throw std::runtime_error(
"Inconsistent Matrix: row and column data differ.");
1221 _rowData.
swap(_columnData);
1271 template <
typename M>
1284 : _matrix(matrix._matrix), _iterator(typename M::template
NonzeroIterator<!Row>(matrix._matrix, major))
1290 : _matrix(matrix._matrix), _iterator(typename M::template
NonzeroIterator<!Row>(matrix._matrix, major, 0))
1303 std::swap(nz.row, nz.column);
1309 assert(&_matrix == &other._matrix);
1310 return _iterator != other._iterator;
1365 return _matrix.hasSortedColumns();
1374 return _matrix.hasSortedRows();
1389 return _matrix.get(column, row);
1407 return _matrix.countColumnNonzeros(row);
1416 return _matrix.countRowNonzeros(column);
1456 template <
typename M>
1506 return _rows.size();
1516 return _columns.size();
1524 const std::vector<std::size_t>&
rows()
const
1541 std::vector<std::size_t> _rows;
1544 std::vector<std::size_t> _columns;
1547 template <
typename M>
1560 : _matrix(matrix), _indices(indices)
1570 : _matrix(other._matrix), _indices(other._indices)
1623 return _matrix.get(_indices.
rows()[row], _indices.
columns()[column]);
1632 for (
auto row : _indices.
rows())
1634 if (row >= _matrix.numRows())
1635 throw std::runtime_error(
"Inconsistent Submatrix: row index too large.");
1637 for (
auto column : _indices.
columns())
1639 if (column >= _matrix.numColumns())
1640 throw std::runtime_error(
"Inconsistent Submatrix: column index too large.");
1642 _matrix.ensureConsistency();
1651 template <
typename Matrix>
1653 size_t& row,
size_t& column)
1655 bool result =
false;
1656 int current_value = 0;
1657 for (
size_t r = row_first; r != row_beyond; ++r)
1659 for (
size_t c = column_first; c != column_beyond; ++c)
1661 int value = matrix(r, c);
1665 value = value >= 0 ? value : -value;
1667 if (!result || value < current_value)
1672 current_value = value;
1679 template <
typename Matrix>
1682 for (
size_t c = column_first; c != column_beyond; ++c)
1683 if (matrix(row, c) != 0)
1688 template <
typename Matrix>
1695 template <
typename Matrix1,
typename Matrix2>
1696 bool equals(
const Matrix1& first,
const Matrix2& second)
1698 if (first.size1() != second.size1())
1700 if (first.size2() != second.size2())
1702 for (
size_t r = 0; r < first.size1(); ++r)
1704 for (
size_t c = 0; c < first.size2(); ++c)
1706 if (first(r, c) != second(r, c))
1722 template <
typename MatrixType>
1725 for (
size_t index = 0; index < matrix.size2(); ++index)
1727 std::swap(matrix(index1, index), matrix(index2, index));
1739 template <
typename MatrixType>
1742 for (
size_t index = 0; index < matrix.size1(); ++index)
1744 std::swap(matrix(index, index1), matrix(index, index2));
Definition: matrix.hpp:88
NonzeroIterator(const DenseMatrix< V > &matrix, Index major, int dummy)
Definition: matrix.hpp:105
bool operator!=(const NonzeroIterator< Row > &other) const
Definition: matrix.hpp:147
NonzeroIterator(const DenseMatrix< V > &matrix, Index major)
Definition: matrix.hpp:90
NonzeroIterator< Row > & operator++()
Definition: matrix.hpp:116
Nonzero operator*() const
Definition: matrix.hpp:131
Dense matrix with entries of type V.
Definition: matrix.hpp:80
DenseMatrix(Index numRows, Index numColumns)
Constructs zero matrix of given size.
Definition: matrix.hpp:243
std::size_t countRowNonzeros(Index row) const
Returns the number of nonzeros in row.
Definition: matrix.hpp:297
DenseMatrix< V > & operator=(const DenseMatrix< V2 > &other)
Assignment operator.
Definition: matrix.hpp:218
DenseMatrix()
Default constructor for 0x0 matrix.
Definition: matrix.hpp:166
detail::Range< NonzeroIterator< false > > NonzeroColumnRange
Definition: matrix.hpp:160
Matrix< V >::Nonzero Nonzero
Definition: matrix.hpp:84
Index _numColumns
Number of rows.
Definition: matrix.hpp:359
DenseMatrix(const DenseMatrix< V2 > &other)
Copy constructor.
Definition: matrix.hpp:189
Index _numRows
Matrix entries with row-major ordering.
Definition: matrix.hpp:358
Index numColumns() const
Returns the number of columns.
Definition: matrix.hpp:265
Index numRows() const
Returns the number of rows.
Definition: matrix.hpp:256
detail::Range< NonzeroIterator< true > > NonzeroRowRange
Definition: matrix.hpp:159
void ensureConsistency() const
Checks for consistency, raising a std::runtime_error if inconsistent.
Definition: matrix.hpp:351
std::size_t countColumnNonzeros(Index column) const
Returns the number of nonzeros in column.
Definition: matrix.hpp:314
Matrix< V >::Value Value
Definition: matrix.hpp:82
Value * _data
Definition: matrix.hpp:357
~DenseMatrix()
Destructor.
Definition: matrix.hpp:233
NonzeroRowRange iterateRowNonzeros(Index row) const
Returns a range for iterating over the nonzeros of row.
Definition: matrix.hpp:331
DenseMatrix(DenseMatrix< V > &&other)
Move constructor that steals the data from other.
Definition: matrix.hpp:176
const Value & get(Index row, Index column) const
Returns entry at row, column.
Definition: matrix.hpp:274
Matrix< V >::Index Index
Definition: matrix.hpp:83
NonzeroColumnRange iterateColumnNonzeros(Index column) const
Returns a range for iterating over the nonzeros of column.
Definition: matrix.hpp:341
void set(Index row, Index column, const V2 &value)
Sets entry at row, column to copy of value.
Definition: matrix.hpp:286
DenseMatrix< V > & operator=(DenseMatrix< V > &&other)
Move assignment operator that steals the data from other.
Definition: matrix.hpp:202
Base class for matrices whose entries have type V.
Definition: matrix.hpp:55
V Value
Definition: matrix.hpp:57
std::size_t Index
Type of entries.
Definition: matrix.hpp:58
Sparse matrix with entries of type V.
Definition: matrix.hpp:368
SparseMatrix & operator=(SparseMatrix &&other)
Move assignment operator.
Definition: matrix.hpp:728
detail::Range< NonzeroIterator< true > > NonzeroRowRange
Definition: matrix.hpp:701
Matrix< V >::Index Index
Definition: matrix.hpp:371
std::size_t numRows() const
Returns the number of rows.
Definition: matrix.hpp:1031
std::size_t numColumns() const
Returns the number of columns.
Definition: matrix.hpp:1040
void ensureConsistency() const
Checks for consistency, raising a std::runtime_error if inconsistent.
Definition: matrix.hpp:1154
bool hasSortedRows() const
Indicates if the row data is sorted by column.
Definition: matrix.hpp:1049
void sortRows()
Sort row data (by column).
Definition: matrix.hpp:1229
~SparseMatrix()=default
Destructor.
SparseMatrix(Data &&rowData, Data &&columnData)
Constructs a matrix.
Definition: matrix.hpp:818
bool hasSortedColumns() const
Indicates if the column data is sorted by row.
Definition: matrix.hpp:1058
SparseMatrix(bool majorRow, Data &&data, Index numMinor)
Constructs a matrix.
Definition: matrix.hpp:788
std::size_t numNonzeros() const
Returns the number of nonzeros.
Definition: matrix.hpp:1095
void set(bool majorRow, Data &&data, Index numMinor)
Sets the contents of the matrix.
Definition: matrix.hpp:965
Matrix< V >::Value Value
Definition: matrix.hpp:370
NonzeroRowRange iterateRowNonzeros(Index row) const
Returns a range for iterating over the nonzeros of row.
Definition: matrix.hpp:1122
std::size_t countColumnNonzeros(Index column) const
Returns the number of nonzeros in column.
Definition: matrix.hpp:1113
const Value & get(Index row, Index column) const
Returns entry at row, column.
Definition: matrix.hpp:1070
void sort()
Sort row and column data (by column and row, respectively).
Definition: matrix.hpp:1247
void set(const Data &rowData, const Data &columnData)
Sets the contents of the matrix.
Definition: matrix.hpp:986
Matrix< V >::Nonzero Nonzero
Definition: matrix.hpp:372
SparseMatrix(SparseMatrix &&other)
Move constructor.
Definition: matrix.hpp:718
SparseMatrix transposed() const
Returns a copy of the matrix' transpose.
Definition: matrix.hpp:1142
detail::Range< NonzeroIterator< false > > NonzeroColumnRange
Definition: matrix.hpp:702
SparseMatrix(const Data &rowData, const Data &columnData)
Constructs a matrix.
Definition: matrix.hpp:803
NonzeroColumnRange iterateColumnNonzeros(Index column) const
Returns a range for iterating over the nonzeros of column.
Definition: matrix.hpp:1132
void set(bool majorRow, const Data &data, Index numMinor)
Sets the contents of the matrix.
Definition: matrix.hpp:937
SparseMatrix(bool majorRow, const Data &data, Index numMinor, bool majorIsSorted=false)
Constructs a matrix.
Definition: matrix.hpp:773
void set(Data &&rowData, Data &&columnData)
Sets the contents of the matrix.
Definition: matrix.hpp:1012
void set(bool majorRow, Index numMajor, Index numMinor, Index numEntries, const Index *first, const Index *beyond, const Index *entryMinors, const Value *entryValues, bool mayContainZeros=true, bool isSorted=false)
Sets the contents of the matrix.
Definition: matrix.hpp:843
void sortColumns()
Sort column data (by row).
Definition: matrix.hpp:1238
SparseMatrix()
Constructs a 0x0 matrix.
Definition: matrix.hpp:708
void transpose()
Transposes the matrix.
Definition: matrix.hpp:1219
std::size_t countRowNonzeros(Index row) const
Returns the number of nonzeros in row.
Definition: matrix.hpp:1104
SparseMatrix(bool majorRow, Index numMajor, Index numMinor, Index numEntries, Index *first, Index *beyond, Index *entryMinors, Value *entryValues, bool mayContainZeros=true, bool isSorted=false)
Constructs a matrix.
Definition: matrix.hpp:754
Indexes a submatrix.
Definition: matrix.hpp:1467
CMR_EXPORT SubmatrixIndices(std::size_t row, std::size_t column)
Constructor for a 1x1 submatrix.
const std::vector< std::size_t > & columns() const
Returns the vector of column indices.
Definition: matrix.hpp:1534
CMR_EXPORT SubmatrixIndices(const SubmatrixIndices &other)
Copy constructor.
Definition: matrix.cpp:7
const std::vector< std::size_t > & rows() const
Returns the vector of row indices.
Definition: matrix.hpp:1524
std::size_t numRows() const
Returns the number of row indices.
Definition: matrix.hpp:1504
std::size_t numColumns() const
Returns the number of column indices.
Definition: matrix.hpp:1514
Definition: matrix.hpp:1549
M::Value Value
Definition: matrix.hpp:1552
bool hasSortedRows() const
Indicates if the row data is sorted by column.
Definition: matrix.hpp:1597
M::Index Index
Definition: matrix.hpp:1551
Submatrix(Submatrix &&other)
Move constructor.
Definition: matrix.hpp:1569
bool hasSortedColumns() const
Indicates if the column data is sorted by row.
Definition: matrix.hpp:1606
M::Nonzero Nonzero
Definition: matrix.hpp:1553
std::size_t numRows() const
Returns the number of rows.
Definition: matrix.hpp:1579
std::size_t numColumns() const
Returns the number of columns.
Definition: matrix.hpp:1588
Submatrix(const M &matrix, const SubmatrixIndices &indices)
Constructs submatrix of matrix indexed by indices.
Definition: matrix.hpp:1559
void ensureConsistency() const
Checks for consistency, raising a std::runtime_error if inconsistent.
Definition: matrix.hpp:1630
const Value & get(Index row, Index column) const
Returns entry at row, column.
Definition: matrix.hpp:1618
Definition: matrix.hpp:1281
Nonzero operator*() const
Definition: matrix.hpp:1300
NonzeroIterator< Row > & operator++()
Definition: matrix.hpp:1295
bool operator!=(const NonzeroIterator< Row > &other) const
Definition: matrix.hpp:1307
NonzeroIterator(const TransposedMatrix< M > &matrix, Index major)
Definition: matrix.hpp:1283
NonzeroIterator(const TransposedMatrix< M > &matrix, Index major, int dummy)
Definition: matrix.hpp:1289
Matrix proxy for the transpose of a matrix.
Definition: matrix.hpp:1273
std::size_t numColumns() const
Returns the number of columns.
Definition: matrix.hpp:1354
bool hasSortedColumns() const
Indicates if the column data is sorted by row.
Definition: matrix.hpp:1372
M::Nonzero Nonzero
Definition: matrix.hpp:1277
std::size_t countRowNonzeros(Index row) const
Returns the number of nonzeros in row.
Definition: matrix.hpp:1405
bool hasSortedRows() const
Indicates if the row data is sorted by column.
Definition: matrix.hpp:1363
M::Value Value
Definition: matrix.hpp:1275
detail::Range< NonzeroIterator< false > > NonzeroColumnRange
Definition: matrix.hpp:1319
std::size_t countColumnNonzeros(Index column) const
Returns the number of nonzeros in column.
Definition: matrix.hpp:1414
void ensureConsistency() const
Checks for consistency, raising a std::runtime_error if inconsistent.
Definition: matrix.hpp:1443
M & _matrix
Definition: matrix.hpp:1449
TransposedMatrix(M &matrix)
Constructs from a matrix of type M.
Definition: matrix.hpp:1325
std::size_t numNonzeros() const
Returns the number of nonzeros.
Definition: matrix.hpp:1396
M::Index Index
Definition: matrix.hpp:1276
std::size_t numRows() const
Returns the number of rows.
Definition: matrix.hpp:1345
NonzeroRowRange iterateRowNonzeros(Index row) const
Returns a range for iterating over the nonzeros of row.
Definition: matrix.hpp:1423
const Value & get(Index row, Index column) const
Returns entry at row, column.
Definition: matrix.hpp:1384
NonzeroColumnRange iterateColumnNonzeros(Index column) const
Returns a range for iterating over the nonzeros of column.
Definition: matrix.hpp:1433
detail::Range< NonzeroIterator< true > > NonzeroRowRange
Definition: matrix.hpp:1318
TransposedMatrix(TransposedMatrix &&other)
Move constructor.
Definition: matrix.hpp:1335
Definition: matrix.hpp:18
Iterator begin()
Definition: matrix.hpp:32
Range(Iterator begin, Iterator end)
Definition: matrix.hpp:20
Range(const Range< Iterator > &other)
Definition: matrix.hpp:26
Iterator end()
Definition: matrix.hpp:37
#define CMR_UNUSED(x)
Definition: env.h:24
Definition: algorithm.hpp:14
void sort(permutation &permutation, size_t first, size_t beyond, Less &less)
Definition: permutations.hpp:583
bool equals(const Matrix1 &first, const Matrix2 &second)
Definition: matrix.hpp:1696
void matrix_permute1(MatrixType &matrix, size_t index1, size_t index2)
Definition: matrix.hpp:1723
bool find_smallest_nonzero_matrix_entry(const Matrix &matrix, size_t row_first, size_t row_beyond, size_t column_first, size_t column_beyond, size_t &row, size_t &column)
Definition: matrix.hpp:1652
TransposedMatrix< M > transposedMatrix(M &matrix)
Returns a TransposedMatrix for matrix.
Definition: matrix.hpp:1457
matrix_transposed< MatrixType > make_transposed_matrix(MatrixType &matrix)
Definition: matrix_transposed.hpp:148
bool matrix_column_zero(const Matrix &matrix, size_t column, size_t row_first, size_t row_beyond)
Definition: matrix.hpp:1689
bool matrix_row_zero(const Matrix &matrix, size_t row, size_t column_first, size_t column_beyond)
Definition: matrix.hpp:1680
void matrix_permute2(MatrixType &matrix, size_t index1, size_t index2)
Definition: matrix.hpp:1740
Row/column index type.
Definition: matrix.hpp:61
Index row
Definition: matrix.hpp:62
Index column
Definition: matrix.hpp:63
const Value & value
Definition: matrix.hpp:64
Nonzero(Index r, Index c, const Value &v)
Definition: matrix.hpp:66
Matrix data, row-wise or column-wise.
Definition: matrix.hpp:382
~Data()=default
Destructor.
std::vector< std::pair< Index, Value > > entries
Array that maps the nonzero indices to pairs of minor index and value.
Definition: matrix.hpp:386
void swap(Data &other)
Swaps data with other.
Definition: matrix.hpp:555
Data & operator=(const Data &other)
Assignment operator.
Definition: matrix.hpp:436
std::vector< std::pair< Index, Index > > range
Array that maps a major to its nonzero range specified by first and beyond entries.
Definition: matrix.hpp:384
std::size_t find(Index major, Index minor) const
Finds entry major,minor.
Definition: matrix.hpp:569
Data & operator=(Data &&other)
Move operator.
Definition: matrix.hpp:424
void sort()
Sort data by minor.
Definition: matrix.hpp:607
bool isSorted
Whether the data is sorted by minor.
Definition: matrix.hpp:388
Data(const Data &other)
Copy constructor.
Definition: matrix.hpp:414
Data()
Default constructor.
Definition: matrix.hpp:394
Data(Data &&other)
Move constructor.
Definition: matrix.hpp:404
void constructFromTransposed(const Data &transposedData, Index numMinor)
Computes the transpose version of data. numMinor is the new number of minor indices.
Definition: matrix.hpp:455
void ensureConsistency(Index numMinor=std::numeric_limits< Index >::max()) const
Checks for consistency, raising a std::runtime_error if inconsistent.
Definition: matrix.hpp:506
Iterator for row- or column-wise iteration over the entries.
Definition: matrix.hpp:633
const Nonzero operator*() const
Returns the current entry.
Definition: matrix.hpp:663
NonzeroIterator(const SparseMatrix< V > &matrix, Index major, int dummy)
Definition: matrix.hpp:642
bool operator!=(const NonzeroIterator< Row > &other) const
Compares two iterators for being not equal.
Definition: matrix.hpp:686
void operator++()
Advances to the next entry in the same major.
Definition: matrix.hpp:676
NonzeroIterator(const NonzeroIterator &other)
Copy constructor.
Definition: matrix.hpp:653
NonzeroIterator(const SparseMatrix< V > &matrix, Index major)
Definition: matrix.hpp:635