vyre 0.4.0

GPU compute intermediate representation with a standard operation library
Documentation
use crate::ops::string_similarity::jaro::jaro_unchecked;
use crate::ops::string_similarity::validation::{validate_pair, SimilarityError};

// CPU reference kernel for `string_similarity.jaro_winkler`.



pub const PREFIX_LIMIT: usize = 4;

pub const PREFIX_SCALE: f32 = 0.1;

/// Compute byte-wise Jaro-Winkler similarity in `[0.0, 1.0]`.
///
/// # Errors
///
/// Returns `Fix: ...` when either input exceeds the documented cap.
pub fn jaro_winkler(a: &[u8], b: &[u8]) -> Result<f32, SimilarityError> {
    validate_pair(a, b)?;
    let jaro = jaro_unchecked(a, b);
    let prefix = a
        .iter()
        .zip(b)
        .take(PREFIX_LIMIT)
        .take_while(|(left, right)| left == right)
        .count() as f32;
    Ok(jaro + prefix * PREFIX_SCALE * (1.0 - jaro))
}

/// Compute Jaro-Winkler similarity and return IEEE-754 binary32 bits.
///
/// # Errors
///
/// Returns `Fix: ...` when either input exceeds the documented cap.
pub fn jaro_winkler_bits(a: &[u8], b: &[u8]) -> Result<u32, SimilarityError> {
    Ok(jaro_winkler(a, b)?.to_bits())
}

// Backend-specific lowering marker.

// WGSL lowering unavailable for `string_similarity.jaro_winkler`.
//
// Exact CPU parity inherits Jaro's match-flag scratch requirement before the
// Winkler prefix adjustment, but the current intrinsic ABI exposes only
// `Bytes, Bytes -> U32` and no scratch arena. Fix: keep this op CPU-only until
// the spec defines bounded match-flag scratch buffers.