Skip to content

Commit f821d81

Browse files
Merge branch 'Sanitizers' of https://github.com/Algebraic-Programming/OneStopParallel into Sanitizers
2 parents f51ace7 + c14a890 commit f821d81

File tree

1 file changed

+14
-42
lines changed

1 file changed

+14
-42
lines changed

include/osp/graph_implementations/eigen_matrix_adapter/eigen_sparse_iterator.hpp

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ limitations under the License.
2020

2121
#ifdef EIGEN_FOUND
2222

23-
# include <Eigen/SparseCore>
24-
25-
# include "osp/concepts/graph_traits.hpp"
26-
2723
namespace osp {
2824

2925
template <typename Graph, typename EigenIdxType>
@@ -37,12 +33,10 @@ class EigenCSRRange {
3733

3834
class Iterator {
3935
Inner it_;
40-
EigenIdxType skip_;
41-
bool atEnd_;
4236

4337
void SkipDiagonal() {
44-
while (((!atEnd_) && (it_.row() == skip_)) & (it_.col() == skip_)) {
45-
++(*this);
38+
while (it_ && (it_.row() == it_.col())) {
39+
++it_;
4640
}
4741
}
4842

@@ -55,28 +49,19 @@ class EigenCSRRange {
5549

5650
Iterator() = default;
5751

58-
Iterator(const Iterator &other) : it_(other.it_), skip_(other.skip_), atEnd_(other.atEnd_) {}
52+
Iterator(const Iterator &other) : it_(other.it_) {}
5953

6054
Iterator &operator=(const Iterator &other) {
6155
it_ = other.it_;
62-
skip_ = other.skip_;
63-
atEnd_ = other.atEnd_;
6456
return *this;
6557
}
6658

67-
Iterator(const CSRMatrix &mat, EigenIdxType idx, bool end = false) : skip_(idx), atEnd_(end) {
68-
if (!end) {
69-
it_ = Inner(mat, idx);
70-
atEnd_ = !it_;
71-
SkipDiagonal();
72-
}
73-
}
59+
Iterator(const CSRMatrix &mat, EigenIdxType idx) : it_(mat, idx) { SkipDiagonal(); }
7460

7561
reference operator*() const { return static_cast<std::size_t>(it_.col()); }
7662

7763
Iterator &operator++() {
7864
++it_;
79-
atEnd_ = !it_;
8065
SkipDiagonal();
8166
return *this;
8267
}
@@ -87,16 +72,15 @@ class EigenCSRRange {
8772
return temp;
8873
}
8974

90-
bool operator==(const Iterator &) const { return atEnd_; }
91-
92-
bool operator!=(const Iterator &) const { return !atEnd_; }
75+
bool operator==(const Iterator &other) const {return it_ == other.it_;}
76+
bool operator!=(const Iterator &other) const { return it_ != other.it_;}
9377
};
9478

9579
EigenCSRRange(const Graph &graph, EigenIdxType idx) : graph_(graph), index_(idx) {}
9680

9781
Iterator begin() const { return Iterator(*graph_.GetCSR(), index_); }
9882

99-
Iterator end() const { return Iterator(*graph_.GetCSR(), index_, true); }
83+
Iterator end() const { return Iterator(); }
10084
};
10185

10286
template <typename Graph, typename EigenIdxType>
@@ -110,12 +94,10 @@ class EigenCSCRange {
11094

11195
class Iterator {
11296
Inner it_;
113-
EigenIdxType skip_;
114-
bool atEnd_;
11597

11698
void SkipDiagonal() {
117-
while ((!atEnd_) & (it_.row() == skip_) & (it_.col() == skip_)) {
118-
++(*this);
99+
while (it_ && (it_.row() == it_.col())) {
100+
++it_;
119101
}
120102
}
121103

@@ -128,28 +110,19 @@ class EigenCSCRange {
128110

129111
Iterator() = default;
130112

131-
Iterator(const Iterator &other) : it_(other.it_), skip_(other.skip_), atEnd_(other.atEnd_) {}
113+
Iterator(const Iterator &other) : it_(other.it_) {}
132114

133115
Iterator &operator=(const Iterator &other) {
134116
it_ = other.it_;
135-
skip_ = other.skip_;
136-
atEnd_ = other.atEnd_;
137117
return *this;
138118
}
139119

140-
Iterator(const CSCMatrix &mat, EigenIdxType idx, bool end = false) : skip_(idx), atEnd_(end) {
141-
if (!end) {
142-
it_ = Inner(mat, idx);
143-
atEnd_ = !it_;
144-
SkipDiagonal();
145-
}
146-
}
120+
Iterator(const CSCMatrix &mat, EigenIdxType idx) : it_(mat, idx) { SkipDiagonal(); }
147121

148122
reference operator*() const { return static_cast<std::size_t>(it_.row()); }
149123

150124
Iterator &operator++() {
151125
++it_;
152-
atEnd_ = !it_;
153126
SkipDiagonal();
154127
return *this;
155128
}
@@ -160,16 +133,15 @@ class EigenCSCRange {
160133
return temp;
161134
}
162135

163-
bool operator==(const Iterator &) const { return atEnd_; }
164-
165-
bool operator!=(const Iterator &) const { return !atEnd_; }
136+
bool operator==(const Iterator &other) const {return it_ == other.it_;}
137+
bool operator!=(const Iterator &other) const { return it_ != other.it_;}
166138
};
167139

168140
EigenCSCRange(const Graph &graph, EigenIdxType idx) : graph_(graph), index_(idx) {}
169141

170142
Iterator begin() const { return Iterator(*graph_.GetCSC(), index_); }
171143

172-
Iterator end() const { return Iterator(*graph_.GetCSC(), index_, true); }
144+
Iterator end() const { return Iterator(); }
173145
};
174146

175147
} // namespace osp

0 commit comments

Comments
 (0)