HighMap library (C++)
Loading...
Searching...
No Matches
vector_utils.hpp
Go to the documentation of this file.
1/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
15#pragma once
16#include <algorithm>
17#include <random>
18#include <string>
19#include <vector>
20
21typedef unsigned int uint;
22
23namespace hmap
24{
25
26// TODO clean up
27
28size_t upperbound_right(const std::vector<float> &v, float value);
29
30std::vector<size_t> argsort(const std::vector<float> &v);
31
32template <typename T>
33void reindex_vector(std::vector<T> &v, std::vector<size_t> &idx)
34{
35 std::vector<T> v_new(v.size());
36 for (uint k = 0; k < v.size(); k++)
37 v_new[k] = v[idx[k]];
38 v = v_new;
39}
40
41template <typename T>
42void shuffle_vector(std::vector<T> &values, std::uint32_t seed)
43{
44 std::mt19937 rng(seed);
45 std::shuffle(values.begin(), values.end(), rng);
46}
47
48template <typename T>
49std::vector<T> shuffled_vector(const std::vector<T> &values, std::uint32_t seed)
50{
51 std::vector<T> result = values;
52 shuffle_vector(result, seed);
53 return result;
54}
55
56void vector_unique_values(std::vector<float> &v);
57
58std::string make_histogram(const std::vector<float> &values,
59 int bin_count,
60 int hist_height);
61
62} // namespace hmap
unsigned int uint
Definition array.hpp:14
Definition algebra.hpp:22
std::vector< T > shuffled_vector(const std::vector< T > &values, std::uint32_t seed)
Definition vector_utils.hpp:49
size_t upperbound_right(const std::vector< float > &v, float value)
Definition vector_utils.cpp:95
std::string make_histogram(const std::vector< float > &values, int bin_count, int hist_height)
Definition vector_utils.cpp:29
std::vector< size_t > argsort(const std::vector< float > &v)
Definition vector_utils.cpp:18
void vector_unique_values(std::vector< float > &v)
Definition vector_utils.cpp:110
void reindex_vector(std::vector< T > &v, std::vector< size_t > &idx)
Definition vector_utils.hpp:33
void shuffle_vector(std::vector< T > &values, std::uint32_t seed)
Definition vector_utils.hpp:42
unsigned int uint
Definition vector_utils.hpp:21