Skip to content

Commit

Permalink
Don't return a value before the first valid data point.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianwalenz committed Jun 27, 2019
1 parent 650fdc2 commit 7733c8c
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/utility/sampledDistribution.H
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,39 @@ public:

uint32 getValue(double d) {

if (d < 0.0) d = 0.0;
if (d > 1.0) d = 1.0;
// Imagine our input histogram (value occurences) is expanded into an
// array of (_dataSum) values, where each 'value' in the input histogram
// is listed 'occurences' times (and that it's sorted).
//
// For input 0 <= 'd' < 1, we want to return the 'value' that is at that
// position in the array.

if (d < 0.0) d = 0.0; // Limit our input (random) number
if (d > 1.0) d = 1.0; // to valid scaling range.

uint64 pos = 0;
uint64 lim = (uint64)floor(_dataSum * d);

if (pos >= _dataSum) pos = _dataSum;
// Scan the _data, looking for the _data element that contains the 'lim'th
// entry in the (imagined) array.

while (_data[pos] < lim) {
lim -= _data[pos];
pos += 1;
}
uint64 value = 0; // value we're testing.

while (_data[value] <= lim) { // If _data[value] is more than the current
lim -= _data[value]; // limit, we're found the value, otherwise,
value += 1; // decrement the limit by the occurrences
} // for this value and move to the next.

assert(pos < _dataLen);
assert(value < _dataLen);

return(pos);
return(value);
};


public:
uint32 _dataLen; // Highest valid point
uint32 _dataMax; // Number allocated
uint32 *_data;
uint32 _dataLen; // Length of the valid data in _data: _data[_dataLen-1] is the last valid data point.
uint32 _dataMax; // Allocated size of _data.
uint32 *_data; // Number of data points of value x: _data[x] == v <-> 'x' was present 'v' times in the input.

uint64 _dataSum;
uint64 _dataSum; // Number of points in the input. It's the sum of all _data[x].
};

0 comments on commit 7733c8c

Please sign in to comment.