vyre 0.4.0

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

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


/// Compute the byte-wise longest common subsequence length.
///
/// # Errors
///
/// Returns `Fix: ...` when input sizes exceed caps or the DP cell cap.
pub fn lcs_length(a: &[u8], b: &[u8]) -> Result<u32, SimilarityError> {
    validate_pair(a, b)?;
    validate_dp_product(a.len(), b.len())?;
    let mut previous = vec![0usize; b.len() + 1];
    let mut current = vec![0usize; b.len() + 1];
    for &left in a {
        for (j, &right) in b.iter().enumerate() {
            current[j + 1] = if left == right {
                previous[j] + 1
            } else {
                previous[j + 1].max(current[j])
            };
        }
        std::mem::swap(&mut previous, &mut current);
        current.fill(0);
    }
    to_u32(previous[b.len()], "lcs length")
}

// Backend-specific lowering marker.

// WGSL lowering unavailable for `string_similarity.lcs_length`.
//
// Exact CPU parity requires caller-provided dynamic-programming rows whose
// size depends on `len(a) * len(b)`, 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 DP scratch buffers.