From df50762498355d1abf609b30404629f0a3c33baf Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 22 Aug 2022 15:51:40 +0200 Subject: [PATCH] Implement copy. --- libsolutil/LinearExpression.cpp | 8 ++++++++ libsolutil/LinearExpression.h | 6 ++++++ 2 files changed, 14 insertions(+) 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(); }