17 const bool make_symmetric,
20 const int cdf_size = cdf.size();
21 assert(cdf[0] == 0.0f && cdf[cdf_size - 1] == 1.0f);
23 const float inv_resolution = 1.0f / (
float)resolution;
24 const float range = to -
from;
25 inv_cdf.resize(resolution);
27 const int half_size = (resolution - 1) / 2;
28 for (
int i = 0; i <= half_size; i++) {
29 float x = i / (
float)half_size;
30 int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin();
32 if (index < cdf_size - 1) {
33 t = (x - cdf[index]) / (cdf[index + 1] - cdf[index]);
39 float y = ((index + t) / (resolution - 1)) * (2.0f * range);
40 inv_cdf[half_size + i] = 0.5f * (1.0f +
y);
41 inv_cdf[half_size - i] = 0.5f * (1.0f -
y);
45 for (
int i = 0; i < resolution; i++) {
46 float x = (i + 0.5f) * inv_resolution;
47 int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin() - 1;
49 if (index < cdf_size - 1) {
50 t = (x - cdf[index]) / (cdf[index + 1] - cdf[index]);
56 inv_cdf[i] = from + range * (index + t) * inv_resolution;
CCL_NAMESPACE_BEGIN void util_cdf_invert(const int resolution, const float from, const float to, const vector< float > &cdf, const bool make_symmetric, vector< float > &inv_cdf)