Skip to content
Snippets Groups Projects
Commit 21df14f2 authored by Tobias Leibner's avatar Tobias Leibner
Browse files

[la.container.matrix-view] add axpy variant

parent 5911fb8c
No related branches found
No related tags found
No related merge requests found
......@@ -374,6 +374,27 @@ public:
add_to_entry(ii, jj, xx.get_entry(ii, jj) * alpha);
}
template <class OtherTraits>
inline void axpy(const ScalarType& alpha, const MatrixInterface<OtherTraits, ScalarType>& xx)
{
const auto& patt = get_pattern();
#ifndef NDEBUG
const auto& other_patt = xx.pattern();
if (xx.rows() != rows() || xx.cols() != cols())
DUNE_THROW(Common::Exceptions::shapes_do_not_match, "Shapes do not match!");
for (size_t ii = 0; ii < rows(); ++ii)
for (auto&& jj : other_patt.inner(ii)) {
// The EigenRowMajorSparseMatrix automatically adds one entry to an empty row
if (!patt.contains(ii, jj)
&& !(patt.inner(ii).size() == 0 && other_patt.inner(ii).size() == 1 && other_patt.inner(ii)[0] == 0))
DUNE_THROW(Dune::MathError, "Pattern of xx has to be a subset of this pattern!");
}
#endif
for (size_t ii = 0; ii < rows(); ++ii)
for (auto&& jj : patt.inner(ii))
add_to_entry(ii, jj, xx.get_entry(ii, jj) * alpha);
}
template <class XX, class YY>
inline void mv(const XX& xx, YY& yy) const
{
......
......@@ -207,6 +207,10 @@ struct MatrixViewTest_{{T_NAME}} : public ::testing::Test
// test axpy
view_upperleft.axpy(ScalarType(4), view_upperleft);
sparse_view_upperleft.axpy(ScalarType(4), sparse_view_upperleft);
sparse_view_lowerright.axpy(ScalarType(4), sparse_lowerright_saved);
EXPECT_DOUBLE_OR_COMPLEX_EQ(ScalarType(5)*sparse_lowerright_saved.get_entry(0, 0), sparse_view_lowerright.get_entry(0, 0));
EXPECT_DOUBLE_OR_COMPLEX_EQ(ScalarType(5)*sparse_lowerright_saved.get_entry(1, 0), sparse_view_lowerright.get_entry(1, 0));
sparse_view_lowerright.scal(ScalarType(1./5.));
VectorImp test_vec(2, ScalarType(1.));
vec_view.axpy(-1., test_vec);
EXPECT_DOUBLE_OR_COMPLEX_EQ(ScalarType(0), vec_view.get_entry(0));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment