mod strategies;
mod validate;
pub use crate::spec::types::ComparatorKind;
pub use validate::validate_comparator_for_type;
pub trait Comparator: Send + Sync {
fn compare(&self, gpu: &[u8], cpu: &[u8]) -> Result<(), String>;
}
pub struct ExactMatch;
pub struct UnorderedMatch;
pub struct ApproximateMatch {
pub epsilon: u32,
}
pub struct SetEqualityMatch {
pub element_size: usize,
}
impl ComparatorKind {
#[inline]
pub fn compare(self, gpu: &[u8], cpu: &[u8]) -> Result<(), String> {
match self {
Self::ExactMatch => ExactMatch.compare(gpu, cpu),
Self::UnorderedMatch => UnorderedMatch.compare(gpu, cpu),
Self::Approximate { epsilon } => ApproximateMatch { epsilon }.compare(gpu, cpu),
Self::SetEquality { element_size } => {
SetEqualityMatch { element_size }.compare(gpu, cpu)
}
}
}
}
impl Comparator for ComparatorKind {
fn compare(&self, gpu: &[u8], cpu: &[u8]) -> Result<(), String> {
(*self).compare(gpu, cpu)
}
}
#[cfg(test)]
mod tests;