Skip to content
This repository was archived by the owner on Dec 21, 2023. It is now read-only.

Commit 3481485

Browse files
author
Hoyt Koepke
committed
Changed fast_uniform to uniform (as uniform was faster).
1 parent 374cc26 commit 3481485

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+174
-193
lines changed

src/core/logging/table_printer/table_printer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct progress_time {
156156
*
157157
* for(size_t i = 0; i < 50000; ++i) {
158158
* table.print_progress_row(proc, proc, progress_time(), i);
159-
* proc += random::fast_uniform<size_t>(0, 100);
159+
* proc += random::uniform<size_t>(0, 100);
160160
* usleep(100); // sleep for 200 microseconds
161161
* }
162162
*

src/core/logging/table_printer/table_printer_examples.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int main(int argc, char **argv) {
5959

6060
for(size_t i = 0; i < 50000; ++i) {
6161
table.print_progress_row(proc, proc, progress_time(), i);
62-
proc += random::fast_uniform<size_t>(0, 100);
62+
proc += random::uniform<size_t>(0, 100);
6363
usleep(100); // sleep for 200 microseconds
6464
}
6565

src/core/random/alias.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ alias_sampler::alias_sampler(const std::vector<double>& p) {
5656
}
5757

5858
size_t alias_sampler::sample() {
59-
size_t k = random::fast_uniform<size_t>(0, K - 1);
60-
if (q[k] > random::fast_uniform<double>(0, 1)) {
59+
size_t k = random::uniform<size_t>(0, K - 1);
60+
if (q[k] > random::uniform<double>(0, 1)) {
6161
return k;
6262
} else {
6363
return J[k];

src/core/random/random.hpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ namespace turi {
5959
return distribution_type(min, max)(m_rng);
6060
}
6161
};
62+
6263
template<>
6364
struct uniform<double> {
6465
typedef std::uniform_real_distribution<double> distribution_type;
@@ -132,7 +133,7 @@ namespace turi {
132133
* Generate a random number in the uniform real with range [min,
133134
* max) or [min, max] if the number type is discrete.
134135
*/
135-
template <typename NumType>
136+
template <typename NumType = uint32_t>
136137
inline NumType uniform(const NumType min, const NumType max,
137138
typename std::enable_if<std::is_integral<NumType>::value>::type* = nullptr) {
138139

@@ -144,7 +145,7 @@ namespace turi {
144145
/**
145146
* Generate a random number in the uniform real with range [min,
146147
* max) or [min, max] if the number type is discrete.
147-
* [Double overload]
148+
* [Float overload]
148149
*/
149150
template <typename NumType>
150151
inline NumType uniform(const NumType min, const NumType max,
@@ -155,14 +156,6 @@ namespace turi {
155156
return d(m_rng);
156157
} // end of uniform
157158

158-
/**
159-
* Generate a random number in the uniform real with range [min,
160-
* max) or [min, max] if the number type is discrete.
161-
*/
162-
template <typename NumType>
163-
inline NumType fast_uniform(const NumType min, const NumType max) {
164-
return uniform<NumType>(min, max);
165-
}
166159

167160
/**
168161
* Generate a random number in the uniform real with range [min,
@@ -379,18 +372,6 @@ namespace turi {
379372
return get_source().uniform<NumType>(min, max);
380373
} // end of uniform
381374

382-
/**
383-
* \ingroup random
384-
* Generate a random number in the uniform real with range [min,
385-
* max) or [min, max] if the number type is discrete.
386-
*/
387-
template<typename NumType>
388-
inline NumType fast_uniform(const NumType min, const NumType max) {
389-
if (min == max) return min;
390-
return get_source().fast_uniform<NumType>(min, max);
391-
} // end of uniform
392-
393-
394375
/**
395376
* \ingroup random
396377
* Generate a random number between 0 and 1
@@ -401,7 +382,7 @@ namespace turi {
401382
* \ingroup random
402383
* Simulates the standard rand function as defined in cstdlib
403384
*/
404-
inline int rand() { return uniform(0, RAND_MAX); }
385+
inline int rand() { return uniform<int>(0, RAND_MAX); }
405386

406387

407388
/**

src/core/storage/serialization/dir_archive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ size_t get_next_random_number() {
278278
gen.nondet_seed();
279279
initialized = true;
280280
}
281-
return gen.fast_uniform<size_t>(0, std::numeric_limits<size_t>::max());
281+
return gen.uniform<size_t>(0, std::numeric_limits<size_t>::max());
282282
}
283283

284284

src/core/storage/sframe_data/sarray_file_format_v2.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class sarray_format_reader_v2: public sarray_format_reader<T> {
314314
* (looping around).
315315
*/
316316
void try_evict_something_from_cache() {
317-
size_t b = turi::random::fast_uniform<size_t>(0, m_cache.size() - 1);
317+
size_t b = turi::random::uniform<size_t>(0, m_cache.size() - 1);
318318
/*
319319
* if the current bit is not 1, try to find the next one bit
320320
* if there is no bit after that, loop around, reset and 0 and try the bit

src/core/util/testing_utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ std::string _get_unique_directory(const std::string& file, size_t line) {
5656

5757
ss << "t" << thread::thread_id() << "__";
5858

59-
ss << random::fast_uniform<size_t>(0, size_t(-1));
59+
ss << random::uniform<size_t>(0, size_t(-1));
6060

6161
return ss.str();
6262
}

src/core/util/testing_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void _save_and_load_object(T& dest, const U& src, std::string dir) {
4848

4949
std::string arc_name = dir + "/test_archive";
5050

51-
uint64_t random_number = hash64(random::fast_uniform<size_t>(0,size_t(-1)));
51+
uint64_t random_number = hash64(random::uniform<size_t>(0,size_t(-1)));
5252

5353
// Save it
5454
dir_archive archive_write;

src/ml/ml_data/ml_data.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ ml_data ml_data::create_subsampled_copy(size_t n_rows, size_t random_seed) const
746746
for(size_t i = 0; i < n_rows; ++i) {
747747
size_t lb = (i > 0) ? (samples[i - 1] + 1) : 0;
748748
size_t ub = (i < n_rows - 1) ? (samples[i + 1] - 1) : data_size - 1;
749-
samples[i] = random::fast_uniform<size_t>(lb, ub);
749+
samples[i] = random::uniform<size_t>(lb, ub);
750750
}
751751

752752
// Break them up into groups

src/ml/sketches/countmin.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class countmin {
6969
gen.seed(seed);
7070
// Initialize hash functions and count matrix
7171
for (size_t j = 0; j < num_hash; ++j) {
72-
seeds.push_back(gen.fast_uniform<size_t>(0, std::numeric_limits<size_t>::max()));
72+
seeds.push_back(gen.uniform<size_t>(0, std::numeric_limits<size_t>::max()));
7373
counts.push_back(std::vector<size_t>(num_bins));
7474
}
7575
}

0 commit comments

Comments
 (0)