1#ifndef QDTSNE_UTILS_HPP
2#define QDTSNE_UTILS_HPP
16#include "aarand/aarand.hpp"
18#include "sanisizer/sanisizer.hpp"
20#ifndef QDTSNE_CUSTOM_PARALLEL
36template<
typename Index_,
typename Float_>
47template<
typename Index_ =
int>
49 return sanisizer::from_float<Index_>(std::ceil(perplexity * 3));
70template<std::
size_t num_dim_,
typename Float_ =
double>
71void initialize_random(Float_*
const Y,
const std::size_t num_points,
const typename RngEngine::result_type seed = 42) {
75 std::size_t num_total = sanisizer::product_unsafe<std::size_t>(num_points, num_dim_);
76 const bool odd = num_total % 2;
82 for (std::size_t i = 0; i < num_total; i += 2) {
83 const auto paired = aarand::standard_normal<Float_>(rng);
85 Y[i + 1] = paired.second;
90 const auto paired = aarand::standard_normal<Float_>(rng);
91 Y[num_total] = paired.first;
108template<std::
size_t num_dim_,
typename Float_ =
double>
109std::vector<Float_>
initialize_random(
const std::size_t num_points,
const typename RngEngine::result_type seed = 42) {
110 std::vector<Float_> Y(sanisizer::product<
typename std::vector<Float_>::size_type>(num_points, num_dim_));
127template<
typename Task_,
class Run_>
128void parallelize(
const int num_workers,
const Task_ num_tasks, Run_ run_task_range) {
129#ifndef QDTSNE_CUSTOM_PARALLEL
132 subpar::parallelize(num_workers, num_tasks, std::move(run_task_range));
134 QDTSNE_CUSTOM_PARALLEL(num_workers, num_tasks, run_task_range);
141template<
typename Input_>
142using I =
typename std::remove_cv<typename std::remove_reference<Input_>::type>::type;
std::vector< std::vector< std::pair< Index_, Distance_ > > > NeighborList
knncolle::NeighborList< Index_, Float_ > NeighborList
Lists of neighbors for each observation.
Definition utils.hpp:37
void parallelize(const int num_workers, const Task_ num_tasks, Run_ run_task_range)
Definition utils.hpp:128
std::mt19937_64 RngEngine
Definition utils.hpp:55
Index_ perplexity_to_k(const double perplexity)
Definition utils.hpp:48
void initialize_random(Float_ *const Y, const std::size_t num_points, const typename RngEngine::result_type seed=42)
Definition utils.hpp:71