Skip to content
Snippets Groups Projects
Commit 370d0b0d authored by Uli Sack's avatar Uli Sack Committed by usack
Browse files

* added method mmv

* added default constructor and made changes in order for it to work properly, i.e.
    * made the summands pointers instead of references
    * allocate memory for summans internally if defult constructor is used
    * add destructor and delete summands if internally stored
* added const getter methods
* added methods N() and M()

[[Imported from SVN: r5482]]
parent f956fd27
No related branches found
No related tags found
No related merge requests found
...@@ -16,46 +16,97 @@ class SumOperator ...@@ -16,46 +16,97 @@ class SumOperator
//! export the summand type //! export the summand type
typedef LowRankMatrix LowRankMatrixType; typedef LowRankMatrix LowRankMatrixType;
//! default constructor - allocates memory for summand operators internally
SumOperator():
summands_allocated_internally_(true)
{
sparse_matrix_ = new SparseMatrixType;
lowrank_matrix_ = new LowRankMatrixType;
}
//! construct from summands //! construct from summands
SumOperator(SparseMatrixType& A, LowRankMatrixType& M): SumOperator(SparseMatrixType& A, LowRankMatrixType& M):
sparse_matrix_(A), sparse_matrix_(&A),
lowrank_matrix_(M) lowrank_matrix_(&M),
summands_allocated_internally_(false)
{} {}
~SumOperator()
{
if (summands_allocated_internally_)
{
delete sparse_matrix_;
delete lowrank_matrix_;
}
}
//! b += (A+M)x //! b += (A+M)x
template <class LVectorType, class RVectorType> template <class LVectorType, class RVectorType>
void umv(const LVectorType& x, RVectorType& b) const void umv(const LVectorType& x, RVectorType& b) const
{ {
sparse_matrix_.umv(x,b); sparse_matrix_->umv(x,b);
lowrank_matrix_.umv(x,b); lowrank_matrix_->umv(x,b);
}
//! b -= (A+M)x
template <class LVectorType, class RVectorType>
void mmv(const LVectorType& x, RVectorType& b) const
{
sparse_matrix_->mmv(x,b);
lowrank_matrix_->mmv(x,b);
} }
//! b = (A+M)x //! b = (A+M)x
template <class LVectorType, class RVectorType> template <class LVectorType, class RVectorType>
void mv(const LVectorType& x, RVectorType& b) void mv(const LVectorType& x, RVectorType& b)
{ {
sparse_matrix_.mv(x,b); sparse_matrix_->mv(x,b);
lowrank_matrix_.umv(x,b); lowrank_matrix_->umv(x,b);
}
//! return the number of rows
const size_t N() const
{
sparse_matrix_->N();
}
//! return the number of columns
const size_t M() const
{
sparse_matrix_->M();
}
//! return one summand
const SparseMatrixType& sparseMatrix() const
{
return *sparse_matrix_;
} }
//! return one summand //! return one summand
SparseMatrixType& getSparseMatrix() SparseMatrixType& sparseMatrix()
{
return *sparse_matrix_;
}
//! return "the other" summand
const LowRankMatrixType& lowRankMatrix() const
{ {
return sparse_matrix_; return *lowrank_matrix_;
} }
//! return "the other" summand //! return "the other" summand
LowRankMatrixType& getLowRankMatrix() LowRankMatrixType& lowRankMatrix()
{ {
return lowrank_matrix_; return *lowrank_matrix_;
} }
private: private:
//! one summand //! one summand
SparseMatrixType& sparse_matrix_; SparseMatrixType* sparse_matrix_;
//! the other summand //! the other summand
LowRankMatrixType& lowrank_matrix_; LowRankMatrixType* lowrank_matrix_;
//! are the summands supplied or stored internally
const bool summands_allocated_internally_;
}; };
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment