use std::sync::OnceLock;
use crate::evaluate::KernelKind;
#[must_use]
pub fn tp_threshold_for(kernel: KernelKind) -> f64 {
match kernel {
KernelKind::Bbox | KernelKind::Segm | KernelKind::Boundary | KernelKind::Keypoints => 0.5,
}
}
#[must_use]
pub fn default_tau_grid() -> &'static [f64] {
static GRID: OnceLock<Vec<f64>> = OnceLock::new();
GRID.get_or_init(|| (0..=100).map(|i| f64::from(i) / 100.0).collect())
.as_slice()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_tau_grid_is_101_points() {
let grid = default_tau_grid();
assert_eq!(grid.len(), 101);
assert!((grid[0]).abs() < 1e-12);
assert!((grid[100] - 1.0).abs() < 1e-12);
assert!((grid[50] - 0.5).abs() < 1e-12);
}
#[test]
fn tp_threshold_for_every_kernel_is_half() {
for kind in [
KernelKind::Bbox,
KernelKind::Segm,
KernelKind::Boundary,
KernelKind::Keypoints,
] {
assert!(
(tp_threshold_for(kind) - 0.5).abs() < 1e-12,
"kernel {kind:?}"
);
}
}
}