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));
65template<std::
size_t num_dim_,
typename Float_ =
double>
66void initialize_random(Float_*
const Y,
const std::size_t num_points,
const unsigned long long seed = 42) {
68 std::mt19937_64 rng(seed);
71 std::size_t num_total = sanisizer::product_unsafe<std::size_t>(num_points, num_dim_);
72 const bool odd = num_total % 2;
78 for (std::size_t i = 0; i < num_total; i += 2) {
79 auto paired = aarand::standard_normal<Float_>(rng);
81 Y[i + 1] = paired.second;
86 auto paired = aarand::standard_normal<Float_>(rng);
87 Y[num_total] = paired.first;
104template<std::
size_t num_dim_,
typename Float_ =
double>
105std::vector<Float_>
initialize_random(
const std::size_t num_points,
const unsigned long long seed = 42) {
106 std::vector<Float_> Y(sanisizer::product<
typename std::vector<Float_>::size_type>(num_points, num_dim_));
123template<
typename Task_,
class Run_>
124void parallelize(
const int num_workers,
const Task_ num_tasks, Run_ run_task_range) {
125#ifndef QDTSNE_CUSTOM_PARALLEL
128 subpar::parallelize(num_workers, num_tasks, std::move(run_task_range));
130 QDTSNE_CUSTOM_PARALLEL(num_workers, num_tasks, run_task_range);
137template<
typename Input_>
138std::remove_cv_t<std::remove_reference_t<Input_> > I(
const Input_ x) {
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:124
Index_ perplexity_to_k(const double perplexity)
Definition utils.hpp:48
void initialize_random(Float_ *const Y, const std::size_t num_points, const unsigned long long seed=42)
Definition utils.hpp:66