HighMap library (C++)
Loading...
Searching...
No Matches
vectors.hpp
Go to the documentation of this file.
1
7#pragma once
8#include <algorithm>
9#include <random>
10#include <string>
11#include <vector>
12
13namespace hmap
14{
15
24std::vector<size_t> argsort(const std::vector<float> &v);
25
31float compute_median(std::vector<float> values);
32
42std::vector<size_t> find_sign_changes(const std::vector<float> &data);
43
58std::vector<float> generate_random_vector(size_t size,
59 float min_value,
60 float max_value,
61 uint32_t seed);
62
76std::vector<int> generate_random_vector(size_t size,
77 int min_value,
78 int max_value,
79 uint32_t seed);
80
96std::vector<int> generate_unique_random_vector(size_t size,
97 int min_value,
98 int max_value,
99 uint32_t seed);
100
109std::string make_histogram(const std::vector<float> &values,
110 int bin_count,
111 int hist_height);
112
124std::vector<float> moving_average(const std::vector<float> &input, int radius);
125
135template <typename T>
136void reindex_vector(std::vector<T> &v, std::vector<size_t> &idx)
137{
138 std::vector<T> v_new(v.size());
139 for (std::uint32_t k = 0; k < v.size(); k++)
140 v_new[k] = v[idx[k]];
141 v = v_new;
142}
143
154std::vector<float> remap(const std::vector<float> &data,
155 float new_min = 0.f,
156 float new_max = 1.f);
157
165template <typename T>
166void shuffle_vector(std::vector<T> &values, std::uint32_t seed)
167{
168 std::mt19937 rng(seed);
169 std::shuffle(values.begin(), values.end(), rng);
170}
171
180template <typename T>
181std::vector<T> shuffled_vector(const std::vector<T> &values, std::uint32_t seed)
182{
183 std::vector<T> result = values;
184 shuffle_vector(result, seed);
185 return result;
186}
187
197size_t upperbound_right(const std::vector<float> &v, float value);
198
207void vector_unique_values(std::vector<float> &v);
208
209} // namespace hmap
Definition algebra.hpp:23
std::vector< size_t > find_sign_changes(const std::vector< float > &data)
Returns indices where a sign change occurs in the input vector.
Definition vectors.cpp:48
std::vector< T > shuffled_vector(const std::vector< T > &values, std::uint32_t seed)
Returns a shuffled copy of a vector.
Definition vectors.hpp:181
size_t upperbound_right(const std::vector< float > &v, float value)
Returns the index of the first element greater than a given value.
Definition vectors.cpp:236
void remap(Array &array, float vmin, float vmax, float from_min, float from_max)
Remap array elements from a starting range to a target range.
Definition range.cpp:363
std::vector< float > moving_average(const std::vector< float > &input, int radius)
Smooths a vector using a centered moving average.
Definition vectors.cpp:210
std::string make_histogram(const std::vector< float > &values, int bin_count, int hist_height)
Generates an ASCII histogram representation of values.
Definition vectors.cpp:144
std::vector< float > generate_random_vector(size_t size, float min_value, float max_value, uint32_t seed)
Generate a vector of random floating-point values within a given range.
Definition vectors.cpp:77
std::vector< size_t > argsort(const std::vector< float > &v)
Returns the indices that would sort the vector.
Definition vectors.cpp:17
std::vector< int > generate_unique_random_vector(size_t size, int min_value, int max_value, uint32_t seed)
Generate a vector of unique random integers within a given range.
Definition vectors.cpp:113
float compute_median(std::vector< float > values)
Computes the median value of a set of floats.
Definition vectors.cpp:28
void vector_unique_values(std::vector< float > &v)
Removes duplicate values from a vector.
Definition vectors.cpp:280
void reindex_vector(std::vector< T > &v, std::vector< size_t > &idx)
Reorders a vector using a given index mapping.
Definition vectors.hpp:136
void shuffle_vector(std::vector< T > &values, std::uint32_t seed)
Shuffles a vector in-place using a deterministic seed.
Definition vectors.hpp:166