23 template <
class Entry,
class Allocator>
class BCRSMatrix;
30 template<
class K>
class DynamicMatrix;
31 template <
class Entry,
class Index>
class NumaBCRSMatrix;
32 template <
class Index>
class NumaCRSPatternCreator;
34 namespace MatrixOpsDetail
36 template <
class Target>
39 template <
class Entry,
class Allocator>
43 template <
class Source,
class RowIndices,
class ColIndices>
45 RowIndices
const& ri, ColIndices
const& ci)
48 using Index =
typename Source::size_type;
52 std::vector<std::tuple<Index,Index>> a;
53 std::vector<Entry> av;
54 for (Index r=0; r<ri.size(); ++r)
57 for (Index c=0; c<ci.size(); ++c)
59 auto coli = row.find(ci[c]);
60 if (coli != row.end())
62 a.push_back(std::make_tuple(r,c));
69 Target S(ri.size(),ci.size(),a.size(),Target::row_wise);
70 using CreateIter =
typename Target::CreateIterator;
72 for(CreateIter row=S.createbegin(); row!=S.createend(); ++row)
73 for ( ; ai!=end(a) && std::get<0>(*ai)==row.index(); ++ai)
74 row.insert(std::get<1>(*ai));
78 for (
auto r=S.begin(); r!=S.end(); ++r)
79 for (
auto c=r->begin(); c!=r->end(); ++c, ++avi)
87 template <
class Entry,
class Index>
88 class Submatrix<NumaBCRSMatrix<Entry,Index>>
91 template <
class Source,
class RowIndices,
class ColIndices>
92 static NumaBCRSMatrix<Entry,Index> apply(Source
const& A,
93 RowIndices
const& ri, ColIndices
const& ci)
95 NumaCRSPatternCreator<Index> creator(ri.size(), ci.size());
100 for(Index r=0; r<ri.size(); ++r)
103 for (Index c=0; c<ci.size(); ++c)
104 if (
auto coli = row.find(ci[c]); coli != row.end())
105 creator.addElement(r,c);
108 NumaBCRSMatrix<Entry,Index> S(creator);
111 for (
auto r=S.begin(); r!=S.end(); ++r)
112 for (
auto c=r->begin(); c!=r->end(); ++c)
113 *c = A[ri[r.index()]][ci[c.index()]];
119 template <
class Entry>
120 class Submatrix<DynamicMatrix<Entry>>
123 template <
class RowIdx,
class ColIdx>
124 static DynamicMatrix<Entry> apply(DynamicMatrix<Entry>
const& A,
125 RowIdx
const& rows, ColIdx
const& cols)
127 assert(*std::min_element(begin(rows),end(rows))>=0);
128 assert(*std::min_element(begin(cols),end(cols))>=0);
129 assert(*std::max_element(begin(rows),end(rows))<A.N());
130 assert(*std::max_element(begin(cols),end(cols))<A.M());
132 DynamicMatrix<Entry> S(size(rows),size(cols));
133 auto ci = begin(cols);
134 for (
int j=0; ci!=end(cols); ++j, ++ci)
136 auto ri = begin(rows);
137 for (
int i=0; ri!=end(rows); ++i, ++ri)
138 S[i][j] = A[*ri][*ci];
143 template <
class Source,
class RowIndices,
class ColIndices>
144 static DynamicMatrix<Entry> apply(Source
const& A,
145 RowIndices
const& ri, ColIndices
const& ci)
147 DynamicMatrix<Entry> S(ri.size(),ci.size());
148 for (
int r=0; r<ri.size(); ++r)
152 for (
int c=0; c<ci.size(); ++c)
153 if (
auto coli = row.find(ci[c]); coli != row.end())
182 template <
class Target,
class Source,
class RowIndices,
class ColIndices>
183 Target
submatrix(Source
const& A, RowIndices
const& ri, ColIndices
const& ci)
185 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