... | ... |
@@ -7,6 +7,7 @@ |
7 | 7 |
|
8 | 8 |
#include <Rcpp.h> |
9 | 9 |
#include <vector> |
10 |
+#include <algorithm> |
|
10 | 11 |
|
11 | 12 |
// forward declarations |
12 | 13 |
class RowMatrix; |
... | ... |
@@ -15,7 +16,7 @@ class ColMatrix; |
15 | 16 |
class RowMatrix |
16 | 17 |
{ |
17 | 18 |
private: |
18 |
- |
|
19 |
+ |
|
19 | 20 |
std::vector<Vector> mRows; |
20 | 21 |
unsigned mNumRows, mNumCols; |
21 | 22 |
|
... | ... |
@@ -23,7 +24,7 @@ public: |
23 | 24 |
|
24 | 25 |
RowMatrix(unsigned nrow, unsigned ncol); |
25 | 26 |
explicit RowMatrix(const Rcpp::NumericMatrix &rmat); |
26 |
- |
|
27 |
+ |
|
27 | 28 |
template <class Parser> |
28 | 29 |
RowMatrix(Parser &p, unsigned nrow, unsigned ncol); |
29 | 30 |
|
... | ... |
@@ -67,6 +68,9 @@ public: |
67 | 68 |
template <class Parser> |
68 | 69 |
ColMatrix(Parser &p, unsigned nrow, unsigned ncol); |
69 | 70 |
|
71 |
+ template <class Parser> |
|
72 |
+ ColMatrix(Parser &p, unsigned nrow, std::vector<unsigned> whichCols); |
|
73 |
+ |
|
70 | 74 |
unsigned nRow() const {return mNumRows;} |
71 | 75 |
unsigned nCol() const {return mNumCols;} |
72 | 76 |
|
... | ... |
@@ -134,12 +138,34 @@ template <class Parser> |
134 | 138 |
RowMatrix::RowMatrix(Parser &p, unsigned nrow, std::vector<unsigned> whichCols) |
135 | 139 |
{ |
136 | 140 |
// TODO implement |
141 |
+ for (unsigned i = 0; i < mNumRows; i++) { |
|
142 |
+ mRows.push_back(Vector(whichCols.size())); |
|
143 |
+ } |
|
144 |
+ |
|
145 |
+ while (p.hasNext()) { |
|
146 |
+ MatrixElement e(p.getNext()); |
|
147 |
+ auto newColsIndex = std::find(whichCols.begin(), whichCols.end(), e.col); |
|
148 |
+ if (newColsIndex != whichCols.end()) { |
|
149 |
+ this->operator()(e.row, newColsIndex - whichCols.begin()) = e.value; |
|
150 |
+ } |
|
151 |
+ } |
|
137 | 152 |
} |
138 | 153 |
|
139 | 154 |
template <class Parser> |
140 |
-ColMatrix::ColMatrix(Parser &p, std::vector<unsigned> whichRows, unsigned ncol) |
|
155 |
+ColMatrix::ColMatrix(Parser &p, unsigned nrow, std::vector<unsigned> whichCols) |
|
141 | 156 |
{ |
142 | 157 |
// TODO implement |
158 |
+ for (unsigned j = 0; j < whichCols.size(); j++) { |
|
159 |
+ mCols.push_back(Vector(mNumRows)); |
|
160 |
+ } |
|
161 |
+ |
|
162 |
+ while(p.hasNext()) { |
|
163 |
+ MatrixElement e(p.getNext()); |
|
164 |
+ auto newColsIndex = std::find(whichCols.begin(), whichCols.end(), e.col); |
|
165 |
+ if (newColsIndex != whichCols.end()) { |
|
166 |
+ this->operator()(e.row, newColsIndex - whichCols.begin()) = e.value; |
|
167 |
+ } |
|
168 |
+ } |
|
143 | 169 |
} |
144 | 170 |
|
145 |
-#endif |
|
146 | 171 |
\ No newline at end of file |
172 |
+#endif |