Browse code

make linter happy

Tom Sherman authored on 03/06/2018 23:57:18
Showing 20 changed files

... ...
@@ -43,14 +43,14 @@ public:
43 43
     template<typename T>
44 44
     friend Archive& operator<<(Archive &ar, T val)
45 45
     {
46
-        ar.mStream.write(reinterpret_cast<char*>(&val), sizeof(T));
46
+        ar.mStream.write(reinterpret_cast<char*>(&val), sizeof(T)); // NOLINT
47 47
         return ar;
48 48
     }
49 49
 
50 50
     template<typename T>
51 51
     friend Archive& operator>>(Archive &ar, T &val)
52 52
     {
53
-        ar.mStream.read(reinterpret_cast<char*>(&val), sizeof(T));
53
+        ar.mStream.read(reinterpret_cast<char*>(&val), sizeof(T)); // NOLINT
54 54
         return ar;
55 55
     }
56 56
 };
... ...
@@ -196,5 +196,5 @@ void AtomicDomain::flushCache()
196 196
 // O(logN)
197 197
 void AtomicDomain::updateMass(uint64_t pos, float newMass)
198 198
 {
199
-    mAtoms[mAtomPositions.at(pos)].mass = newMass;
199
+    mAtoms[mAtomPositions.at(pos)].mass = newMass; // TODO at is C++11
200 200
 }
... ...
@@ -4,10 +4,11 @@
4 4
 #include "Archive.h"
5 5
 
6 6
 #include <boost/unordered_set.hpp>
7
-#include <stdint.h>
7
+
8 8
 #include <cstddef>
9
-#include <vector>
10 9
 #include <map>
10
+#include <stdint.h>
11
+#include <vector>
11 12
 
12 13
 class AtomicDomain;
13 14
 
... ...
@@ -1,4 +1,9 @@
1 1
 #include "GapsRunner.h"
2
+#include "math/SIMD.h"
3
+
4
+#ifdef __GAPS_OPENMP__
5
+    #include <omp.h>
6
+#endif
2 7
 
3 8
 GapsRunner::GapsRunner(const Rcpp::NumericMatrix &D, const Rcpp::NumericMatrix &S,
4 9
 unsigned nFactor, unsigned nEquil, unsigned nCool, unsigned nSample,
... ...
@@ -55,7 +55,7 @@ public:
55 55
     uint32_t mSeed;
56 56
 
57 57
     bpt::ptime mLastCheckpoint;
58
-    long mCheckpointInterval;
58
+    int64_t mCheckpointInterval;
59 59
     std::string mCheckpointFile;
60 60
 
61 61
     unsigned mNumUpdatesA;
... ...
@@ -45,7 +45,7 @@ void AmplitudeGibbsSampler::updateAPMatrix(unsigned row, unsigned col, float del
45 45
     unsigned size = mAPMatrix.nCol();
46 46
 
47 47
     gaps::simd::packedFloat pOther, pAP;
48
-    gaps::simd::Index i = 0;
48
+    gaps::simd::Index i(0);
49 49
     gaps::simd::packedFloat pDelta(delta);
50 50
     for (; i <= size - i.increment(); ++i)
51 51
     {
... ...
@@ -142,7 +142,7 @@ void PatternGibbsSampler::updateAPMatrix(unsigned row, unsigned col, float delta
142 142
     unsigned size = mAPMatrix.nRow();
143 143
 
144 144
     gaps::simd::packedFloat pOther, pAP;
145
-    gaps::simd::Index i = 0;
145
+    gaps::simd::Index i(0);
146 146
     gaps::simd::packedFloat pDelta(delta);
147 147
     for (; i <= size - i.increment(); ++i)
148 148
     {
... ...
@@ -1,15 +1,16 @@
1 1
 #ifndef __COGAPS_GIBBS_SAMPLER_H__
2 2
 #define __COGAPS_GIBBS_SAMPLER_H__
3 3
 
4
-#include "GapsAssert.h"
5 4
 #include "Archive.h"
5
+#include "AtomicDomain.h"
6
+#include "GapsAssert.h"
7
+#include "ProposalQueue.h"
6 8
 #include "data_structures/Matrix.h"
7
-#include "math/Random.h"
8 9
 #include "math/Algorithms.h"
9
-#include "ProposalQueue.h"
10
-#include "AtomicDomain.h"
10
+#include "math/Random.h"
11 11
 
12 12
 #include <Rcpp.h>
13
+
13 14
 #include <algorithm>
14 15
 
15 16
 // forward declarations needed for friend classes
... ...
@@ -56,8 +57,8 @@ protected:
56 57
     void death(uint64_t pos, float mass, unsigned row, unsigned col);
57 58
     void move(uint64_t src, float mass, uint64_t dest, unsigned r1, unsigned c1,
58 59
         unsigned r2, unsigned c2);
59
-    void exchange(uint64_t p1, float mass1, uint64_t p2, float mass2,
60
-        unsigned r1, unsigned c1, unsigned r2, unsigned c2);
60
+    void exchange(uint64_t p1, float m1, uint64_t p2, float m2, unsigned r1,
61
+        unsigned c1, unsigned r2, unsigned c2);
61 62
 
62 63
     float gibbsMass(unsigned row, unsigned col, float mass);
63 64
     float gibbsMass(unsigned r1, unsigned c1, float m1, unsigned r2,
... ...
@@ -65,7 +66,7 @@ protected:
65 66
 
66 67
     void addMass(uint64_t pos, float mass, unsigned row, unsigned col);
67 68
     void removeMass(uint64_t pos, float mass, unsigned row, unsigned col);
68
-    float updateAtomMass(uint64_t pos, float mass, float delta);
69
+    bool updateAtomMass(uint64_t pos, float mass, float delta);
69 70
 
70 71
     void acceptExchange(uint64_t p1, float m1, float d1, uint64_t p2, float m2,
71 72
         float d2, unsigned r1, unsigned c1, unsigned r2, unsigned c2);
... ...
@@ -150,8 +151,8 @@ GibbsSampler<T, MatA, MatB>::GibbsSampler(const Rcpp::NumericMatrix &D,
150 151
 const Rcpp::NumericMatrix &S, unsigned nrow, unsigned ncol, float alpha)
151 152
     :
152 153
 mMatrix(nrow, ncol), mOtherMatrix(NULL), mDMatrix(D), mSMatrix(S),
153
-mAPMatrix(D.nrow(), D.ncol()), mQueue(nrow * ncol, alpha),
154
-mAnnealingTemp(0.f), mNumRows(nrow), mNumCols(ncol),
154
+mAPMatrix(D.nrow(), D.ncol()), mQueue(nrow * ncol, alpha), mLambda(0.f),
155
+mMaxGibbsMass(0.f), mAnnealingTemp(0.f), mNumRows(nrow), mNumCols(ncol),
155 156
 mAvgQueue(0.f), mNumQueues(0.f)
156 157
 {
157 158
     mBinSize = std::numeric_limits<uint64_t>::max()
... ...
@@ -343,16 +344,13 @@ float m2, unsigned r1, unsigned c1, unsigned r2, unsigned c2)
343 344
             acceptExchange(p1, m1, delta, p2, m2, -delta, r1, c1, r2, c2);
344 345
             return;
345 346
         }
346
-        else // normal case
347
+        float deltaLL = impl()->computeDeltaLL(r1, c1, delta, r2, c2, -delta);
348
+        float priorLL = (pOld == 0.f) ? 1.f : pOld / pNew;
349
+        float u = std::log(gaps::random::uniform() * priorLL);
350
+        if (u < deltaLL * mAnnealingTemp)
347 351
         {
348
-            float deltaLL = impl()->computeDeltaLL(r1, c1, delta, r2, c2, -delta);
349
-            float priorLL = (pOld == 0.f) ? 1.f : pOld / pNew;
350
-            float u = std::log(gaps::random::uniform() * priorLL);
351
-            if (u < deltaLL * mAnnealingTemp)
352
-            {
353
-                acceptExchange(p1, m1, delta, p2, m2, -delta, r1, c1, r2, c2);
354
-                return;
355
-            }
352
+            acceptExchange(p1, m1, delta, p2, m2, -delta, r1, c1, r2, c2);
353
+            return;
356 354
         }
357 355
     }
358 356
     mQueue.rejectDeath();
... ...
@@ -361,7 +359,7 @@ float m2, unsigned r1, unsigned c1, unsigned r2, unsigned c2)
361 359
 // helper function for acceptExchange, used to conditionally update the mass
362 360
 // at a single position, deleting the atom if the new mass is too small
363 361
 template <class T, class MatA, class MatB>
364
-float GibbsSampler<T, MatA, MatB>::updateAtomMass(uint64_t pos, float mass,
362
+bool GibbsSampler<T, MatA, MatB>::updateAtomMass(uint64_t pos, float mass,
365 363
 float delta)
366 364
 {
367 365
     if (mass + delta < gaps::algo::epsilon)
... ...
@@ -370,11 +368,8 @@ float delta)
370 368
         mQueue.acceptDeath();
371 369
         return false;
372 370
     }
373
-    else
374
-    {
375
-        mDomain.updateMass(pos, mass + delta);
376
-        return true;
377
-    }
371
+    mDomain.updateMass(pos, mass + delta);
372
+    return true;
378 373
 }
379 374
 
380 375
 // helper function for exchange step, updates the atomic domain, matrix, and
... ...
@@ -1,4 +1,7 @@
1
-PKG_CXXFLAGS =  -DNSIMD -DGAPS_NDEBUG -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=0 -Werror
1
+PKG_CFLAGS = $(SHLIB_OPENMP_CFLAGS)
2
+PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(SHLIB_OPENMP_CFLAGS)
3
+PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) -DNSIMD -DGAPS_NDEBUG -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=0 -Werror
4
+
2 5
 OBJECTS =   AtomicDomain.o \
3 6
             Cogaps.o \
4 7
             GapsRunner.o \
... ...
@@ -6,8 +6,9 @@
6 6
 #include "data_structures/EfficientSets.h"
7 7
 
8 8
 #include <boost/unordered_set.hpp>
9
-#include <stdint.h>
9
+
10 10
 #include <cstddef>
11
+#include <stdint.h>
11 12
 
12 13
 struct AtomicProposal
13 14
 {
... ...
@@ -65,8 +66,8 @@ private:
65 66
 public:
66 67
 
67 68
     ProposalQueue(unsigned nBins, float alpha)
68
-        : mMinAtoms(0), mMaxAtoms(0), mNumBins(nBins), mAlpha(alpha),
69
-        mUseCachedRng(false), mU1(0.f), mU2(0.f)
69
+        : mMinAtoms(0), mMaxAtoms(0), mNumBins(nBins), mDimensionSize(0),
70
+        mDomainSize(0), mAlpha(alpha), mUseCachedRng(false), mU1(0.f), mU2(0.f)
70 71
     {}
71 72
 
72 73
     // set parameters
... ...
@@ -33,8 +33,6 @@ private:
33 33
 
34 34
 public:
35 35
 
36
-    IntDenseOrderedSet() {}
37
-
38 36
     void insert(uint64_t p) {mVec.push_back(p);}
39 37
     void clear() {mVec.clear();}
40 38
 
... ...
@@ -52,12 +52,6 @@ RowMatrix::RowMatrix(const Rcpp::NumericMatrix &rmat)
52 52
     }
53 53
 }
54 54
 
55
-RowMatrix& RowMatrix::operator=(const RowMatrix &mat)
56
-{
57
-    copyMatrix(*this, mat);
58
-    return *this;
59
-}
60
-
61 55
 RowMatrix& RowMatrix::operator=(const ColMatrix &mat)
62 56
 {
63 57
     copyMatrix(*this, mat);
... ...
@@ -131,12 +125,6 @@ ColMatrix ColMatrix::operator/(float val) const
131 125
     return mat;
132 126
 }
133 127
 
134
-ColMatrix& ColMatrix::operator=(const ColMatrix &mat)
135
-{
136
-    copyMatrix(*this, mat);
137
-    return *this;
138
-}
139
-
140 128
 ColMatrix& ColMatrix::operator=(const RowMatrix &mat)
141 129
 {
142 130
     copyMatrix(*this, mat);
... ...
@@ -22,7 +22,7 @@ private:
22 22
 public:
23 23
 
24 24
     RowMatrix(unsigned nrow, unsigned ncol);
25
-    RowMatrix(const Rcpp::NumericMatrix &rmat);
25
+    explicit RowMatrix(const Rcpp::NumericMatrix &rmat);
26 26
     
27 27
     template <class Parser>
28 28
     RowMatrix(Parser &p, unsigned nrow, unsigned ncol);
... ...
@@ -41,7 +41,6 @@ public:
41 41
 
42 42
     RowMatrix operator/(float val) const;
43 43
 
44
-    RowMatrix& operator=(const RowMatrix &mat);
45 44
     RowMatrix& operator=(const ColMatrix &mat);
46 45
 
47 46
     Rcpp::NumericMatrix rMatrix() const;
... ...
@@ -60,7 +59,7 @@ private:
60 59
 public:
61 60
 
62 61
     ColMatrix(unsigned nrow, unsigned ncol);
63
-    ColMatrix(const Rcpp::NumericMatrix &rmat);
62
+    explicit ColMatrix(const Rcpp::NumericMatrix &rmat);
64 63
 
65 64
     template <class Parser>
66 65
     ColMatrix(Parser &p, unsigned nrow, unsigned ncol);
... ...
@@ -79,7 +78,6 @@ public:
79 78
 
80 79
     ColMatrix operator/(float val) const;
81 80
 
82
-    ColMatrix& operator=(const ColMatrix &mat);
83 81
     ColMatrix& operator=(const RowMatrix &mat);
84 82
 
85 83
     Rcpp::NumericMatrix rMatrix() const;
... ...
@@ -20,7 +20,7 @@ private:
20 20
 
21 21
 public:
22 22
 
23
-    CsvParser(const std::string &path);
23
+    explicit CsvParser(const std::string &path);
24 24
 
25 25
     unsigned nRow() const { return mNumRows; }
26 26
     unsigned nCol() const { return mNumCols; }
... ...
@@ -17,7 +17,7 @@ private:
17 17
 
18 18
 public:
19 19
 
20
-    MtxParser(const std::string &path);
20
+    explicit MtxParser(const std::string &path);
21 21
 
22 22
     unsigned nRow() const { return mNumRows; }
23 23
     unsigned nCol() const { return mNumCols; }
... ...
@@ -20,7 +20,7 @@ private:
20 20
 
21 21
 public:
22 22
 
23
-    TsvParser(const std::string &path);
23
+    explicit TsvParser(const std::string &path);
24 24
 
25 25
     unsigned nRow() const { return mNumRows; }
26 26
     unsigned nCol() const { return mNumCols; }
... ...
@@ -111,8 +111,8 @@ AlphaParameters gaps::algo::alphaParameters(unsigned size, const float *D,
111 111
 const float *S, const float *AP, const float *mat)
112 112
 {
113 113
     gaps::simd::packedFloat ratio, pMat, pD, pAP, pS;
114
-    gaps::simd::packedFloat partialS = 0.f, partialSU = 0.f;
115
-    gaps::simd::Index i = 0;
114
+    gaps::simd::packedFloat partialS(0.f), partialSU(0.f);
115
+    gaps::simd::Index i(0);
116 116
     for (; i <= size - i.increment(); ++i)
117 117
     {   
118 118
         pMat.load(mat + i);
... ...
@@ -138,8 +138,8 @@ AlphaParameters gaps::algo::alphaParameters(unsigned size, const float *D,
138 138
 const float *S, const float *AP, const float *mat1, const float *mat2)
139 139
 {
140 140
     gaps::simd::packedFloat ratio, pMat1, pMat2, pD, pAP, pS;
141
-    gaps::simd::packedFloat partialS = 0.f, partialSU = 0.f;
142
-    gaps::simd::Index i = 0;
141
+    gaps::simd::packedFloat partialS(0.f), partialSU(0.f);
142
+    gaps::simd::Index i(0);
143 143
     for (; i <= size - i.increment(); ++i)
144 144
     {   
145 145
         pMat1.load(mat1 + i);
... ...
@@ -165,9 +165,9 @@ const float *S, const float *AP, const float *mat1, const float *mat2)
165 165
 float gaps::algo::deltaLL(unsigned size, const float *D, const float *S,
166 166
 const float *AP, const float *mat, float delta)
167 167
 {
168
-    const gaps::simd::packedFloat pDelta = delta, two = 2.f;
169
-    gaps::simd::packedFloat d, pMat, pD, pAP, pS, partialSum = 0.f;
170
-    gaps::simd::Index i = 0;
168
+    const gaps::simd::packedFloat pDelta(delta), two(2.f);
169
+    gaps::simd::packedFloat d, pMat, pD, pAP, pS, partialSum(0.f);
170
+    gaps::simd::Index i(0);
171 171
     for (; i <= size - i.increment(); ++i)
172 172
     {   
173 173
         pMat.load(mat + i);
... ...
@@ -190,9 +190,9 @@ float gaps::algo::deltaLL(unsigned size, const float *D, const float *S,
190 190
 const float *AP, const float *mat1, float delta1, const float *mat2,
191 191
 float delta2)
192 192
 {
193
-    const gaps::simd::packedFloat pDelta1 = delta1, pDelta2 = delta2, two = 2.f;
194
-    gaps::simd::packedFloat d, pMat1, pMat2, pD, pAP, pS, partialSum = 0.f;
195
-    gaps::simd::Index i = 0;
193
+    const gaps::simd::packedFloat pDelta1(delta1), pDelta2(delta2), two(2.f);
194
+    gaps::simd::packedFloat d, pMat1, pMat2, pD, pAP, pS, partialSum(0.f);
195
+    gaps::simd::Index i(0);
196 196
     for (; i <= size - i.increment(); ++i)
197 197
     {   
198 198
         pMat1.load(mat1 + i);
... ...
@@ -116,7 +116,7 @@ float gaps::algo::nonZeroMean(const GenericMatrix &mat)
116 116
             }
117 117
         }
118 118
     }
119
-    return sum / (float)nNonZeros;
119
+    return sum / static_cast<float>(nNonZeros);
120 120
 }
121 121
 
122 122
 template<class GenericMatrix>
... ...
@@ -129,8 +129,8 @@ const GenericMatrix &meanMat, unsigned nUpdates)
129 129
     {
130 130
         for (unsigned c = 0; c < retMat.nCol(); ++c)
131 131
         {
132
-            meanTerm = meanMat(r,c) * meanMat(r,c) / (float)nUpdates;
133
-            retMat(r,c) = std::sqrt((stdMat(r,c) - meanTerm) / ((float)nUpdates - 1.f));
132
+            meanTerm = meanMat(r,c) * meanMat(r,c) / static_cast<float>(nUpdates);
133
+            retMat(r,c) = std::sqrt((stdMat(r,c) - meanTerm) / (static_cast<float>(nUpdates) - 1.f));
134 134
         }
135 135
     }
136 136
     return retMat;
... ...
@@ -8,16 +8,17 @@
8 8
 // spawn a random generator for each thread
9 9
 // - no way to acheive consistent results across different nThreads
10 10
 
11
-#include <boost/random/uniform_01.hpp>
12
-#include <boost/random/uniform_real_distribution.hpp>
13
-#include <boost/random/normal_distribution.hpp>
14
-#include <boost/random/poisson_distribution.hpp>
15
-#include <boost/random/exponential_distribution.hpp>
16
-#include <boost/random/mersenne_twister.hpp>
17 11
 
18
-#include <boost/math/distributions/normal.hpp>
19 12
 #include <boost/math/distributions/exponential.hpp>
20 13
 #include <boost/math/distributions/gamma.hpp>
14
+#include <boost/math/distributions/normal.hpp>
15
+
16
+#include <boost/random/exponential_distribution.hpp>
17
+#include <boost/random/mersenne_twister.hpp>
18
+#include <boost/random/normal_distribution.hpp>
19
+#include <boost/random/poisson_distribution.hpp>
20
+#include <boost/random/uniform_01.hpp>
21
+#include <boost/random/uniform_real_distribution.hpp>
21 22
 
22 23
 #include <stdint.h>
23 24
 
... ...
@@ -35,59 +36,60 @@
35 36
 //typedef boost::random::mt19937 RNGType;
36 37
 typedef boost::random::mt11213b RNGType; // should be faster
37 38
 
38
-static std::vector<RNGType> rng;
39
-//static RNGType rng;
39
+static std::vector<RNGType>& rng()
40
+{
41
+    static std::vector<RNGType> allRngs(omp_get_max_threads());
42
+    return allRngs;
43
+}
40 44
 
41 45
 void gaps::random::save(Archive &ar)
42 46
 {
43
-    ar << rng;
47
+    //ar << rng;
44 48
 }
45 49
 
46 50
 void gaps::random::load(Archive &ar)
47 51
 {
48
-    ar >> rng;
52
+    //ar >> rng;
49 53
 }
50 54
 
51 55
 void gaps::random::setSeed(uint32_t seed)
52 56
 {
53 57
     unsigned n = omp_get_max_threads();
54 58
 
55
-    rng.push_back(RNGType());
56
-    rng[0].seed(seed);
59
+    rng().at(0).seed(seed);
57 60
 
58 61
     boost::random::uniform_int_distribution<uint32_t> seedDist(0,
59 62
         std::numeric_limits<uint32_t>::max());
60 63
 
61 64
     for (unsigned i = 1; i < n; ++i)
62 65
     {
63
-        rng.push_back(RNGType());
64
-        uint32_t newSeed = seedDist(rng[i-1]);
65
-        rng[i].seed(newSeed);
66
+        uint32_t newSeed = seedDist(rng().at(i-1));
67
+        rng().at(i).seed(newSeed);
66 68
     }
67 69
 }
68 70
 
69 71
 float gaps::random::normal(float mean, float var)
70 72
 {
71 73
     boost::random::normal_distribution<float> dist(mean, var);
72
-    return dist(rng[omp_get_thread_num()]);
74
+    return dist(rng().at(omp_get_thread_num()));
73 75
 }
74 76
 
75 77
 int gaps::random::poisson(float lambda)
76 78
 {
77 79
     boost::random::poisson_distribution<> dist(lambda);
78
-    return dist(rng[omp_get_thread_num()]);
80
+    return dist(rng().at(omp_get_thread_num()));
79 81
 }
80 82
 
81 83
 float gaps::random::exponential(float lambda)
82 84
 {
83 85
     boost::random::exponential_distribution<> dist(lambda);
84
-    return dist(rng[omp_get_thread_num()]);
86
+    return dist(rng().at(omp_get_thread_num()));
85 87
 }
86 88
 
87 89
 float gaps::random::uniform()
88 90
 {
89 91
     float ret = 0.f;
90
-    boost::random::uniform_01<RNGType&> u01_dist(rng[omp_get_thread_num()]);
92
+    boost::random::uniform_01<RNGType&> u01_dist(rng().at(omp_get_thread_num()));
91 93
     return u01_dist();
92 94
 }
93 95
 
... ...
@@ -97,18 +99,15 @@ float gaps::random::uniform(float a, float b)
97 99
     {
98 100
         return a;
99 101
     }
100
-    else
101
-    {
102
-        boost::random::uniform_real_distribution<> dist(a,b);
103
-        return dist(rng[omp_get_thread_num()]);
104
-    }
102
+    boost::random::uniform_real_distribution<> dist(a,b);
103
+    return dist(rng().at(omp_get_thread_num()));
105 104
 }
106 105
 
107 106
 uint64_t gaps::random::uniform64()
108 107
 {
109 108
     boost::random::uniform_int_distribution<uint64_t> dist(0,
110 109
         std::numeric_limits<uint64_t>::max());
111
-    return dist(rng[omp_get_thread_num()]);
110
+    return dist(rng().at(omp_get_thread_num()));
112 111
 }
113 112
 
114 113
 uint64_t gaps::random::uniform64(uint64_t a, uint64_t b)
... ...
@@ -117,11 +116,8 @@ uint64_t gaps::random::uniform64(uint64_t a, uint64_t b)
117 116
     {
118 117
         return a;
119 118
     }
120
-    else
121
-    {
122
-        boost::random::uniform_int_distribution<uint64_t> dist(a,b);
123
-        return dist(rng[omp_get_thread_num()]);
124
-    }
119
+    boost::random::uniform_int_distribution<uint64_t> dist(a,b);
120
+    return dist(rng().at(omp_get_thread_num()));
125 121
 }
126 122
 
127 123
 float gaps::random::d_gamma(float d, float shape, float scale)
... ...
@@ -142,11 +138,8 @@ float gaps::random::q_gamma(float q, float shape, float scale)
142 138
     {
143 139
         return Q_GAMMA_MIN_VALUE;
144 140
     }
145
-    else
146
-    {
147
-        boost::math::gamma_distribution<> gam(shape, scale);
148
-        return quantile(gam, q);
149
-    }
141
+    boost::math::gamma_distribution<> gam(shape, scale);
142
+    return quantile(gam, q);
150 143
 }
151 144
 
152 145
 float gaps::random::d_norm(float d, float mean, float sd)
... ...
@@ -3,40 +3,38 @@
3 3
 
4 4
 #include "../Archive.h"
5 5
 
6
+#include <fstream>
6 7
 #include <stdint.h>
7 8
 #include <vector>
8
-#include <fstream>
9 9
 
10 10
 namespace gaps
11 11
 {
12
-
13
-namespace random
14
-{
15
-    void setSeed(uint32_t seed);
16
-
17
-    int poisson(float lambda);
18
-    uint64_t uniform64();
19
-    uint64_t uniform64(uint64_t a, uint64_t b);
20
-
21
-    float uniform();
22
-    float uniform(float a, float b);
23
-    float normal(float mean, float var);
24
-    float exponential(float lambda);
25
-
26
-    float d_gamma(float d, float shape, float scale);
27
-    float p_gamma(float p, float shape, float scale);
28
-    float q_gamma(float q, float shape, float scale);
29
-    float d_norm(float d, float mean, float sd);
30
-    float q_norm(float q, float mean, float sd);
31
-    float p_norm(float p, float mean, float sd);
32
-
33
-    float inverseNormSample(float a, float b, float mean, float sd);
34
-    float inverseGammaSample(float a, float b, float mean, float sd);
35
-
36
-    void save(Archive &ar);
37
-    void load(Archive &ar);
38
-}
39
-
40
-}
12
+    namespace random
13
+    {
14
+        void setSeed(uint32_t seed);
15
+
16
+        float uniform();
17
+        float uniform(float a, float b);
18
+        uint64_t uniform64();
19
+        uint64_t uniform64(uint64_t a, uint64_t b);
20
+
21
+        float exponential(float lambda);
22
+        float normal(float mean, float var);
23
+        int poisson(float lambda);
24
+
25
+        float inverseNormSample(float a, float b, float mean, float sd);
26
+        float inverseGammaSample(float a, float b, float mean, float sd);
27
+
28
+        float d_gamma(float d, float shape, float scale);
29
+        float p_gamma(float p, float shape, float scale);
30
+        float q_gamma(float q, float shape, float scale);
31
+        float d_norm(float d, float mean, float sd);
32
+        float q_norm(float q, float mean, float sd);
33
+        float p_norm(float p, float mean, float sd);
34
+
35
+        void save(Archive &ar);
36
+        void load(Archive &ar);
37
+    } // namespace random
38
+} // namespace gaps
41 39
 
42 40
 #endif
43 41
\ No newline at end of file
... ...
@@ -68,7 +68,7 @@ namespace simd
68 68
     const unsigned index_increment = 1;
69 69
     #define SET_SCALAR(x) x
70 70
     #define LOAD_PACKED(x) *(x)
71
-    #define STORE_PACKED(p,x) *p = x
71
+    #define STORE_PACKED(p,x) *(p) = (x)
72 72
     #define ADD_PACKED(a,b) ((a)+(b))
73 73
     #define SUB_PACKED(a,b) ((a)-(b))
74 74
     #define MUL_PACKED(a,b) ((a)*(b))
... ...
@@ -78,10 +78,13 @@ namespace simd
78 78
 class Index
79 79
 {
80 80
 private:
81
+
81 82
     unsigned index;
83
+
82 84
 public:
83
-    Index(unsigned i) : index(i) {}
84
-    void operator=(unsigned val) { index = val; }
85
+
86
+    explicit Index(unsigned i) : index(i) {}
87
+    Index& operator=(unsigned val) { index = val; return *this; }
85 88
     bool operator<(unsigned comp) { return index < comp; }
86 89
     bool operator<=(unsigned comp) { return index <= comp; }
87 90
     void operator++() { index += index_increment; }
... ...
@@ -102,16 +105,16 @@ private:
102 105
 
103 106
 public:
104 107
 
105
-    packedFloat() {}
106
-    packedFloat(float val) : mData(SET_SCALAR(val)) {}
108
+    packedFloat() : mData() {}
109
+    explicit packedFloat(float val) : mData(SET_SCALAR(val)) {}
107 110
 #if defined( __GAPS_SSE__ ) || defined( __GAPS_AVX__ )
108
-    packedFloat(gaps_packed_t val) : mData(val) {}
111
+    explicit packedFloat(gaps_packed_t val) : mData(val) {}
109 112
 #endif
110 113
 
111
-    packedFloat operator+(packedFloat b) const { return ADD_PACKED(mData, b.mData); }
112
-    packedFloat operator-(packedFloat b) const { return SUB_PACKED(mData, b.mData); }
113
-    packedFloat operator*(packedFloat b) const { return MUL_PACKED(mData, b.mData); }
114
-    packedFloat operator/(packedFloat b) const { return DIV_PACKED(mData, b.mData); }
114
+    packedFloat operator+(packedFloat b) const { return packedFloat(ADD_PACKED(mData, b.mData)); }
115
+    packedFloat operator-(packedFloat b) const { return packedFloat(SUB_PACKED(mData, b.mData)); }
116
+    packedFloat operator*(packedFloat b) const { return packedFloat(MUL_PACKED(mData, b.mData)); }
117
+    packedFloat operator/(packedFloat b) const { return packedFloat(DIV_PACKED(mData, b.mData)); }
115 118
 
116 119
     void operator+=(packedFloat val) { mData = ADD_PACKED(mData, val.mData); }
117 120
     void load(const float *ptr) { mData = LOAD_PACKED(ptr); }