MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / upper_bound_index

Function upper_bound_index

tools/bloom-reference/src/main.rs:1484–1501  ·  view source on GitHub ↗

Inverse-CDF inversion: returns the largest index i such that `cdf[i] <= u`. Used for both marginal and conditional sampling.

(cdf: &[f32], u: f32)

Source from the content-addressed store, hash-verified

1482/// Inverse-CDF inversion: returns the largest index i such that
1483/// `cdf[i] <= u`. Used for both marginal and conditional sampling.
1484fn upper_bound_index(cdf: &[f32], u: f32) -> usize {
1485 // Binary search for the last index whose CDF value is <= u.
1486 let mut lo = 0usize;
1487 let mut hi = cdf.len();
1488 while lo < hi {
1489 let mid = (lo + hi) / 2;
1490 if cdf[mid] <= u {
1491 lo = mid + 1;
1492 } else {
1493 hi = mid;
1494 }
1495 }
1496 if lo == 0 {
1497 0
1498 } else {
1499 lo - 1
1500 }
1501}
1502
1503impl Environment {
1504 fn load_hdr(path: &Path, intensity: f32) -> Result<Self, String> {

Callers 1

sample_pixelMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected