18 const bool make_symmetric,
21 const int cdf_size = cdf.size();
22 assert(cdf[0] == 0.0f && cdf[cdf_size - 1] == 1.0f);
24 const float inv_resolution = 1.0f / (
float)resolution;
25 const float range = to - from;
26 inv_cdf.resize(resolution);
28 const int half_size = (resolution - 1) / 2;
29 for (
int i = 0;
i <= half_size;
i++) {
30 const float x =
i / (
float)half_size;
31 int index = upper_bound(cdf.begin(), cdf.end(),
x) - cdf.begin();
33 if (index < cdf_size - 1) {
34 t = (
x - cdf[index]) / (cdf[index + 1] - cdf[index]);
40 const float y = ((index + t) / (resolution - 1)) * (2.0f * range);
41 inv_cdf[half_size +
i] = 0.5f * (1.0f +
y);
42 inv_cdf[half_size -
i] = 0.5f * (1.0f -
y);
46 for (
int i = 0;
i < resolution;
i++) {
47 const float x = (
i + 0.5f) * inv_resolution;
48 int index = upper_bound(cdf.begin(), cdf.end(),
x) - cdf.begin() - 1;
50 if (index < cdf_size - 1) {
51 t = (
x - cdf[index]) / (cdf[index + 1] - cdf[index]);
57 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)