diff --git a/libsolutil/LinearExpression.cpp b/libsolutil/LinearExpression.cpp index e947b807b..8d47043ff 100644 --- a/libsolutil/LinearExpression.cpp +++ b/libsolutil/LinearExpression.cpp @@ -40,6 +40,14 @@ SparseMatrix::SparseMatrixIterator SparseMatrix::IteratorCombiner::end() return SparseMatrixIterator(nullptr, m_isRow); } +SparseMatrix::SparseMatrix(SparseMatrix const& _other) +{ + ensureSize(_other.rows(), _other.columns()); + for (size_t row = 0; row < _other.rows(); row++) + for (auto&& entry: const_cast(_other).iterateRow(row)) + prependInRow(nullptr, row, entry.col, entry.value); +} + SparseMatrix::IteratorCombiner SparseMatrix::iterateColumn(size_t _column) { return IteratorCombiner{ diff --git a/libsolutil/LinearExpression.h b/libsolutil/LinearExpression.h index cdf8f599a..6ddd265c7 100644 --- a/libsolutil/LinearExpression.h +++ b/libsolutil/LinearExpression.h @@ -239,6 +239,12 @@ public: SparseMatrixIterator end(); }; + SparseMatrix() = default; + SparseMatrix(SparseMatrix const&); + SparseMatrix(SparseMatrix&&) = default; + SparseMatrix& operator=(SparseMatrix const& _other) { *this = SparseMatrix(_other); return *this; } + SparseMatrix& operator=(SparseMatrix&&) = default; + size_t rows() const { return m_row_start.size(); } size_t columns() const { return m_col_start.size(); }