Browse code

make range inclusive

Tom Sherman authored on 23/08/2018 20:06:38
Showing 2 changed files

... ...
@@ -496,6 +496,7 @@ bool GibbsSampler<T, MatA, MatB>::updateAtomMass(Atom *atom, float delta)
496 496
 {
497 497
     if (atom->mass + delta < gaps::epsilon)
498 498
     {
499
+        DEBUG_PING // want to know if this ever happens
499 500
         mDomain.cacheErase(atom->pos);
500 501
         mQueue.acceptDeath();
501 502
         return false;
... ...
@@ -510,12 +511,6 @@ template <class T, class MatA, class MatB>
510 511
 void GibbsSampler<T, MatA, MatB>::acceptExchange(AtomicProposal *prop,
511 512
 float d1, unsigned r1, unsigned c1, unsigned r2, unsigned c2)
512 513
 {
513
-    // can make this assertion more formal if we customize p/q norm functions
514
-    // to handle tail situations a certain way
515
-    GAPS_ASSERT(prop->atom1->mass + d1 > gaps::epsilon);
516
-    GAPS_ASSERT(prop->atom2->mass - d1 > gaps::epsilon);
517
-    //d1 = gaps::max(-1.f * (prop->atom1->mass - epsilon), d1);
518
-
519 514
     float d2 = -1.f * d1;
520 515
     bool b1 = updateAtomMass(prop->atom1, d1);
521 516
     bool b2 = updateAtomMass(prop->atom2, d2);
... ...
@@ -123,14 +123,15 @@ uint32_t GapsRng::uniform32()
123 123
     return next();
124 124
 }
125 125
 
126
+// inclusive of a and b
126 127
 uint32_t GapsRng::uniform32(uint32_t a, uint32_t b)
127 128
 {
128
-    uint32_t range = b - a;
129
-    if (range == 0)
129
+    if (b == a)
130 130
     {
131 131
         return a;
132 132
     }
133 133
 
134
+    uint32_t range = b + 1 - a;
134 135
     uint32_t x = uniform32();
135 136
     uint32_t iPart = std::numeric_limits<uint32_t>::max() / range;
136 137
     while (x >= range * iPart)
... ...
@@ -147,14 +148,15 @@ uint64_t GapsRng::uniform64()
147 148
     return high | low;
148 149
 }
149 150
 
151
+// inclusive of a and b
150 152
 uint64_t GapsRng::uniform64(uint64_t a, uint64_t b)
151 153
 {
152
-    uint64_t range = b - a;
153
-    if (range == 0)
154
+    if (b == a)
154 155
     {
155 156
         return a;
156 157
     }
157 158
 
159
+    uint64_t range = b + 1 - a;
158 160
     uint64_t x = uniform64();
159 161
     uint64_t iPart = std::numeric_limits<uint64_t>::max() / range;
160 162
     while (x >= range * iPart)