Browse code

reset to old commit; added back safe changes

Tom Sherman authored on 24/05/2018 20:32:14
Showing17 changed files

... ...
@@ -2,7 +2,6 @@
2 2
 #include "AtomicDomain.h"
3 3
 #include "math/Random.h"
4 4
 
5
-#include <omp.h>
6 5
 #include <stdint.h>
7 6
 #include <utility>
8 7
 
... ...
@@ -16,8 +15,6 @@ Atom AtomicDomain::front() const
16 15
 Atom AtomicDomain::randomAtom() const
17 16
 {
18 17
     uint64_t ndx = gaps::random::uniform64(0, mAtoms.size() - 1);
19
-    //GAPS_ASSERT(mAtoms.size() >= 1);
20
-    //GAPS_ASSERT(ndx < mAtoms.size());
21 18
     return mAtoms[ndx];
22 19
 }
23 20
 
... ...
@@ -14,8 +14,10 @@ const Rcpp::NumericMatrix &FP, unsigned checkpointInterval,
14 14
 const std::string &cptFile, unsigned pumpThreshold, unsigned nPumpSamples,
15 15
 unsigned nCores)
16 16
 {
17
-    unsigned availableCores = omp_get_max_threads();
18
-    Rprintf("Running on %d out of %d available cores\n", nCores, availableCores);
17
+    #ifdef __GAPS_OPENMP__
18
+        unsigned availableCores = omp_get_max_threads();
19
+        Rprintf("Running on %d out of %d available cores\n", nCores, availableCores);
20
+    #endif
19 21
 
20 22
     // create internal state from parameters and run from there
21 23
     GapsRunner runner(D, S, nFactor, nEquil, nEquilCool, nSample,
... ...
@@ -61,7 +63,7 @@ std::string getBuildReport_cpp()
61 63
     std::string simd = "SIMD not enabled\n";
62 64
 #endif
63 65
 
64
-#if defined(_OPENMP)
66
+#ifdef __GAPS_OPENMP__
65 67
     std::string openmp = "Compiled with OpenMP\n";
66 68
 #else
67 69
     std::string openmp = "Compiler did not support OpenMP\n";
... ...
@@ -207,11 +207,6 @@ void GapsRunner::displayStatus(const std::string &type, unsigned nIterTotal)
207 207
 {
208 208
     if (mNumOutputs > 0 && (mCurrentIter + 1) % mNumOutputs == 0 && mPrintMessages)
209 209
     {
210
-        // print algo status
211
-        Rprintf("%s %d of %d, Atoms:%lu(%lu) Chi2 = %.2f\n", type.c_str(),
212
-            mCurrentIter + 1, nIterTotal, mASampler.nAtoms(),
213
-            mPSampler.nAtoms(), mASampler.chi2());
214
-
215 210
         // compute time
216 211
         bpt::time_duration diff = bpt_now() - mStartTime;
217 212
         double elapsed = diff.total_seconds();
... ...
@@ -221,6 +216,12 @@ void GapsRunner::displayStatus(const std::string &type, unsigned nIterTotal)
221 216
         printTime("Elapsed Time", elapsed);
222 217
         printTime("Estimated Total Time", estTotal);
223 218
         printTime("Estimated Remaining Time", estTotal - elapsed);
219
+
220
+        // print algo status
221
+        Rprintf("%s %d of %d, Atoms:%lu(%lu) Chi2 = %.2f\n\n", type.c_str(),
222
+            mCurrentIter + 1, nIterTotal, mASampler.nAtoms(),
223
+            mPSampler.nAtoms(), mASampler.chi2());
224
+
224 225
     }
225 226
 }
226 227
 
... ...
@@ -3,6 +3,7 @@
3 3
 
4 4
 #include "Archive.h"
5 5
 #include "data_structures/Matrix.h"
6
+#include "data_structures/Vector.h"
6 7
 #include "GibbsSampler.h"
7 8
 #include "GapsStatistics.h"
8 9
 
... ...
@@ -12,17 +12,16 @@ const PatternGibbsSampler &PSampler)
12 12
 {
13 13
     mStatUpdates++;
14 14
 
15
-    Vector normVec(mNumPatterns);
16 15
     for (unsigned j = 0; j < mNumPatterns; ++j)
17 16
     {
18
-        normVec[j] = gaps::algo::sum(PSampler.mMatrix.getRow(j));
19
-        normVec[j] = normVec[j] == 0 ? 1.f : normVec[j];
17
+        float norm = gaps::algo::sum(PSampler.mMatrix.getRow(j));
18
+        norm = norm == 0.f ? 1.f : norm;
20 19
 
21
-        Vector quot(PSampler.mMatrix.getRow(j) / normVec[j]);
20
+        Vector quot(PSampler.mMatrix.getRow(j) / norm);
22 21
         mPMeanMatrix.getRow(j) += quot;
23 22
         mPStdMatrix.getRow(j) += gaps::algo::elementSq(quot);
24 23
 
25
-        Vector prod(ASampler.mMatrix.getCol(j) * normVec[j]);
24
+        Vector prod(ASampler.mMatrix.getCol(j) * norm);
26 25
         mAMeanMatrix.getCol(j) += prod;
27 26
         mAStdMatrix.getCol(j) += gaps::algo::elementSq(prod); 
28 27
     }
... ...
@@ -11,7 +11,6 @@
11 11
 
12 12
 #include <Rcpp.h>
13 13
 #include <algorithm>
14
-#include <omp.h>
15 14
 
16 15
 // forward declarations needed for friend classes
17 16
 class AmplitudeGibbsSampler;
... ...
@@ -9,7 +9,9 @@ OBJECTS =   AtomicDomain.o \
9 9
             test-runner.o \
10 10
             math/Algorithms.o \
11 11
             data_structures/Matrix.o \
12
+            data_structures/Vector.o \
12 13
             math/Random.o \
14
+            file_parser/CsvParser.o \
13 15
             cpp_tests/testAlgorithms.o \
14 16
             cpp_tests/testAtomicDomain.o \
15 17
             cpp_tests/testGapsRunner.o \
... ...
@@ -48,27 +48,5 @@ TEST_CASE("Test Matrix.h")
48 48
         REQUIRE(cmS.nRow() == 1363);
49 49
         REQUIRE(cmS.nCol() == 9);
50 50
     }
51
-
52
-    SECTION("Matrix Update")
53
-    {
54
-        RowMatrix rm(10, 25);
55
-        ColMatrix cm(10, 25);
56
-
57
-        rm.update(MatrixChange('A', 3, 4, 3.0));
58
-        cm.update(MatrixChange('P', 1, 2, 13.0));
59
-
60
-        REQUIRE(rm(3,4) == 3.0);
61
-        REQUIRE(cm(1,2) == 13.0);
62
-        REQUIRE(rm.getRow(3)[4] == 3.0);
63
-        REQUIRE(cm.getCol(2)[1] == 13.0);
64
-
65
-        rm.update(MatrixChange('A', 3, 4, 3.0));
66
-        cm.update(MatrixChange('P', 1, 2, 5.0));
67
-        
68
-        REQUIRE(rm(3,4) == 6.0);
69
-        REQUIRE(cm(1,2) == 18.0);
70
-        REQUIRE(rm.getRow(3)[4] == 6.0);
71
-        REQUIRE(cm.getCol(2)[1] == 18.0);
72
-    }
73 51
 }
74 52
 
... ...
@@ -20,7 +20,7 @@ public:
20 20
     void insert(uint64_t n) {mSet[n] = mCurrentKey;}
21 21
 };
22 22
 
23
-// have sorted vector with at least some % of holes
23
+// TODO have sorted vector with at least some % of holes
24 24
 // even distribute entries along it
25 25
 // when shift happens, should be minimal
26 26
 
... ...
@@ -37,7 +37,7 @@ public:
37 37
     void insert(uint64_t p) {mVec.push_back(p);}
38 38
     void clear() {mVec.clear();}
39 39
 
40
-    // inclusive of a and b
40
+    // inclusive of a and b, TODO improve performance
41 41
     bool isEmptyInterval(uint64_t a, uint64_t b)
42 42
     {
43 43
         for (unsigned i = 0; i < mVec.size(); ++i)
... ...
@@ -1,26 +1,5 @@
1 1
 #include "Matrix.h"
2 2
 
3
-#include <stdexcept>
4
-
5
-static const float EPSILON = 1.e-10;
6
-
7
-/******************************** HELPER *******************************/
8
-
9
-static void updateHelper2(float& val, float delta)
10
-{
11
-    val = std::abs(val + delta) < EPSILON ? 0.0 : val + delta;
12
-}
13
-
14
-template<class GenericMatrix>
15
-static void updateHelper(GenericMatrix &mat, const MatrixChange &change)
16
-{
17
-    updateHelper2(mat(change.row1, change.col1), change.delta1);
18
-    if (change.nChanges > 1)
19
-    {
20
-        updateHelper2(mat(change.row2, change.col2), change.delta2);
21
-    }
22
-}
23
-
24 3
 template<class GenericMatrix>
25 4
 static Rcpp::NumericMatrix convertToRMatrix(const GenericMatrix &mat)
26 5
 {
... ...
@@ -35,118 +14,16 @@ static Rcpp::NumericMatrix convertToRMatrix(const GenericMatrix &mat)
35 14
     return rmat;
36 15
 }
37 16
 
38
-/******************************** VECTOR *******************************/
39
-
40
-void Vector::concat(const Vector& vec)
41
-{
42
-    mValues.insert(mValues.end(), vec.mValues.begin(), vec.mValues.end());
43
-}
44
-
45
-void Vector::operator+=(const Vector &vec)
46
-{
47
-    for (unsigned i = 0; i < size(); ++i)
48
-    {
49
-        mValues[i] += vec[i];
50
-    }
51
-}
52
-
53
-void Vector::operator=(const Vector &vec)
17
+template<class MatA, class MatB>
18
+static void copyMatrix(MatA &dest, const MatB &source)
54 19
 {
55
-    mValues = vec.mValues;
56
-}
57
-
58
-Vector Vector::operator+(Vector vec) const
59
-{
60
-    for (unsigned i = 0; i < size(); ++i)
20
+    for (unsigned i = 0; i < source.nRow(); ++i)
61 21
     {
62
-        vec[i] += mValues[i];
63
-    }
64
-    return vec;
65
-}
66
-
67
-Vector Vector::operator-(Vector vec) const
68
-{
69
-    for (unsigned i = 0; i < size(); ++i)
70
-    {
71
-        vec[i] -= mValues[i];
72
-    }
73
-    return vec;
74
-}
75
-
76
-Vector Vector::operator*(Vector vec) const
77
-{
78
-    for (unsigned i = 0; i < size(); ++i)
79
-    {
80
-        vec[i] *= mValues[i];
81
-    }
82
-    return vec;
83
-}
84
-
85
-Vector Vector::operator/(Vector vec) const
86
-{
87
-    for (unsigned i = 0; i < size(); ++i)
88
-    {
89
-        vec[i] /= mValues[i];
90
-    }
91
-    return vec;
92
-}
93
-
94
-Vector Vector::operator+(float val) const
95
-{
96
-    Vector vec(*this);
97
-    for (unsigned i = 0; i < size(); ++i)
98
-    {
99
-        vec[i] += val;
100
-    }
101
-    return vec;
102
-}
103
-
104
-Vector Vector::operator-(float val) const
105
-{
106
-    Vector vec(*this);
107
-    for (unsigned i = 0; i < size(); ++i)
108
-    {
109
-        vec[i] -= val;
110
-    }
111
-    return vec;
112
-}
113
-
114
-Vector Vector::operator*(float val) const
115
-{
116
-    Vector vec(*this);
117
-    for (unsigned i = 0; i < size(); ++i)
118
-    {
119
-        vec[i] *= val;
120
-    }
121
-    return vec;
122
-}
123
-
124
-Vector Vector::operator/(float val) const
125
-{
126
-    Vector vec(*this);
127
-    for (unsigned i = 0; i < size(); ++i)
128
-    {
129
-        vec[i] /= val;
130
-    }
131
-    return vec;
132
-}
133
-
134
-Archive& operator<<(Archive &ar, Vector &vec)
135
-{
136
-    for (unsigned i = 0; i < vec.size(); ++i)
137
-    {
138
-        ar << vec[i];
139
-    }
140
-    return ar;
141
-}
142
-
143
-Archive& operator>>(Archive &ar, Vector &vec)
144
-{
145
-    for (unsigned i = 0; i < vec.size(); ++i)
146
-    {
147
-        ar >> vec.mValues[i];
22
+        for (unsigned j = 0; j < source.nCol(); ++j)
23
+        {
24
+            dest(i,j) = source(i,j);
25
+        }
148 26
     }
149
-    return ar;
150 27
 }
151 28
     
152 29
 /****************************** ROW MATRIX *****************************/
... ...
@@ -173,36 +50,24 @@ RowMatrix::RowMatrix(const Rcpp::NumericMatrix &rmat)
173 50
     }
174 51
 }
175 52
 
176
-RowMatrix::RowMatrix(const RowMatrix &mat)
177
-: mNumRows(mat.nRow()), mNumCols(mat.nCol())
53
+RowMatrix::RowMatrix(const std::string &path)
178 54
 {
179
-    for (unsigned i = 0; i < mNumRows; ++i)
180
-    {
181
-        mRows.push_back(mat.getRow(i));
182
-    }
55
+
183 56
 }
184 57
 
185
-RowMatrix::RowMatrix(const ColMatrix &mat)
186
-: mNumRows(mat.nRow()), mNumCols(mat.nCol())
58
+void RowMatrix::operator=(const RowMatrix &mat)
187 59
 {
188
-    for (unsigned i = 0; i < mNumRows; ++i)
189
-    {
190
-        mRows.push_back(Vector(mNumCols));
191
-        for (unsigned j = 0; j < mNumCols; ++j)
192
-        {
193
-            this->operator()(i,j) = mat(i,j);
194
-        }
195
-    }
60
+    copyMatrix(*this, mat);
196 61
 }
197 62
 
198
-void RowMatrix::update(const MatrixChange &change)
63
+void RowMatrix::operator=(const ColMatrix &mat)
199 64
 {
200
-    updateHelper<RowMatrix>(*this, change);
65
+    copyMatrix(*this, mat);
201 66
 }
202 67
 
203 68
 Rcpp::NumericMatrix RowMatrix::rMatrix() const
204 69
 {
205
-    return convertToRMatrix<RowMatrix>(*this);
70
+    return convertToRMatrix(*this);
206 71
 }
207 72
 
208 73
 RowMatrix RowMatrix::operator/(float val) const
... ...
@@ -215,17 +80,6 @@ RowMatrix RowMatrix::operator/(float val) const
215 80
     return mat;
216 81
 }
217 82
 
218
-void RowMatrix::operator=(const ColMatrix &mat)
219
-{
220
-    for (unsigned i = 0; i < mNumRows; ++i)
221
-    {
222
-        for (unsigned j = 0; j < mNumCols; ++j)
223
-        {
224
-            this->operator()(i,j) = mat(i,j);
225
-        }
226
-    }
227
-}
228
-
229 83
 Archive& operator<<(Archive &ar, RowMatrix &mat)
230 84
 {
231 85
     for (unsigned i = 0; i < mat.nRow(); ++i)
... ...
@@ -268,18 +122,9 @@ ColMatrix::ColMatrix(const Rcpp::NumericMatrix &rmat)
268 122
     }
269 123
 }
270 124
 
271
-ColMatrix::ColMatrix(const ColMatrix &mat)
272
-: mNumRows(mat.nRow()), mNumCols(mat.nCol())
125
+ColMatrix::ColMatrix(const std::string &path)
273 126
 {
274
-    for (unsigned j = 0; j < mNumCols; ++j)
275
-    {
276
-        mCols.push_back(mat.getCol(j));
277
-    }
278
-}
279 127
 
280
-void ColMatrix::update(const MatrixChange &change)
281
-{
282
-    updateHelper<ColMatrix>(*this, change);
283 128
 }
284 129
 
285 130
 ColMatrix ColMatrix::operator/(float val) const
... ...
@@ -292,20 +137,19 @@ ColMatrix ColMatrix::operator/(float val) const
292 137
     return mat;
293 138
 }
294 139
 
140
+void ColMatrix::operator=(const ColMatrix &mat)
141
+{
142
+    copyMatrix(*this, mat);
143
+}
144
+
295 145
 void ColMatrix::operator=(const RowMatrix &mat)
296 146
 {
297
-    for (unsigned i = 0; i < mNumRows; ++i)
298
-    {
299
-        for (unsigned j = 0; j < mNumCols; ++j)
300
-        {
301
-            this->operator()(i,j) = mat(i,j);
302
-        }
303
-    }
147
+    copyMatrix(*this, mat);
304 148
 }
305 149
 
306 150
 Rcpp::NumericMatrix ColMatrix::rMatrix() const
307 151
 {
308
-    return convertToRMatrix<ColMatrix>(*this);
152
+    return convertToRMatrix(*this);
309 153
 }
310 154
 
311 155
 Archive& operator<<(Archive &ar, ColMatrix &mat)
... ...
@@ -2,9 +2,9 @@
2 2
 #define __COGAPS_MATRIX_H__
3 3
 
4 4
 #include "../Archive.h"
5
+#include "Vector.h"
5 6
 
6 7
 #include <Rcpp.h>
7
-#include <boost/align/aligned_allocator.hpp>
8 8
 #include <vector>
9 9
 
10 10
 struct MatrixChange
... ...
@@ -32,46 +32,6 @@ struct MatrixChange
32 32
     {}
33 33
 };
34 34
 
35
-namespace bal = boost::alignment;
36
-typedef std::vector<float, bal::aligned_allocator<float,32> > aligned_vector;
37
-
38
-class Vector
39
-{
40
-private:
41
-
42
-    aligned_vector mValues;
43
-
44
-public:
45
-
46
-    Vector(unsigned size) : mValues(aligned_vector(size, 0.f)) {}
47
-    Vector(unsigned size, float val) : mValues(aligned_vector(size, val)) {}
48
-    Vector(const aligned_vector &v) : mValues(v) {}
49
-    Vector(const Vector &vec) : mValues(vec.mValues) {}
50
-
51
-    const float* ptr() const {return &mValues[0];}
52
-    float* ptr() {return &mValues[0];}
53
-
54
-    float& operator[](unsigned i) {return mValues[i];}
55
-    float operator[](unsigned i) const {return mValues[i];}
56
-    unsigned size() const {return mValues.size();}
57
-
58
-    Rcpp::NumericVector rVec() const {return Rcpp::wrap(mValues);}
59
-    void concat(const Vector& vec);
60
-    void operator+=(const Vector &vec);
61
-    void operator=(const Vector &vec);
62
-
63
-    Vector operator+(Vector vec) const;
64
-    Vector operator-(Vector vec) const;
65
-    Vector operator*(Vector vec) const;
66
-    Vector operator/(Vector vec) const;
67
-    Vector operator+(float val) const;
68
-    Vector operator-(float val) const;
69
-    Vector operator*(float val) const;
70
-    Vector operator/(float val) const;
71
-
72
-    friend Archive& operator<<(Archive &ar, Vector &vec);
73
-    friend Archive& operator>>(Archive &ar, Vector &vec);
74
-};
75 35
 
76 36
 class ColMatrix;
77 37
 
... ...
@@ -82,14 +42,11 @@ private:
82 42
     std::vector<Vector> mRows;
83 43
     unsigned mNumRows, mNumCols;
84 44
 
85
-    RowMatrix() {}
86
-
87 45
 public:
88 46
 
89 47
     RowMatrix(unsigned nrow, unsigned ncol);
90 48
     RowMatrix(const Rcpp::NumericMatrix &rmat);
91
-    RowMatrix(const RowMatrix &mat);
92
-    RowMatrix(const ColMatrix &mat);
49
+    RowMatrix(const std::string &path);
93 50
 
94 51
     unsigned nRow() const {return mNumRows;}
95 52
     unsigned nCol() const {return mNumCols;}
... ...
@@ -105,9 +62,9 @@ public:
105 62
 
106 63
     RowMatrix operator/(float val) const;
107 64
 
65
+    void operator=(const RowMatrix &mat);
108 66
     void operator=(const ColMatrix &mat);
109 67
 
110
-    void update(const MatrixChange &change);
111 68
     Rcpp::NumericMatrix rMatrix() const;
112 69
 
113 70
     friend Archive& operator<<(Archive &ar, RowMatrix &mat);
... ...
@@ -121,14 +78,11 @@ private:
121 78
     std::vector<Vector> mCols;
122 79
     unsigned mNumRows, mNumCols;
123 80
 
124
-    ColMatrix() {}
125
-
126 81
 public:
127 82
 
128 83
     ColMatrix(unsigned nrow, unsigned ncol);
129 84
     ColMatrix(const Rcpp::NumericMatrix &rmat);
130
-    ColMatrix(const ColMatrix &mat);
131
-    ColMatrix(const RowMatrix &mat);
85
+    ColMatrix(const std::string &path);
132 86
 
133 87
     unsigned nRow() const {return mNumRows;}
134 88
     unsigned nCol() const {return mNumCols;}
... ...
@@ -144,9 +98,9 @@ public:
144 98
 
145 99
     ColMatrix operator/(float val) const;
146 100
 
101
+    void operator=(const ColMatrix &mat);
147 102
     void operator=(const RowMatrix &mat);
148 103
 
149
-    void update(const MatrixChange &change);
150 104
     Rcpp::NumericMatrix rMatrix() const;
151 105
 
152 106
     friend Archive& operator<<(Archive &ar, ColMatrix &mat);
153 107
new file mode 100644
... ...
@@ -0,0 +1,52 @@
1
+#include "Vector.h"
2
+
3
+void Vector::concat(const Vector& vec)
4
+{
5
+    mValues.insert(mValues.end(), vec.mValues.begin(), vec.mValues.end());
6
+}
7
+
8
+void Vector::operator+=(const Vector &vec)
9
+{
10
+    for (unsigned i = 0; i < size(); ++i)
11
+    {
12
+        mValues[i] += vec[i];
13
+    }
14
+}
15
+
16
+Vector Vector::operator*(float val) const
17
+{
18
+    Vector vec(*this);
19
+    for (unsigned i = 0; i < size(); ++i)
20
+    {
21
+        vec[i] *= val;
22
+    }
23
+    return vec;
24
+}
25
+
26
+Vector Vector::operator/(float val) const
27
+{
28
+    Vector vec(*this);
29
+    for (unsigned i = 0; i < size(); ++i)
30
+    {
31
+        vec[i] /= val;
32
+    }
33
+    return vec;
34
+}
35
+
36
+Archive& operator<<(Archive &ar, Vector &vec)
37
+{
38
+    for (unsigned i = 0; i < vec.size(); ++i)
39
+    {
40
+        ar << vec[i];
41
+    }
42
+    return ar;
43
+}
44
+
45
+Archive& operator>>(Archive &ar, Vector &vec)
46
+{
47
+    for (unsigned i = 0; i < vec.size(); ++i)
48
+    {
49
+        ar >> vec.mValues[i];
50
+    }
51
+    return ar;
52
+}
0 53
\ No newline at end of file
1 54
new file mode 100644
... ...
@@ -0,0 +1,41 @@
1
+#ifndef __COGAPS_VECTOR_H__
2
+#define __COGAPS_VECTOR_H__
3
+
4
+#include "../Archive.h"
5
+
6
+#include <boost/align/aligned_allocator.hpp>
7
+#include <vector>
8
+
9
+namespace bal = boost::alignment;
10
+typedef std::vector<float, bal::aligned_allocator<float,32> > aligned_vector;
11
+
12
+class Vector
13
+{
14
+private:
15
+
16
+    aligned_vector mValues;
17
+
18
+public:
19
+
20
+    Vector(unsigned size) : mValues(aligned_vector(size, 0.f)) {}
21
+
22
+    const float* ptr() const {return &mValues[0];}
23
+    float* ptr() {return &mValues[0];}
24
+
25
+    float& operator[](unsigned i) {return mValues[i];}
26
+    float operator[](unsigned i) const {return mValues[i];}
27
+
28
+    unsigned size() const {return mValues.size();}
29
+
30
+    Rcpp::NumericVector rVec() const {return Rcpp::wrap(mValues);}
31
+    void concat(const Vector& vec);
32
+    void operator+=(const Vector &vec);
33
+
34
+    Vector operator*(float val) const;
35
+    Vector operator/(float val) const;
36
+
37
+    friend Archive& operator<<(Archive &ar, Vector &vec);
38
+    friend Archive& operator>>(Archive &ar, Vector &vec);
39
+};
40
+
41
+#endif
0 42
\ No newline at end of file
1 43
new file mode 100644
... ...
@@ -0,0 +1,41 @@
1
+#include "CsvParser.h"
2
+
3
+// open file, read column names
4
+CsvParser::CsvParser(const std::string &path)
5
+{
6
+    mFile.open(path.c_str());
7
+
8
+    std::string line;
9
+    std::getline(mFile, line); // read first entry (blank)
10
+    
11
+    while (!std::isdigit(mFile.peek()))
12
+    {
13
+        std::getline(mFile, line)
14
+        mColNames.push_back(line);
15
+    }
16
+    mRowNames.push_back(mColNames.back());
17
+    mColNames.pop_back(); // read one too far
18
+}
19
+
20
+bool CsvParser::hasNext() const
21
+{
22
+    return mFile.peek() != EOF;
23
+}
24
+
25
+MatrixElement CsvParser::getNext() const
26
+{
27
+    int c = mFile.peek();
28
+    
29
+    std::string line;
30
+    std::getline(mFile, line);
31
+    if (std::isdigit(c)) // matrix element
32
+    {
33
+        Rcout << line << '\n';
34
+        return MatrixElement(0,0,0.f);
35
+    }
36
+    else // row name
37
+    {
38
+        mRowNames.push_back(line);
39
+        return getNext();
40
+    }
41
+}
0 42
\ No newline at end of file
1 43
new file mode 100644
... ...
@@ -0,0 +1,30 @@
1
+#ifndef __COGAPS_CSV_PARSER_H__
2
+#define __COGAPS_CSV_PARSER_H__
3
+
4
+#include "MatrixElement.h"
5
+
6
+#include <fstream>
7
+#include <vector>
8
+#include <string>
9
+
10
+class CsvParser
11
+{
12
+private:
13
+
14
+    std::ifstream mFile;
15
+
16
+    std::vector<std::string> mRowNames;
17
+    std::vector<std::string> mColNames;
18
+
19
+    unsigned mCurrentRow;
20
+    unsigned mCurrentCol;
21
+
22
+public:
23
+
24
+    CsvParser(const std::string &path);
25
+
26
+    bool hasNext() const;
27
+    MatrixElement getNext() const; 
28
+};
29
+
30
+#endif
0 31
\ No newline at end of file
1 32
new file mode 100644
... ...
@@ -0,0 +1,15 @@
1
+#ifndef __COGAPS_MATRIX_ELEMENT_H__
2
+#define __COGAPS_MARRIX_ELEMENT_H__
3
+
4
+struct MatrixElement
5
+{
6
+    unsigned row;
7
+    unsigned col;
8
+    float value;
9
+
10
+    MatrixElement(unsigned r, unsigned c, float v)
11
+        : row(r), col(c), value(v)
12
+    {}
13
+};
14
+
15
+#endif
0 16
\ No newline at end of file
... ...
@@ -5,8 +5,10 @@
5 5
     #define __x86_64__ 1
6 6
 #endif
7 7
 
8
-#if !defined(_OPENMP)
8
+#ifndef _OPENMP
9 9
     #warning "Compiler does not support OpenMP"
10
+#else
11
+    #define __GAPS_OPENMP__
10 12
 #endif
11 13
 
12 14
 #ifndef SSE_INSTR_SET