Browse code

Rename headers from .hpp to .h

const-ae authored on 19/03/2020 15:07:52
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,82 @@
1
+#ifndef ColumnView_h
2
+#define ColumnView_h
3
+
4
+#include <Rcpp.h>
5
+#include "SparseMatrixView.h"
6
+#include "VectorSubsetView.h"
7
+
8
+
9
+class ColumnView {
10
+  const dgCMatrixView* matrix;
11
+
12
+public:
13
+  class col_container {
14
+  public:
15
+    VectorSubsetView<REALSXP> values;
16
+    VectorSubsetView<INTSXP> row_indices;
17
+    const R_len_t number_of_zeros;
18
+
19
+    col_container(VectorSubsetView<REALSXP> values_, VectorSubsetView<INTSXP> row_indices_, R_len_t number_of_zeros_):
20
+      values(values_), row_indices(row_indices_), number_of_zeros(number_of_zeros_) {}
21
+  };
22
+
23
+
24
+  class iterator {
25
+    ColumnView* cv;
26
+    int index;
27
+  public:
28
+    using iterator_category= std::input_iterator_tag;
29
+    using value_type = col_container;
30
+    using reference = col_container&;
31
+    using pointer = col_container*;
32
+    using difference_type = void;
33
+
34
+    iterator(ColumnView* cv_): cv(cv_), index(0) {
35
+      if(cv != nullptr && cv->matrix->ncol == 0){
36
+        cv = nullptr;
37
+      }
38
+    }
39
+
40
+    col_container operator*() const {
41
+      int start_pos = cv->matrix->col_ptrs[index];
42
+      int end_pos = cv->matrix->col_ptrs[index + 1];
43
+      int number_of_zeros = cv->matrix->nrow - (end_pos - start_pos);
44
+      VectorSubsetView<REALSXP> values(cv->matrix->values, start_pos, end_pos);
45
+      VectorSubsetView<INTSXP> row_indices(cv->matrix->row_indices, start_pos, end_pos);
46
+
47
+      return col_container(values, row_indices, number_of_zeros);
48
+    }
49
+
50
+    iterator& operator++(){ // preincrement
51
+      ++index;
52
+      if(index == cv->matrix->ncol)
53
+        cv=nullptr;
54
+      return *this;
55
+    }
56
+
57
+    friend bool operator==(iterator const& lhs,iterator const& rhs){
58
+      return lhs.cv == rhs.cv;
59
+    }
60
+    friend bool operator!=(iterator const& lhs,iterator const& rhs){
61
+      return !(lhs==rhs);
62
+    }
63
+
64
+  };
65
+
66
+  ColumnView(dgCMatrixView* matrix_): matrix(matrix_) {}
67
+  iterator begin() { return iterator(this); }
68
+  iterator end() { return iterator(nullptr); }
69
+
70
+};
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+#endif /* ColumnView_h */