20 template<
class K>
class DynamicMatrix;
21 template <
class Entry,
class Index>
class NumaBCRSMatrix;
22 template <
class Index>
class NumaCRSPatternCreator;
24 namespace MatrixOpsDetail
26 template <
class Target>
29 template <
class Entry,
class Allocator>
30 class Submatrix<
Dune::BCRSMatrix<Entry,Allocator>>
33 template <
class Source,
class RowIndices,
class ColIndices>
34 static Dune::BCRSMatrix<Entry,Allocator> apply(Source
const& A,
35 RowIndices
const& ri, ColIndices
const& ci)
37 using Target = Dune::BCRSMatrix<Entry,Allocator>;
38 using Index =
typename Source::size_type;
42 std::vector<std::tuple<Index,Index>> a;
43 std::vector<Entry> av;
44 for (Index r=0; r<ri.size(); ++r)
47 for (Index c=0; c<ci.size(); ++c)
49 auto coli = row.find(ci[c]);
50 if (coli != row.end())
52 a.push_back(std::make_tuple(r,c));
59 Target S(ri.size(),ci.size(),a.size(),Target::row_wise);
60 using CreateIter =
typename Target::CreateIterator;
62 for(CreateIter row=S.createbegin(); row!=S.createend(); ++row)
63 for ( ; ai!=end(a) && std::get<0>(*ai)==row.index(); ++ai)
64 row.insert(std::get<1>(*ai));
68 for (
auto r=S.begin(); r!=S.end(); ++r)
69 for (
auto c=r->begin(); c!=r->end(); ++c, ++avi)
77 template <
class Entry,
class Index>
78 class Submatrix<NumaBCRSMatrix<Entry,Index>>
81 template <
class Source,
class RowIndices,
class ColIndices>
82 static NumaBCRSMatrix<Entry,Index> apply(Source
const& A,
83 RowIndices
const& ri, ColIndices
const& ci)
85 NumaCRSPatternCreator<Index> creator(ri.size(), ci.size());
90 for(Index r=0; r<ri.size(); ++r)
93 for (Index c=0; c<ci.size(); ++c)
94 if (
auto coli = row.find(ci[c]); coli != row.end())
95 creator.addElement(r,c);
98 NumaBCRSMatrix<Entry,Index> S(creator);
101 for (
auto r=S.begin(); r!=S.end(); ++r)
102 for (
auto c=r->begin(); c!=r->end(); ++c)
103 *c = A[ri[r.index()]][ci[c.index()]];
109 template <
class Entry>
110 class Submatrix<DynamicMatrix<Entry>>
113 template <
class RowIdx,
class ColIdx>
114 static DynamicMatrix<Entry> apply(DynamicMatrix<Entry>
const& A,
115 RowIdx
const& rows, ColIdx
const& cols)
117 assert(*std::min_element(begin(rows),end(rows))>=0);
118 assert(*std::min_element(begin(cols),end(cols))>=0);
119 assert(*std::max_element(begin(rows),end(rows))<A.N());
120 assert(*std::max_element(begin(cols),end(cols))<A.M());
122 DynamicMatrix<Entry> S(size(rows),size(cols));
123 auto ci = begin(cols);
124 for (
int j=0; ci!=end(cols); ++j, ++ci)
126 auto ri = begin(rows);
127 for (
int i=0; ri!=end(rows); ++i, ++ri)
128 S[i][j] = A[*ri][*ci];
133 template <
class Source,
class RowIndices,
class ColIndices>
134 static DynamicMatrix<Entry> apply(Source
const& A,
135 RowIndices
const& ri, ColIndices
const& ci)
137 DynamicMatrix<Entry> S(ri.size(),ci.size());
138 for (
int r=0; r<ri.size(); ++r)
142 for (
int c=0; c<ci.size(); ++c)
143 if (
auto coli = row.find(ci[c]); coli != row.end())
172 template <
class Target,
class Source,
class RowIndices,
class ColIndices>
173 Target
submatrix(Source
const& A, RowIndices
const& ri, ColIndices
const& ci)
175 return MatrixOpsDetail::Submatrix<Target>::apply(A,ri,ci);
Target submatrix(Source const &A, RowIndices const &ri, ColIndices const &ci)
extracts a sparse or dense submatrix of