diff --git a/src/core/logging/table_printer/table_printer.hpp b/src/core/logging/table_printer/table_printer.hpp index cc8a2f3d17..15da9919ae 100644 --- a/src/core/logging/table_printer/table_printer.hpp +++ b/src/core/logging/table_printer/table_printer.hpp @@ -156,7 +156,7 @@ struct progress_time { * * for(size_t i = 0; i < 50000; ++i) { * table.print_progress_row(proc, proc, progress_time(), i); - * proc += random::fast_uniform(0, 100); + * proc += random::uniform(0, 100); * usleep(100); // sleep for 200 microseconds * } * diff --git a/src/core/logging/table_printer/table_printer_examples.cpp b/src/core/logging/table_printer/table_printer_examples.cpp index 10ef67003c..f686c1fa02 100644 --- a/src/core/logging/table_printer/table_printer_examples.cpp +++ b/src/core/logging/table_printer/table_printer_examples.cpp @@ -59,7 +59,7 @@ int main(int argc, char **argv) { for(size_t i = 0; i < 50000; ++i) { table.print_progress_row(proc, proc, progress_time(), i); - proc += random::fast_uniform(0, 100); + proc += random::uniform(0, 100); usleep(100); // sleep for 200 microseconds } diff --git a/src/core/random/alias.cpp b/src/core/random/alias.cpp index ea3fb9549c..c8483f170a 100644 --- a/src/core/random/alias.cpp +++ b/src/core/random/alias.cpp @@ -56,8 +56,8 @@ alias_sampler::alias_sampler(const std::vector& p) { } size_t alias_sampler::sample() { - size_t k = random::fast_uniform(0, K - 1); - if (q[k] > random::fast_uniform(0, 1)) { + size_t k = random::uniform(0, K - 1); + if (q[k] > random::uniform(0, 1)) { return k; } else { return J[k]; diff --git a/src/core/random/random.hpp b/src/core/random/random.hpp index 9b711c0c9d..27fc20ca57 100644 --- a/src/core/random/random.hpp +++ b/src/core/random/random.hpp @@ -144,7 +144,7 @@ namespace turi { /** * Generate a random number in the uniform real with range [min, * max) or [min, max] if the number type is discrete. - * [Double overload] + * [Float overload] */ template inline NumType uniform(const NumType min, const NumType max, @@ -155,14 +155,6 @@ namespace turi { return d(m_rng); } // end of uniform - /** - * Generate a random number in the uniform real with range [min, - * max) or [min, max] if the number type is discrete. - */ - template - inline NumType fast_uniform(const NumType min, const NumType max) { - return uniform(min, max); - } /** * Generate a random number in the uniform real with range [min, @@ -385,11 +377,16 @@ namespace turi { * max) or [min, max] if the number type is discrete. */ template - inline NumType fast_uniform(const NumType min, const NumType max) { + inline NumType uniform(const NumType min, const NumType max) { if (min == max) return min; +<<<<<<< Updated upstream return get_source().fast_uniform(min, max); } // end of uniform +======= + return get_source().uniform(min, max); + } // end of uniform +>>>>>>> Stashed changes /** * \ingroup random diff --git a/src/core/storage/serialization/dir_archive.cpp b/src/core/storage/serialization/dir_archive.cpp index ba904d3daa..898eca2500 100644 --- a/src/core/storage/serialization/dir_archive.cpp +++ b/src/core/storage/serialization/dir_archive.cpp @@ -278,7 +278,7 @@ size_t get_next_random_number() { gen.nondet_seed(); initialized = true; } - return gen.fast_uniform(0, std::numeric_limits::max()); + return gen.uniform(0, std::numeric_limits::max()); } diff --git a/src/core/storage/sframe_data/sarray_file_format_v2.hpp b/src/core/storage/sframe_data/sarray_file_format_v2.hpp index c1817b2a03..52f7940cf2 100644 --- a/src/core/storage/sframe_data/sarray_file_format_v2.hpp +++ b/src/core/storage/sframe_data/sarray_file_format_v2.hpp @@ -314,7 +314,7 @@ class sarray_format_reader_v2: public sarray_format_reader { * (looping around). */ void try_evict_something_from_cache() { - size_t b = turi::random::fast_uniform(0, m_cache.size() - 1); + size_t b = turi::random::uniform(0, m_cache.size() - 1); /* * if the current bit is not 1, try to find the next one bit * if there is no bit after that, loop around, reset and 0 and try the bit diff --git a/src/core/util/testing_utils.cpp b/src/core/util/testing_utils.cpp index 66307baf74..d4be6d6d71 100644 --- a/src/core/util/testing_utils.cpp +++ b/src/core/util/testing_utils.cpp @@ -56,7 +56,7 @@ std::string _get_unique_directory(const std::string& file, size_t line) { ss << "t" << thread::thread_id() << "__"; - ss << random::fast_uniform(0, size_t(-1)); + ss << random::uniform(0, size_t(-1)); return ss.str(); } diff --git a/src/core/util/testing_utils.hpp b/src/core/util/testing_utils.hpp index 15bffa518b..3b01567ff8 100644 --- a/src/core/util/testing_utils.hpp +++ b/src/core/util/testing_utils.hpp @@ -48,7 +48,7 @@ void _save_and_load_object(T& dest, const U& src, std::string dir) { std::string arc_name = dir + "/test_archive"; - uint64_t random_number = hash64(random::fast_uniform(0,size_t(-1))); + uint64_t random_number = hash64(random::uniform(0,size_t(-1))); // Save it dir_archive archive_write; diff --git a/src/ml/ml_data/ml_data.cpp b/src/ml/ml_data/ml_data.cpp index c04f8b25b6..bc70c3fa81 100644 --- a/src/ml/ml_data/ml_data.cpp +++ b/src/ml/ml_data/ml_data.cpp @@ -746,7 +746,7 @@ ml_data ml_data::create_subsampled_copy(size_t n_rows, size_t random_seed) const for(size_t i = 0; i < n_rows; ++i) { size_t lb = (i > 0) ? (samples[i - 1] + 1) : 0; size_t ub = (i < n_rows - 1) ? (samples[i + 1] - 1) : data_size - 1; - samples[i] = random::fast_uniform(lb, ub); + samples[i] = random::uniform(lb, ub); } // Break them up into groups diff --git a/src/ml/sketches/countmin.hpp b/src/ml/sketches/countmin.hpp index c3f46f7e49..4b726655cf 100644 --- a/src/ml/sketches/countmin.hpp +++ b/src/ml/sketches/countmin.hpp @@ -69,7 +69,7 @@ class countmin { gen.seed(seed); // Initialize hash functions and count matrix for (size_t j = 0; j < num_hash; ++j) { - seeds.push_back(gen.fast_uniform(0, std::numeric_limits::max())); + seeds.push_back(gen.uniform(0, std::numeric_limits::max())); counts.push_back(std::vector(num_bins)); } } diff --git a/src/ml/sketches/countsketch.hpp b/src/ml/sketches/countsketch.hpp index 1c065cc3cf..5df55554fe 100644 --- a/src/ml/sketches/countsketch.hpp +++ b/src/ml/sketches/countsketch.hpp @@ -62,8 +62,8 @@ class countsketch { gen.seed(seed); // Initialize hash functions and count matrix for (size_t j = 0; j < num_hash; ++j) { - seeds.push_back(gen.fast_uniform(0, std::numeric_limits::max())); - seeds_binary.push_back(gen.fast_uniform(0, std::numeric_limits::max())); + seeds.push_back(gen.uniform(0, std::numeric_limits::max())); + seeds_binary.push_back(gen.uniform(0, std::numeric_limits::max())); counts.push_back(std::vector(num_bins)); } diff --git a/src/toolkits/clustering/kmeans.cpp b/src/toolkits/clustering/kmeans.cpp index f3ed4c1ac6..a56c2ca4df 100644 --- a/src/toolkits/clustering/kmeans.cpp +++ b/src/toolkits/clustering/kmeans.cpp @@ -722,7 +722,7 @@ void kmeans_model::choose_random_centers() { progress_table.print_header(); // Choose the first center and set in the model. - size_t idx_center = turi::random::fast_uniform(0, seeds.size() - 1); + size_t idx_center = turi::random::uniform(0, seeds.size() - 1); progress_table.print_progress_row(0, 0, idx_center); clusters[0].center = seeds[idx_center]; diff --git a/src/toolkits/factorization/factorization_model_impl.hpp b/src/toolkits/factorization/factorization_model_impl.hpp index 2e993d891d..4f5251df93 100644 --- a/src/toolkits/factorization/factorization_model_impl.hpp +++ b/src/toolkits/factorization/factorization_model_impl.hpp @@ -178,7 +178,7 @@ class factorization_model_impl final : public factorization_model { size_t end_w_idx = ((thread_idx + 1) * n_total_dimensions) / num_threads; for(size_t i = start_w_idx; i < end_w_idx; ++i) - w[i] = (sd > 0) ? random::fast_uniform(-sd/2, sd/2) : 0; + w[i] = (sd > 0) ? random::uniform(-sd/2, sd/2) : 0; } else { w.setZero(); } @@ -206,9 +206,9 @@ class factorization_model_impl final : public factorization_model { // observations, num_factors > 100), this gave good // starting values and didn't diverge on reset. - V(i, j) = (V_sd > 0) ? random::fast_uniform(lb, ub) : 0; + V(i, j) = (V_sd > 0) ? random::uniform(lb, ub) : 0; - if(random::fast_uniform(0, num_factors()) > std::min(4ULL, num_factors() / 2)) + if(random::uniform(0, num_factors()) > std::min(4ULL, num_factors() / 2)) V(i, j) /= 1000; } } diff --git a/src/toolkits/factorization/ranking_sgd_solver_base.hpp b/src/toolkits/factorization/ranking_sgd_solver_base.hpp index 96b607dbee..401ed3cc33 100644 --- a/src/toolkits/factorization/ranking_sgd_solver_base.hpp +++ b/src/toolkits/factorization/ranking_sgd_solver_base.hpp @@ -479,7 +479,7 @@ class ranking_sgd_solver_base : public sgd::sgd_solver_base { // Get num_sampled_negative_examples candidate points. for(size_t i = 0; i < num_sampled_negative_examples; ++i) { - size_t candidate_item = random::fast_uniform(0, n_items - 1); + size_t candidate_item = random::uniform(0, n_items - 1); item_observed.prefetch(candidate_item); candidate_negative_items[i] = candidate_item; } @@ -554,7 +554,7 @@ class ranking_sgd_solver_base : public sgd::sgd_solver_base { proc_buf.available_item_list_chosen_indices.resize(num_sampled_negative_examples); for(size_t i = 0; i < num_sampled_negative_examples; ++i) { - size_t idx = random::fast_uniform(0, proc_buf.available_item_list.size()-1); + size_t idx = random::uniform(0, proc_buf.available_item_list.size()-1); chosen_negative_items[i] = proc_buf.available_item_list[idx]; proc_buf.available_item_list_chosen_indices[i] = idx; DASSERT_FALSE(item_observed.get(chosen_negative_items[i])); diff --git a/src/toolkits/ml_data_2/ml_data.cpp b/src/toolkits/ml_data_2/ml_data.cpp index 6f682fa392..6ca1f32cc9 100644 --- a/src/toolkits/ml_data_2/ml_data.cpp +++ b/src/toolkits/ml_data_2/ml_data.cpp @@ -639,7 +639,7 @@ ml_data ml_data::create_subsampled_copy(size_t n_rows, size_t random_seed) const for(size_t i = 0; i < n_rows; ++i) { size_t lb = (i > 0) ? (samples[i - 1] + 1) : 0; size_t ub = (i < n_rows - 1) ? (samples[i + 1] - 1) : data_size - 1; - samples[i] = random::fast_uniform(lb, ub); + samples[i] = random::uniform(lb, ub); } // Break them up into groups diff --git a/src/toolkits/ml_data_2/ml_data_setup.cpp b/src/toolkits/ml_data_2/ml_data_setup.cpp index d008b5ee38..7940f46d63 100644 --- a/src/toolkits/ml_data_2/ml_data_setup.cpp +++ b/src/toolkits/ml_data_2/ml_data_setup.cpp @@ -564,7 +564,7 @@ void ml_data::_fill_data_blocks(bool in_training_mode) { while(true) { // If it's a full block, write it to a random location. - size_t write_out_segment = random::fast_uniform(0, output_iterators.size()-1); + size_t write_out_segment = random::uniform(0, output_iterators.size()-1); if(output_iterator_locks[write_out_segment].try_lock()) { auto& it_out = output_iterators[write_out_segment]; diff --git a/src/toolkits/nearest_neighbors/lsh_family.cpp b/src/toolkits/nearest_neighbors/lsh_family.cpp index 0049c47fc7..532fc76b32 100644 --- a/src/toolkits/nearest_neighbors/lsh_family.cpp +++ b/src/toolkits/nearest_neighbors/lsh_family.cpp @@ -92,7 +92,7 @@ void lsh_euclidean::pre_lsh(const v2::ml_data& mld_ref, bool is_sparse) { }); } w = std::max(size_t(1), static_cast(distance_matrix.mean())); - rand_vec = rand_vec.unaryExpr([&](double x) { return random::fast_uniform(0., w); }); + rand_vec = rand_vec.unaryExpr([&](double x) { return random::uniform(0., w); }); } void lsh_euclidean::init_model(size_t num_dimensions) { @@ -101,7 +101,7 @@ void lsh_euclidean::init_model(size_t num_dimensions) { rand_mat.resize(num_projections, num_input_dimensions); rand_vec.resize(num_projections); rand_mat = rand_mat.unaryExpr([](double x) { return random::normal(0., 1.); }); - rand_vec = rand_vec.unaryExpr([&](double x) { return random::fast_uniform(0., w); }); + rand_vec = rand_vec.unaryExpr([&](double x) { return random::uniform(0., w); }); } void lsh_euclidean::save(turi::oarchive& oarc) const { @@ -172,7 +172,7 @@ void lsh_manhattan::pre_lsh(const v2::ml_data& mld_ref, bool is_sparse) { } w = std::max(size_t(1), static_cast(distance_matrix.mean())); - rand_vec = rand_vec.unaryExpr([&](double x) { return random::fast_uniform(0., w); }); + rand_vec = rand_vec.unaryExpr([&](double x) { return random::uniform(0., w); }); } void lsh_manhattan::init_model(size_t num_dimensions) { @@ -181,7 +181,7 @@ void lsh_manhattan::init_model(size_t num_dimensions) { rand_mat.resize(num_projections, num_input_dimensions); rand_vec.resize(num_projections); rand_mat = rand_mat.unaryExpr([](double x) { return random::cauchy(0., 1.); }); - rand_vec = rand_vec.unaryExpr([&](double x) { return random::fast_uniform(0., w); }); + rand_vec = rand_vec.unaryExpr([&](double x) { return random::uniform(0., w); }); } void lsh_cosine::init_model(size_t num_dimensions) { @@ -233,7 +233,7 @@ void lsh_jaccard::init_model(size_t num_dimensions) { rand_sign.assign(num_input_dimensions, 0); parallel_for (0, num_input_dimensions, [&](size_t idx) { rand_permutation[idx] = idx; - if (random::fast_uniform(0., 1.) > 0.5) { + if (random::uniform(0., 1.) > 0.5) { rand_sign[idx] = 1; } }); diff --git a/src/toolkits/sparse_similarity/sparse_similarity_lookup_impl.hpp b/src/toolkits/sparse_similarity/sparse_similarity_lookup_impl.hpp index 901ceb0e7f..603690f0d9 100644 --- a/src/toolkits/sparse_similarity/sparse_similarity_lookup_impl.hpp +++ b/src/toolkits/sparse_similarity/sparse_similarity_lookup_impl.hpp @@ -582,8 +582,8 @@ class sparse_similarity_lookup_impl : public sparse_similarity_lookup { for(size_t s_idx = sample_start_idx; s_idx < sample_end_idx; ++s_idx) { auto& s = samples[s_idx]; - s.i = random::fast_uniform(0, num_items - 1); - s.j = random::fast_uniform(0, num_items - 1); + s.i = random::uniform(0, num_items - 1); + s.j = random::uniform(0, num_items - 1); s.log_1_m_q = 0; } @@ -598,7 +598,7 @@ class sparse_similarity_lookup_impl : public sparse_similarity_lookup { // Do an iid sample here. item_count_distribution.resize(user_count_dist_sample_size); for(size_t i = 0; i < user_count_dist_sample_size; ++i) { - size_t idx = random::fast_uniform(0, items_per_user.size() - 1); + size_t idx = random::uniform(0, items_per_user.size() - 1); item_count_distribution[i] = items_per_user[idx]; } mult_factor = double(items_per_user.size()) / item_count_distribution.size(); diff --git a/src/toolkits/text/alias.cpp b/src/toolkits/text/alias.cpp index aca951360d..3b5feeb780 100644 --- a/src/toolkits/text/alias.cpp +++ b/src/toolkits/text/alias.cpp @@ -563,7 +563,7 @@ size_t alias_topic_model::sample_topic(size_t d, size_t w, size_t s, double prob_sparse_sample = Q(0, w) / (Pdw + Q(0, w)); size_t t = static_cast(-1); - if (random::fast_uniform(0, 1) < prob_sparse_sample) { + if (random::uniform(0, 1) < prob_sparse_sample) { // Use samples precomputed via Alias sampler t = word_samples[w].back(); @@ -576,7 +576,7 @@ size_t alias_topic_model::sample_topic(size_t d, size_t w, size_t s, } else { // Inverse CDF method on the sparse part - double cutoff = random::fast_uniform(0, Pdw); + double cutoff = random::uniform(0, Pdw); double current = 0.0; if (doc_topic_counts.get_row(d).size() == 0) { @@ -609,7 +609,7 @@ size_t alias_topic_model::sample_topic(size_t d, size_t w, size_t s, (Pdw * pdwt + Q(0, w) * q(w, t)); // Perform MH step - size_t chosen_topic = (random::fast_uniform(0, 1) < + size_t chosen_topic = (random::uniform(0, 1) < std::min(1.0, pi)) ? t : s; // Reset probs to 0 for (const auto& kv : doc_topic_counts.get_row(d)) { diff --git a/src/toolkits/text/cgs.cpp b/src/toolkits/text/cgs.cpp index 19e1694ac5..102cd2921c 100644 --- a/src/toolkits/text/cgs.cpp +++ b/src/toolkits/text/cgs.cpp @@ -258,7 +258,7 @@ std::map cgs_topic_model::sample_counts( // Iterate through each token // Choose a random spot in the document to try first. This way we reduce biases. - size_t shift = random::fast_uniform(0, x.size()-1); + size_t shift = random::uniform(0, x.size()-1); for (size_t _j = 0; _j < x.size(); ++_j) { size_t j = (_j + shift) % x.size(); diff --git a/src/toolkits/text/scvb.hpp b/src/toolkits/text/scvb.hpp index b7cfac78b2..03c055f613 100644 --- a/src/toolkits/text/scvb.hpp +++ b/src/toolkits/text/scvb.hpp @@ -84,7 +84,7 @@ class scvb0_solver { void initialize_N_theta_j(size_t C_j) { N_theta_j = Eigen::MatrixXd::Zero(model->num_topics, 1); for (size_t i = 0; i < C_j; ++i) { - size_t ix = random::fast_uniform(0, model->num_topics-1); + size_t ix = random::uniform(0, model->num_topics-1); N_theta_j(ix) += 1; } } diff --git a/src/toolkits/text/topic_model.cpp b/src/toolkits/text/topic_model.cpp index 9aff978dc2..7d7a3eae81 100644 --- a/src/toolkits/text/topic_model.cpp +++ b/src/toolkits/text/topic_model.cpp @@ -350,7 +350,7 @@ topic_model::count_matrix_type topic_model::predict_counts(std::shared_ptr(0, num_topics - 1); + size_t topic = random::uniform(0, num_topics - 1); DASSERT_TRUE(topic < num_topics); topic_assignments.push_back(topic); doc_topic_counts(doc_id, topic) += freq; @@ -373,7 +373,7 @@ topic_model::count_matrix_type topic_model::predict_counts(std::shared_ptr(0, x.size()-1); + size_t shift = random::uniform(0, x.size()-1); for (size_t _j = 0; _j < x.size(); ++_j) { size_t j = (_j + shift) % x.size(); diff --git a/src/toolkits/util/data_generators.cpp b/src/toolkits/util/data_generators.cpp index 84a61a851f..396a769028 100644 --- a/src/toolkits/util/data_generators.cpp +++ b/src/toolkits/util/data_generators.cpp @@ -139,7 +139,7 @@ sframe lm_data_generator::generate(size_t n_observations, if(n_categorical_values[j] == 0) { x[j] = random::normal(0, 1); } else { - x[j] = random::fast_uniform(0, n_categorical_values[j] - 1); + x[j] = random::uniform(0, n_categorical_values[j] - 1); } } diff --git a/src/toolkits/util/random_sframe_generation.cpp b/src/toolkits/util/random_sframe_generation.cpp index ce225dec0c..5e234ef04d 100644 --- a/src/toolkits/util/random_sframe_generation.cpp +++ b/src/toolkits/util/random_sframe_generation.cpp @@ -160,7 +160,7 @@ gl_sframe _generate_random_classification_sframe(size_t n_rows, std::string colu } for(size_t i = num_classes; i < n_bins; ++i) { - bin_to_class_map[i] = random::fast_uniform(0, num_classes - 1); + bin_to_class_map[i] = random::uniform(0, num_classes - 1); } random::shuffle(bin_to_class_map); diff --git a/test/fileio/block_cache_test.cxx b/test/fileio/block_cache_test.cxx index ffbf62568f..c3462e4899 100644 --- a/test/fileio/block_cache_test.cxx +++ b/test/fileio/block_cache_test.cxx @@ -40,8 +40,8 @@ struct block_cache_test { for (size_t nprobes = 0; nprobes < num_probes; ++nprobes) { TS_ASSERT_EQUALS(cache.value_length(std::to_string(key)), 256); // generate a random start-end sequence to read - size_t start = random::fast_uniform(0, 255); - size_t end = random::fast_uniform(0, 256); + size_t start = random::uniform(0, 255); + size_t end = random::uniform(0, 256); std::string value; auto ret = cache.read(std::to_string(key), value, start, end); // make sure the values we read were valid diff --git a/test/generics/gl_string.cxx b/test/generics/gl_string.cxx index 09ba679b2c..46736dc7a5 100644 --- a/test/generics/gl_string.cxx +++ b/test/generics/gl_string.cxx @@ -21,7 +21,7 @@ using namespace turi; int random_int() { - return random::fast_uniform(0, std::numeric_limits::max()); + return random::uniform(0, std::numeric_limits::max()); } void verify_serialization(const gl_string& v) { @@ -181,7 +181,7 @@ void verify_consistency(const gl_string& v) { void stress_test(size_t n_tests) { - auto gen_element = [](){ return char(random::fast_uniform(32, 127)); }; + auto gen_element = [](){ return char(random::uniform(32, 127)); }; gl_string v; std::string v_ref; @@ -204,7 +204,7 @@ void stress_test(size_t n_tests) { operations.push_back([&]() { auto e = gen_element(); - size_t idx = random::fast_uniform(0, v.size()); + size_t idx = random::uniform(0, v.size()); v.insert(v.begin() + idx, e); v_ref.insert(v_ref.begin() + idx, e); }); @@ -224,7 +224,7 @@ void stress_test(size_t n_tests) { operations.push_back([&]() { auto e = gen_element(); - size_t idx = random::fast_uniform(0, v.size()); + size_t idx = random::uniform(0, v.size()); v.insert(v.begin() + idx, 3, e); v_ref.insert(v_ref.begin() + idx, 3, e); }); @@ -246,7 +246,7 @@ void stress_test(size_t n_tests) { operations.push_back([&]() { auto e = gen_element(); auto e2 = e; - size_t idx = random::fast_uniform(0, v.size()); + size_t idx = random::uniform(0, v.size()); v.insert(v.begin() + idx, std::move(e)); v_ref.insert(v_ref.begin() + idx, std::move(e2)); }); @@ -267,7 +267,7 @@ void stress_test(size_t n_tests) { operations.push_back([&]() { std::string ev = {gen_element(), gen_element(), gen_element()}; - size_t idx = random::fast_uniform(0, v.size()); + size_t idx = random::uniform(0, v.size()); v.insert(v.begin() + idx, ev.begin(), ev.end()); v_ref.insert(v_ref.begin() + idx, ev.begin(), ev.end()); }); @@ -281,7 +281,7 @@ void stress_test(size_t n_tests) { // Erase, single element. operations.push_back([&]() { if(v.empty()) return; - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); v.erase(v.begin() + idx); v_ref.erase(v_ref.begin() + idx); }); @@ -289,8 +289,8 @@ void stress_test(size_t n_tests) { // Erase, block operations.push_back([&]() { if(v.empty()) return; - size_t idx_1 = random::fast_uniform(0, v.size() - 1); - size_t idx_2 = random::fast_uniform(0, v.size() - 1); + size_t idx_1 = random::uniform(0, v.size() - 1); + size_t idx_2 = random::uniform(0, v.size() - 1); v.erase(v.begin() + std::min(idx_1, idx_2), v.begin() + std::max(idx_1, idx_2)); v_ref.erase(v_ref.begin() + std::min(idx_1, idx_2), v_ref.begin() + std::max(idx_1, idx_2)); }); @@ -298,7 +298,7 @@ void stress_test(size_t n_tests) { // Erase, to end operations.push_back([&]() { if(v.empty()) return; - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); v.erase(v.begin() + idx, v.end()); v_ref.erase(v_ref.begin() + idx, v_ref.end()); }); @@ -306,7 +306,7 @@ void stress_test(size_t n_tests) { // Erase, from beginning operations.push_back([&]() { if(v.empty()) return; - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); v.erase(v.begin(), v.begin() + idx); v_ref.erase(v_ref.begin(), v_ref.begin() + idx); }); @@ -366,7 +366,7 @@ void stress_test(size_t n_tests) { // shuffle by index operations.push_back([&]() { for(size_t j = 0; j < v.size(); ++j) { - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); std::swap(v[j], v[idx]); std::swap(v_ref[j], v_ref[idx]); } @@ -375,7 +375,7 @@ void stress_test(size_t n_tests) { // shuffle by iterator operations.push_back([&]() { for(size_t j = 0; j < v.size(); ++j) { - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); std::swap(*(v.begin() + j), *(v.begin() + idx)); std::swap(*(v_ref.begin() + j), *(v_ref.begin() + idx)); } @@ -384,7 +384,7 @@ void stress_test(size_t n_tests) { // shuffle by reverse iterator operations.push_back([&]() { for(size_t j = 0; j < v.size(); ++j) { - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); std::swap(*(v.rbegin() + j), *(v.rbegin() + idx)); std::swap(*(v_ref.rbegin() + j), *(v_ref.rbegin() + idx)); } @@ -398,7 +398,7 @@ void stress_test(size_t n_tests) { v.swap(v2); v_ref.swap(v2_ref); - size_t idx = random::fast_uniform(0, v.size()); + size_t idx = random::uniform(0, v.size()); v.insert(v.begin() + idx, v2.begin(), v2.end()); v_ref.insert(v_ref.begin() + idx, v2_ref.begin(), v2_ref.end()); }); @@ -441,8 +441,8 @@ void stress_test(size_t n_tests) { // substring operations.push_back([&]() { - size_t n1 = random::fast_uniform(0, v.size()); - size_t n2 = random::fast_uniform(0, v.size()); + size_t n1 = random::uniform(0, v.size()); + size_t n2 = random::uniform(0, v.size()); if(n1 > n2) std::swap(n1, n2); @@ -457,7 +457,7 @@ void stress_test(size_t n_tests) { }); for(size_t i = 0; i < n_tests; ++i) { - size_t idx = random::fast_uniform(0, operations.size() - 1); + size_t idx = random::uniform(0, operations.size() - 1); operations[idx](); ASSERT_EQ(v.size(), v_ref.size()); diff --git a/test/generics/gl_vector.cxx b/test/generics/gl_vector.cxx index a6ff723712..4f6bc90ff4 100644 --- a/test/generics/gl_vector.cxx +++ b/test/generics/gl_vector.cxx @@ -37,7 +37,7 @@ size_t alignment_round(size_t n) { } int random_int() { - return random::fast_uniform(0, std::numeric_limits::max()); + return random::uniform(0, std::numeric_limits::max()); } template @@ -1521,7 +1521,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { operations.push_back([&]() { auto e = gen_element(); - size_t idx = random::fast_uniform(0, v.size()); + size_t idx = random::uniform(0, v.size()); v.insert(v.begin() + idx, e); v_ref.insert(v_ref.begin() + idx, e); }); @@ -1541,7 +1541,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { operations.push_back([&]() { auto e = gen_element(); - size_t idx = random::fast_uniform(0, v.size()); + size_t idx = random::uniform(0, v.size()); v.insert(v.begin() + idx, 3, e); v_ref.insert(v_ref.begin() + idx, 3, e); }); @@ -1563,7 +1563,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { operations.push_back([&]() { auto e = gen_element(); auto e2 = e; - size_t idx = random::fast_uniform(0, v.size()); + size_t idx = random::uniform(0, v.size()); v.insert(v.begin() + idx, std::move(e)); v_ref.insert(v_ref.begin() + idx, std::move(e2)); }); @@ -1584,7 +1584,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { operations.push_back([&]() { std::vector ev = {gen_element(), gen_element(), gen_element()}; - size_t idx = random::fast_uniform(0, v.size()); + size_t idx = random::uniform(0, v.size()); v.insert(v.begin() + idx, ev.begin(), ev.end()); v_ref.insert(v_ref.begin() + idx, ev.begin(), ev.end()); }); @@ -1598,7 +1598,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { // Erase, single element. operations.push_back([&]() { if(v.empty()) return; - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); v.erase(v.begin() + idx); v_ref.erase(v_ref.begin() + idx); }); @@ -1606,8 +1606,8 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { // Erase, block operations.push_back([&]() { if(v.empty()) return; - size_t idx_1 = random::fast_uniform(0, v.size() - 1); - size_t idx_2 = random::fast_uniform(0, v.size() - 1); + size_t idx_1 = random::uniform(0, v.size() - 1); + size_t idx_2 = random::uniform(0, v.size() - 1); v.erase(v.begin() + std::min(idx_1, idx_2), v.begin() + std::max(idx_1, idx_2)); v_ref.erase(v_ref.begin() + std::min(idx_1, idx_2), v_ref.begin() + std::max(idx_1, idx_2)); }); @@ -1615,7 +1615,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { // Erase, to end operations.push_back([&]() { if(v.empty()) return; - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); v.erase(v.begin() + idx, v.end()); v_ref.erase(v_ref.begin() + idx, v_ref.end()); }); @@ -1623,7 +1623,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { // Erase, from beginning operations.push_back([&]() { if(v.empty()) return; - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); v.erase(v.begin(), v.begin() + idx); v_ref.erase(v_ref.begin(), v_ref.begin() + idx); }); @@ -1681,7 +1681,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { // shuffle by index operations.push_back([&]() { for(size_t j = 0; j < v.size(); ++j) { - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); std::swap(v[j], v[idx]); std::swap(v_ref[j], v_ref[idx]); } @@ -1690,7 +1690,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { // shuffle by iterator operations.push_back([&]() { for(size_t j = 0; j < v.size(); ++j) { - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); std::swap(*(v.begin() + j), *(v.begin() + idx)); std::swap(*(v_ref.begin() + j), *(v_ref.begin() + idx)); } @@ -1699,7 +1699,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { // shuffle by reverse iterator operations.push_back([&]() { for(size_t j = 0; j < v.size(); ++j) { - size_t idx = random::fast_uniform(0, v.size() - 1); + size_t idx = random::uniform(0, v.size() - 1); std::swap(*(v.rbegin() + j), *(v.rbegin() + idx)); std::swap(*(v_ref.rbegin() + j), *(v_ref.rbegin() + idx)); } @@ -1713,7 +1713,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { v.swap(v2); v_ref.swap(v2_ref); - size_t idx = random::fast_uniform(0, v.size()); + size_t idx = random::uniform(0, v.size()); v.insert(v.begin() + idx, v2.begin(), v2.end()); v_ref.insert(v_ref.begin() + idx, v2_ref.begin(), v2_ref.end()); }); @@ -1754,7 +1754,7 @@ void stress_test(size_t n_tests, GenFunction&& gen_element) { }); for(size_t i = 0; i < n_tests; ++i) { - size_t idx = random::fast_uniform(0, operations.size() - 1); + size_t idx = random::uniform(0, operations.size() - 1); operations[idx](); ASSERT_EQ(v.size(), v_ref.size()); @@ -1794,7 +1794,7 @@ struct gl_vector_stress_test { void test_vector() { random::seed(2); stress_test >(100000, []() { - size_t len = random::fast_uniform(0, 10); + size_t len = random::uniform(0, 10); gl_vector v; v.reserve(len); for(size_t i = 0; i < len; ++i) { @@ -1808,7 +1808,7 @@ struct gl_vector_stress_test { void test_gl_vector() { random::seed(3); stress_test >(100000, []() { - size_t len = random::fast_uniform(0, 10); + size_t len = random::uniform(0, 10); gl_vector v; v.reserve(len); for(size_t i = 0; i < len; ++i) { diff --git a/test/ml_data/dml_basic_storage.cxx b/test/ml_data/dml_basic_storage.cxx index 99260ad00d..0c2a26158e 100644 --- a/test/ml_data/dml_basic_storage.cxx +++ b/test/ml_data/dml_basic_storage.cxx @@ -282,7 +282,7 @@ static void run_storage_check_test(size_t n, const std::string& run_string, if (row_end > row_start) { auto it = sliced_data.get_iterator(); - size_t idx = random::fast_uniform(0, row_end - 1 - row_start); + size_t idx = random::uniform(0, row_end - 1 - row_start); it.seek(idx); ASSERT_EQ(it.row_index(), idx); diff --git a/test/ml_data/dml_distributed_library.cpp b/test/ml_data/dml_distributed_library.cpp index 691bd1c161..f622753259 100644 --- a/test/ml_data/dml_distributed_library.cpp +++ b/test/ml_data/dml_distributed_library.cpp @@ -47,7 +47,7 @@ void run_reconcile_test(size_t n, const std::string& run_string, random::seed(dc_ptr->procid()); // Just so they don't all have the same number of entries - n += random::fast_uniform(0, std::max(0, n / 2)); + n += random::uniform(0, std::max(0, n / 2)); globals::set_global("TURI_ML_DATA_TARGET_ROW_BYTE_MINIMUM", 29); globals::set_global("TURI_ML_DATA_STATS_PARALLEL_ACCESS_THRESHOLD", 7); diff --git a/test/random/random_test.cxx b/test/random/random_test.cxx index ee60643c37..e8e5956c75 100644 --- a/test/random/random_test.cxx +++ b/test/random/random_test.cxx @@ -24,7 +24,7 @@ void uniform_speed(const size_t max_iter) { double slow_time = ti.current_time(); ti.start(); for(size_t i = 0; i < max_iter; ++i) { - sum += (NumType)(turi::random::fast_uniform(0, 10)); + sum += (NumType)(turi::random::uniform(0, 10)); } double fast_time = ti.current_time(); std::cout << slow_time << ", " << fast_time << std::endl; diff --git a/test/random/test_alias.cpp b/test/random/test_alias.cpp index 8786c0094a..cddc4cb510 100644 --- a/test/random/test_alias.cpp +++ b/test/random/test_alias.cpp @@ -30,7 +30,7 @@ std::vector create_large_pmf(size_t K) { auto probs = std::vector(K); double total = 0; for (size_t k = 0; k < probs.size(); ++k) { - probs[k] = random::fast_uniform(0, 100); + probs[k] = random::uniform(0, 100); total += probs[k]; } for (size_t k = 0; k < probs.size(); ++k) { @@ -74,7 +74,7 @@ void run_alias_benchmark(size_t num_samples, std::vector probs) { size_t K = probs.size(); ti.start(); for (size_t i=0; i < num_samples; ++i) { - k += random::fast_uniform(0, K); + k += random::uniform(0, K); } std::cout << std::setw(20) << "fast unif " << ti.current_time() << std::endl; diff --git a/test/sframe/sarray_file_format_v2_test.cxx b/test/sframe/sarray_file_format_v2_test.cxx index 90438e5d72..235caa592f 100644 --- a/test/sframe/sarray_file_format_v2_test.cxx +++ b/test/sframe/sarray_file_format_v2_test.cxx @@ -169,7 +169,7 @@ struct sarray_file_format_v2_test { random::seed(10001); for (size_t i = 0;i < 1600; ++i) { size_t len = 4096; - size_t start = random::fast_uniform(0, 16 * VERY_LARGE_SIZE - 4097); + size_t start = random::uniform(0, 16 * VERY_LARGE_SIZE - 4097); std::vector vals; reader.read_rows(start, start + len, vals); TS_ASSERT_EQUALS(vals.size(), len); @@ -201,7 +201,7 @@ struct sarray_file_format_v2_test { std::vector start_points; for (size_t i = 0;i < 16; ++i) { start_points.push_back( - random::fast_uniform(0, + random::uniform(0, 15 * VERY_LARGE_SIZE)); // 15 so as to give some gap for reading } @@ -256,7 +256,7 @@ struct sarray_file_format_v2_test { random::seed(10001); for (size_t i = 0;i < 1600; ++i) { size_t len = 4096; - size_t start = random::fast_uniform(0, 16 * VERY_LARGE_SIZE - 4097); + size_t start = random::uniform(0, 16 * VERY_LARGE_SIZE - 4097); std::vector vals; reader.read_rows(start, start + len, vals); TS_ASSERT_EQUALS(vals.size(), len); @@ -288,7 +288,7 @@ struct sarray_file_format_v2_test { std::vector start_points; for (size_t i = 0;i < 16; ++i) { start_points.push_back( - random::fast_uniform(0, + random::uniform(0, 15 * VERY_LARGE_SIZE)); // 15 so as to give some gap for reading } @@ -316,7 +316,7 @@ struct sarray_file_format_v2_test { std::vector start_points; for (size_t i = 0;i < 16; ++i) { start_points.push_back( - random::fast_uniform(0, + random::uniform(0, 15 * VERY_LARGE_SIZE)); // 15 so as to give some gap for reading } @@ -417,7 +417,7 @@ struct sarray_file_format_v2_test { random::seed(10001); for (size_t i = 0;i < 1600; ++i) { size_t len = 4096; - size_t start = random::fast_uniform(0, 16 * VERY_LARGE_SIZE - 4097); + size_t start = random::uniform(0, 16 * VERY_LARGE_SIZE - 4097); std::vector vals; reader.read_rows(start, start + len, vals); TS_ASSERT_EQUALS(vals.size(), len); @@ -457,7 +457,7 @@ struct sarray_file_format_v2_test { std::vector start_points; for (size_t i = 0;i < 16; ++i) { start_points.push_back( - random::fast_uniform(0, + random::uniform(0, 15 * VERY_LARGE_SIZE)); // 15 so as to give some gap for reading } @@ -489,7 +489,7 @@ struct sarray_file_format_v2_test { std::vector start_points; for (size_t i = 0;i < 16; ++i) { start_points.push_back( - random::fast_uniform(0, + random::uniform(0, 15 * VERY_LARGE_SIZE)); // 15 so as to give some gap for reading } diff --git a/test/sframe_query_engine/optimizations.cxx b/test/sframe_query_engine/optimizations.cxx index 41925ccf04..20af16c2c1 100644 --- a/test/sframe_query_engine/optimizations.cxx +++ b/test/sframe_query_engine/optimizations.cxx @@ -60,7 +60,7 @@ static node source_sarray() { std::vector data(n); for (size_t i = 0; i < n; ++i) - data[i] = random::fast_uniform(0,9); + data[i] = random::uniform(0,9); auto sa = std::make_shared>(); @@ -147,7 +147,7 @@ static node binary_source_sarray() { std::vector data(n); for (size_t i = 0; i < n; ++i) { - data[i] = (i < 4) ? 1 : random::fast_uniform(0,1); + data[i] = (i < 4) ? 1 : random::uniform(0,1); } auto sa = std::make_shared>(); @@ -187,7 +187,7 @@ static node source_sframe(size_t n_columns) { data[i].resize(n); for(size_t j = 0; j < n; ++j) { - data[i][j] = random::fast_uniform(0,9); + data[i][j] = random::uniform(0,9); } } @@ -237,7 +237,7 @@ static node shifted_source_sframe(size_t n_columns) { data[i].resize(2*n); for(size_t j = 0; j < 2*n; ++j) { - data[i][j] = random::fast_uniform(0,9); + data[i][j] = random::uniform(0,9); } } @@ -618,7 +618,7 @@ struct opts { std::vector indices; for(size_t i = 0; i < 5; ++i) - indices.push_back(random::fast_uniform(0, 9)); + indices.push_back(random::uniform(0, 9)); if(i % 2 == 0) n = make_union(n, source_sframe(5)); @@ -679,9 +679,9 @@ struct opts { std::vector indices; for(size_t i = 0; i < 5; ++i) - indices.push_back(random::fast_uniform(0, 9)); + indices.push_back(random::uniform(0, 9)); - if(random::fast_uniform(0, 1) == 0) + if(random::uniform(0, 1) == 0) n = make_union(n, old_n); else n = make_union(old_n, n); @@ -707,9 +707,9 @@ struct opts { std::vector indices; for(size_t i = 0; i < 5; ++i) - indices.push_back(random::fast_uniform(0, 9)); + indices.push_back(random::uniform(0, 9)); - if(random::fast_uniform(0, 1) == 0) + if(random::uniform(0, 1) == 0) n = make_union(n, old_n); else n = make_union(old_n, n); @@ -722,8 +722,8 @@ struct opts { nodes.push_back(n); - n = make_union(n, nodes[random::fast_uniform(0, nodes.size() - 1)]); - n = make_union(n, nodes[random::fast_uniform(0, nodes.size() - 1)]); + n = make_union(n, nodes[random::uniform(0, nodes.size() - 1)]); + n = make_union(n, nodes[random::uniform(0, nodes.size() - 1)]); } _RUN(n); @@ -798,7 +798,7 @@ struct opts { for(size_t i = 0; i < 20; ++i) { - std::vector indices = {random::fast_uniform(0, 5 + i - 1)}; + std::vector indices = {random::uniform(0, 5 + i - 1)}; n = make_union(n, make_transform(make_project(n, indices) ) ); } @@ -815,7 +815,7 @@ struct opts { std::vector indices; for(size_t j = 0; j < 2; ++j) - indices.push_back(random::fast_uniform(0, 5 + i - 1)); + indices.push_back(random::uniform(0, 5 + i - 1)); n = make_union(n, make_transform(make_project(n, indices) ) ); } @@ -833,7 +833,7 @@ struct opts { std::vector indices; for(size_t j = 0; j < 4; ++j) - indices.push_back(random::fast_uniform(0, 5 + i - 1)); + indices.push_back(random::uniform(0, 5 + i - 1)); n = make_union(n, make_transform(make_project(n, indices) ) ); } @@ -866,7 +866,7 @@ struct opts { std::vector indices; for(size_t j = 0; j < 5; ++j) - indices.push_back(random::fast_uniform(0, 4)); + indices.push_back(random::uniform(0, 4)); if(i %3 == 0) n = make_project(make_append(n, n2), indices); @@ -968,7 +968,7 @@ struct opts { std::vector indices; for(size_t j = 0; j < 2; ++j) - indices.push_back(random::fast_uniform(0, 5 + i - 1)); + indices.push_back(random::uniform(0, 5 + i - 1)); n = make_union(n, make_transform(make_project(n, indices) ) ); } @@ -1065,9 +1065,9 @@ struct opts { std::vector node_list = {make_generalized_transform(n, 10)}; for(size_t i = 0; i < 30; ++i) { - size_t idx_1 = random::fast_uniform(0, node_list.size() - 1); - size_t proj_idx = random::fast_uniform(0, 9); - size_t idx_2 = random::fast_uniform(0, node_list.size() - 1); + size_t idx_1 = random::uniform(0, node_list.size() - 1); + size_t proj_idx = random::uniform(0, 9); + size_t idx_2 = random::uniform(0, node_list.size() - 1); node_list.push_back(make_union(node_list[idx_1], make_project(node_list[idx_2], {proj_idx}))); } @@ -1096,13 +1096,13 @@ struct opts { std::vector node_list = {make_generalized_transform(n, 10)}; for(size_t i = 0; i < 20; ++i) { - size_t idx_1 = random::fast_uniform(0, node_list.size() - 1); - size_t idx_2 = random::fast_uniform(0, node_list.size() - 1); - size_t idx_3 = random::fast_uniform(0, node_list.size() - 1); + size_t idx_1 = random::uniform(0, node_list.size() - 1); + size_t idx_2 = random::uniform(0, node_list.size() - 1); + size_t idx_3 = random::uniform(0, node_list.size() - 1); std::vector project_indices(5); for(size_t& idx : project_indices) - idx = random::fast_uniform(0, 9); + idx = random::uniform(0, 9); node_list.push_back(make_union(node_list[idx_1], make_project(node_list[idx_2], project_indices))); node_list.push_back(make_union(node_list[idx_1], make_generalized_transform(node_list[idx_3], 10))); @@ -1111,7 +1111,7 @@ struct opts { n = make_union(node_list[0], node_list[1]); for(size_t i = 2; i < node_list.size(); ++i) { - size_t idx = random::fast_uniform(0, 14); + size_t idx = random::uniform(0, 14); n = make_union(n, make_project(node_list[i], {idx})); } @@ -1170,7 +1170,7 @@ struct opts { node n = base_1; for(size_t i = 0; i < 20; ++i) { - size_t idx_1 = random::fast_uniform(0, 9); + size_t idx_1 = random::uniform(0, 9); n = make_union(n, make_transform(make_project(base_1, {idx_1}))); } @@ -1186,8 +1186,8 @@ struct opts { node n = base_1; for(size_t i = 0; i < 20; ++i) { - size_t idx_1 = random::fast_uniform(0, 9); - size_t idx_2 = random::fast_uniform(0, 9); + size_t idx_1 = random::uniform(0, 9); + size_t idx_2 = random::uniform(0, 9); n = make_union(n, make_transform(make_project(base_1, {idx_1, idx_2}))); } diff --git a/test/sketches/hyperloglog_test.cxx b/test/sketches/hyperloglog_test.cxx index 2fca4af091..ac30fe6a6f 100644 --- a/test/sketches/hyperloglog_test.cxx +++ b/test/sketches/hyperloglog_test.cxx @@ -12,7 +12,7 @@ struct hyperloglog_test { turi::sketches::hyperloglog hll(hllbits); std::vector v(len); for (size_t i = 0;i < len; ++i) { - v[i] = turi::random::fast_uniform(0, random_range - 1); + v[i] = turi::random::uniform(0, random_range - 1); hll.add(v[i]); } std::sort(v.begin(), v.end()); @@ -39,7 +39,7 @@ struct hyperloglog_test { std::vector v(len); for (size_t i = 0;i < len; ++i) { - v[i] = turi::random::fast_uniform(0, random_range - 1); + v[i] = turi::random::uniform(0, random_range - 1); hllarr[i% 16].add(v[i]); sequential_hll.add(v[i]); } diff --git a/test/sketches/space_saving_test.cxx b/test/sketches/space_saving_test.cxx index aa3f570276..7d154d5610 100644 --- a/test/sketches/space_saving_test.cxx +++ b/test/sketches/space_saving_test.cxx @@ -25,7 +25,7 @@ struct space_saving_test { std::vector v(len); std::map true_counter; for (size_t i = 0;i < len; ++i) { - v[i] = turi::random::fast_uniform(0, random_range - 1); + v[i] = turi::random::uniform(0, random_range - 1); ++true_counter[v[i]]; } turi::timer ti; @@ -66,7 +66,7 @@ struct space_saving_test { std::vector v(len); std::unordered_map true_counter; for (size_t i = 0;i < len; ++i) { - v[i] = turi::random::fast_uniform(0, random_range - 1); + v[i] = turi::random::uniform(0, random_range - 1); ++true_counter[v[i]]; } turi::timer ti; diff --git a/test/unity/toolkits/feature_engineering/dict_flattening.cxx b/test/unity/toolkits/feature_engineering/dict_flattening.cxx index 83b2563e91..b12febd3d1 100644 --- a/test/unity/toolkits/feature_engineering/dict_flattening.cxx +++ b/test/unity/toolkits/feature_engineering/dict_flattening.cxx @@ -139,7 +139,7 @@ struct dictionary_flatting_test { flexible_type _add_nested_component(flex_dict& final_out, std::string key_root, size_t depth) { - size_t t = random::fast_uniform(0, 6); + size_t t = random::uniform(0, 6); if(depth < 1) { t = t % 4; @@ -148,29 +148,29 @@ struct dictionary_flatting_test { switch(t) { case 0: { // integer - flex_int n = random::fast_uniform(0, 100); + flex_int n = random::uniform(0, 100); final_out.push_back( {key_root, n}); return n; } case 1: { // float - flex_float n = random::fast_uniform(0, 1); + flex_float n = random::uniform(0, 1); final_out.push_back( {key_root, n}); return n; } case 2: { // string - flex_string n = std::to_string(random::fast_uniform(0, 1000)); + flex_string n = std::to_string(random::uniform(0, 1000)); final_out.push_back( {key_root + "." + n, 1}); return n; } case 3: { // vector - size_t length = random::fast_uniform(0, 10); + size_t length = random::uniform(0, 10); flex_vec v(length); for(size_t i = 0; i < length; ++i) { - v[i] = random::fast_uniform(0, 1); + v[i] = random::uniform(0, 1); final_out.push_back({key_root + "." + std::to_string(i), v[i]}); } @@ -179,7 +179,7 @@ struct dictionary_flatting_test { case 4: { // list - size_t length = random::fast_uniform(0, 10); + size_t length = random::uniform(0, 10); flex_list v(length); for(size_t i = 0; i < length; ++i) { @@ -191,12 +191,12 @@ struct dictionary_flatting_test { case 5: { // dict - size_t length = random::fast_uniform(0, 10); + size_t length = random::uniform(0, 10); flex_dict d(length); for(size_t i = 0; i < length; ++i) { flex_string s = "key-" + std::to_string(i) + "-" - + std::to_string(random::fast_uniform(0,1000)); + + std::to_string(random::uniform(0,1000)); d[i] = {s, _add_nested_component(final_out, key_root + "." + s, depth - 1)}; } @@ -220,7 +220,7 @@ struct dictionary_flatting_test { for(size_t i = 0; i < 20; ++i) { auto& p = d[i]; p.first = "a" + std::to_string(i) + "-" - + std::to_string(random::fast_uniform(0,1000000)); + + std::to_string(random::uniform(0,1000000)); p.second = _add_nested_component(true_out, p.first, depth); } @@ -247,7 +247,7 @@ struct dictionary_flatting_test { flex_dict d(10); for(auto& p : d) { - p.first = "a" + std::to_string(random::fast_uniform(0,1000000)); + p.first = "a" + std::to_string(random::uniform(0,1000000)); p.second = _add_nested_component(true_out, p.first, 3); } diff --git a/test/unity/toolkits/ml_data_2/basic_iteration.cxx b/test/unity/toolkits/ml_data_2/basic_iteration.cxx index c465600d46..edf4232492 100644 --- a/test/unity/toolkits/ml_data_2/basic_iteration.cxx +++ b/test/unity/toolkits/ml_data_2/basic_iteration.cxx @@ -417,8 +417,8 @@ struct ml_data_numeric_iteration_test { std::vector seen_value(n); - size_t row_start = random::fast_uniform(0, n-1); - size_t row_end = random::fast_uniform(0, n-1); + size_t row_start = random::uniform(0, n-1); + size_t row_end = random::uniform(0, n-1); if(row_start > row_end) { if(i % 2 == 0) @@ -529,8 +529,8 @@ struct ml_data_numeric_iteration_test { std::vector seen_value(n); - size_t row_start = random::fast_uniform(0, n-1); - size_t row_end = random::fast_uniform(0, n-1); + size_t row_start = random::uniform(0, n-1); + size_t row_end = random::uniform(0, n-1); if(row_start > row_end) { if(i % 2 == 0) diff --git a/test/unity/toolkits/ml_data_2/basic_storage.cxx b/test/unity/toolkits/ml_data_2/basic_storage.cxx index 2a0c300be0..ee0e5fcaa3 100644 --- a/test/unity/toolkits/ml_data_2/basic_storage.cxx +++ b/test/unity/toolkits/ml_data_2/basic_storage.cxx @@ -318,7 +318,7 @@ struct test_basic_storage { if(row_end > row_start) { auto it = sliced_data.get_iterator(); - size_t idx = random::fast_uniform(0, row_end - 1 - row_start); + size_t idx = random::uniform(0, row_end - 1 - row_start); it.seek(idx); ASSERT_EQ(it.row_index(), idx); diff --git a/test/unity/toolkits/ml_data_2/creation_methods.cxx b/test/unity/toolkits/ml_data_2/creation_methods.cxx index 07cf83dff8..4b96254a87 100644 --- a/test/unity/toolkits/ml_data_2/creation_methods.cxx +++ b/test/unity/toolkits/ml_data_2/creation_methods.cxx @@ -407,7 +407,7 @@ struct test_selection { for(size_t i = 0; i < 500; ++i) { - pull_indices.push_back(random::fast_uniform(0, 199)); + pull_indices.push_back(random::uniform(0, 199)); std::sort(pull_indices.begin(), pull_indices.end()); diff --git a/test/unity/toolkits/ml_data_2/side_features.cxx b/test/unity/toolkits/ml_data_2/side_features.cxx index beaf7a9f7b..b55d7e18b9 100644 --- a/test/unity/toolkits/ml_data_2/side_features.cxx +++ b/test/unity/toolkits/ml_data_2/side_features.cxx @@ -106,7 +106,7 @@ void test_consistency(const v2::ml_data& data, it.fill_observation(x); // Strip and replace the features associated with one of the columns - size_t idx = random::fast_uniform(0, data.metadata()->num_columns(false) - 1); + size_t idx = random::uniform(0, data.metadata()->num_columns(false) - 1); data.get_side_features()->strip_side_features_from_row(idx, x); data.get_side_features()->add_partial_side_features_to_row(x, idx); @@ -119,7 +119,7 @@ void test_consistency(const v2::ml_data& data, it.fill_observation(x_gi); // Strip and replace the features associated with one of the columns - size_t idx = random::fast_uniform(0, data.metadata()->num_columns(false) - 1); + size_t idx = random::uniform(0, data.metadata()->num_columns(false) - 1); data.get_side_features()->strip_side_features_from_row(idx, x_gi); data.get_side_features()->add_partial_side_features_to_row(x_gi, idx); diff --git a/test/unity/toolkits/recsys/algo_utils.cxx b/test/unity/toolkits/recsys/algo_utils.cxx index 0170050a0a..daf885bb92 100644 --- a/test/unity/toolkits/recsys/algo_utils.cxx +++ b/test/unity/toolkits/recsys/algo_utils.cxx @@ -122,10 +122,10 @@ struct recsys_algo_model_test { random::seed(0); for(size_t& v : v1) - v = random::fast_uniform(0, 1000); + v = random::uniform(0, 1000); for(size_t& v : v2) - v = random::fast_uniform(0, 1000); + v = random::uniform(0, 1000); std::sort(v1.begin(), v1.end()); std::sort(v2.begin(), v2.end()); diff --git a/test/unity/toolkits/recsys/itemcf.cxx b/test/unity/toolkits/recsys/itemcf.cxx index cd5843b567..b5134d453e 100644 --- a/test/unity/toolkits/recsys/itemcf.cxx +++ b/test/unity/toolkits/recsys/itemcf.cxx @@ -41,15 +41,15 @@ struct recsys_itemcf_test { std::vector counts(num_items, 0); do { - size_t user = random::fast_uniform(0, num_users - 1); - size_t item = random::fast_uniform(0, num_items - 1); + size_t user = random::uniform(0, num_users - 1); + size_t item = random::uniform(0, num_items - 1); double accept_prob = 1.0 - double(item) / num_items; - double r = random::fast_uniform(0.0, 1.0); + double r = random::uniform(0.0, 1.0); if(r < accept_prob) { - double rating = random::fast_uniform(1.0, 5.0); + double rating = random::uniform(1.0, 5.0); train_data.push_back( {std::to_string(user), std::to_string(item), rating} ); ++counts[item]; } diff --git a/test/unity/toolkits/recsys/itemcf_stress_test.cpp b/test/unity/toolkits/recsys/itemcf_stress_test.cpp index 9cbccf82ba..e4eb906e30 100644 --- a/test/unity/toolkits/recsys/itemcf_stress_test.cpp +++ b/test/unity/toolkits/recsys/itemcf_stress_test.cpp @@ -28,8 +28,8 @@ int main(int argc, char** argv) { auto tr_dist = [](size_t k) { - random::fast_uniform(0, k); - return random::fast_uniform(0, std::max(1, k)); + random::uniform(0, k); + return random::uniform(0, std::max(1, k)); }; size_t n_threads = thread::cpu_count(); diff --git a/test/unity/toolkits/recsys/new_user_tests.cxx b/test/unity/toolkits/recsys/new_user_tests.cxx index e513ceff57..c559a30c24 100644 --- a/test/unity/toolkits/recsys/new_user_tests.cxx +++ b/test/unity/toolkits/recsys/new_user_tests.cxx @@ -45,8 +45,8 @@ void run_test_new_users(const std::map& opts std::vector > data(n_obs); for(size_t i = 0; i < n_obs; ++i) { - size_t user = random::fast_uniform(0, n_users-1); - size_t item = random::fast_uniform(0, n_items-1); + size_t user = random::uniform(0, n_users-1); + size_t item = random::uniform(0, n_items-1); data[i] = {user, item, 1.0 / (1.0 + user + item)}; } diff --git a/test/unity/toolkits/recsys/popularity.cxx b/test/unity/toolkits/recsys/popularity.cxx index 32fc4c8b66..0d5e04564d 100644 --- a/test/unity/toolkits/recsys/popularity.cxx +++ b/test/unity/toolkits/recsys/popularity.cxx @@ -52,12 +52,12 @@ struct recsys_popularity_test { } do { - size_t user = random::fast_uniform(0, num_users - 1); - size_t item = random::fast_uniform(0, num_items - 1); + size_t user = random::uniform(0, num_users - 1); + size_t item = random::uniform(0, num_items - 1); double accept_prob = 1.0 - double(item) / num_items; - double r = random::fast_uniform(0.0, 1.0); + double r = random::uniform(0.0, 1.0); if(r < accept_prob) { train_data.push_back( {user, item} ); diff --git a/test/unity/toolkits/recsys/train_test_split.cxx b/test/unity/toolkits/recsys/train_test_split.cxx index ecf2877cde..2f758e5649 100644 --- a/test/unity/toolkits/recsys/train_test_split.cxx +++ b/test/unity/toolkits/recsys/train_test_split.cxx @@ -44,8 +44,8 @@ struct train_test_split { } do { - size_t user = random::fast_uniform(0, num_users - 1); - size_t item = random::fast_uniform(0, num_items - 1); + size_t user = random::uniform(0, num_users - 1); + size_t item = random::uniform(0, num_items - 1); train_data.push_back( {user, item} ); } while(train_data.size() < num_observations); diff --git a/test/unity/toolkits/recsys/weird_segments.cxx b/test/unity/toolkits/recsys/weird_segments.cxx index 34f4c3c87f..38bb112072 100644 --- a/test/unity/toolkits/recsys/weird_segments.cxx +++ b/test/unity/toolkits/recsys/weird_segments.cxx @@ -43,8 +43,8 @@ void run_test_weird_segments(const std::map& opts std::vector > data(n_obs); for(size_t i = 0; i < n_obs; ++i) { - size_t user = random::fast_uniform(0, n_users-1); - size_t item = random::fast_uniform(0, n_items-1); + size_t user = random::uniform(0, n_users-1); + size_t item = random::uniform(0, n_items-1); data[i] = {user, item, 1.0 / (1.0 + user + item)}; } diff --git a/test/unity/toolkits/search_test.cxx b/test/unity/toolkits/search_test.cxx index a491632652..3f8149852b 100644 --- a/test/unity/toolkits/search_test.cxx +++ b/test/unity/toolkits/search_test.cxx @@ -47,7 +47,7 @@ void run_search_test(size_t num_trials = 3, std::vector tokens = {}; for (size_t i = 0; i < num_trials; ++i) { - auto word_id = random::fast_uniform(0, vocab.size()-1); + auto word_id = random::uniform(0, vocab.size()-1); tokens.push_back(vocab[word_id]); } diff --git a/test/unity/toolkits/sparse_similarity/generate_sparse_data.hpp b/test/unity/toolkits/sparse_similarity/generate_sparse_data.hpp index 9f60043da3..281ade140e 100644 --- a/test/unity/toolkits/sparse_similarity/generate_sparse_data.hpp +++ b/test/unity/toolkits/sparse_similarity/generate_sparse_data.hpp @@ -19,9 +19,9 @@ static std::vector > > generate( data.resize(n); for(size_t i = 0; i < size_t(n * m * p); ++i) { - size_t row_idx = random::fast_uniform(0, n-1); - size_t col_idx = random::fast_uniform(0, m-1); - double value = random::fast_uniform(0, 1); + size_t row_idx = random::uniform(0, n-1); + size_t col_idx = random::uniform(0, m-1); + double value = random::uniform(0, 1); if(binary) { value = (value < 0.1) ? 0 : 1; diff --git a/test/unity/toolkits/sparse_similarity/test_brute_force_all_pairs.cxx b/test/unity/toolkits/sparse_similarity/test_brute_force_all_pairs.cxx index 53f095d526..7dd0b18920 100644 --- a/test/unity/toolkits/sparse_similarity/test_brute_force_all_pairs.cxx +++ b/test/unity/toolkits/sparse_similarity/test_brute_force_all_pairs.cxx @@ -219,7 +219,7 @@ void run_test(const std::vector > >& data_1, // Make sure it works with no entries at all. for(size_t i = 2; i < m; ++i) { - if(random::fast_uniform(0, 1) == 0) { + if(random::uniform(0, 1) == 0) { query_mask.set_bit(i); } } diff --git a/test/unity/toolkits/synthetic_timings/time_data_loading.cpp b/test/unity/toolkits/synthetic_timings/time_data_loading.cpp index d339e0921c..5e540499e8 100644 --- a/test/unity/toolkits/synthetic_timings/time_data_loading.cpp +++ b/test/unity/toolkits/synthetic_timings/time_data_loading.cpp @@ -39,8 +39,8 @@ int main(int argc, char **argv) { for(size_t i = 0; i < n_obs; ++i) { - users[i] = random::fast_uniform(0, n_users-1); - size_t item_1 = random::fast_uniform(0, n_items-1); + users[i] = random::uniform(0, n_users-1); + size_t item_1 = random::uniform(0, n_items-1); if(use_strings) items[i] = std::to_string(item_1) + "_" + std::to_string(size_t(hash64(item_1))); else diff --git a/test/unity/toolkits/test_evaluation.cxx b/test/unity/toolkits/test_evaluation.cxx index 52088b5c7b..6740ac0a3d 100644 --- a/test/unity/toolkits/test_evaluation.cxx +++ b/test/unity/toolkits/test_evaluation.cxx @@ -31,8 +31,8 @@ BOOST_AUTO_TEST_CASE(test_rmse_and_max_error) { double total = 0.0; double true_max_error = 0; for (size_t i = 0; i < num_observations; ++i) { - predictions[i] = random::fast_uniform(0, 1); - targets[i] = random::fast_uniform(0, 1); + predictions[i] = random::uniform(0, 1); + targets[i] = random::uniform(0, 1); double err = std::abs((double)predictions[i] - (double)targets[i]); total += std::pow(err, 2); true_max_error = std::max(true_max_error, err); @@ -70,8 +70,8 @@ BOOST_AUTO_TEST_CASE(test_roc_curve) { for (size_t i = 0; i < num_observations; ++i) { predictions[i] = float(i) / num_observations; - // random::fast_uniform(0, 1); - targets[i] = random::fast_uniform(0, 1); + // random::uniform(0, 1); + targets[i] = random::uniform(0, 1); if (targets[i] == 1) { if (predictions[i] == 1) { true_positive += 1; @@ -134,11 +134,11 @@ BOOST_AUTO_TEST_CASE(test_accuracy) { auto targets = std::vector(num_observations); for (size_t i = 0; i < num_observations; ++i) { - double prob = random::fast_uniform(0.0, 1.0); + double prob = random::uniform(0.0, 1.0); predictions[i] = prob > 0.5 ? 1 : 0; pred_vectors[i] = flex_vec({1.0 - prob, prob}); pred_dicts[i] = flex_dict({{0, 1.0 - prob}, {1, prob}}); - targets[i] = random::fast_uniform(0, 1); + targets[i] = random::uniform(0, 1); if (targets[i] == 1) { if (predictions[i] == 1) { true_positive += 1; diff --git a/test/unity/toolkits/topic_model.cxx b/test/unity/toolkits/topic_model.cxx index 8d704624b2..bb8e922bbf 100644 --- a/test/unity/toolkits/topic_model.cxx +++ b/test/unity/toolkits/topic_model.cxx @@ -76,8 +76,8 @@ struct topic_model_test { std::vector> elem(doc_length); for(size_t i = 0; i < num_documents; ++i) { for(size_t j = 0; j < doc_length; ++j) { - flexible_type word_id = random::fast_uniform(0, vocab_size); - size_t freq = random::fast_uniform(1, max_word_frequency); + flexible_type word_id = random::uniform(0, vocab_size); + size_t freq = random::uniform(1, max_word_frequency); elem[j] = std::make_pair((flex_string) word_id, freq); } /* std::cout << flexible_type(elem) << std::endl; */ diff --git a/test/util/time_fast_power.cpp b/test/util/time_fast_power.cpp index 75c962faae..0ca3c4ecf1 100644 --- a/test/util/time_fast_power.cpp +++ b/test/util/time_fast_power.cpp @@ -23,7 +23,7 @@ void _run_time_test(size_t max_value) { std::vector powers(n_iterations); for(size_t i = 0; i < n_iterations; ++i) - powers[i] = random::fast_uniform(0, max_value); + powers[i] = random::uniform(0, max_value); {