vyre 0.4.0

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

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


/// Extract all overlapping byte n-grams.
///
/// # Errors
///
/// Returns `Fix: ...` when input or `n` exceeds the documented cap, or when
/// `n == 0`.
pub fn ngram_extract(input: &[u8], n: u32) -> Result<Vec<Vec<u8>>, SimilarityError> {
    validate_input("input", input)?;
    let n = validate_ngram_len(n)?;
    if n > input.len() {
        return Ok(Vec::new());
    }
    Ok(input.windows(n).map(<[u8]>::to_vec).collect())
}

// Backend-specific lowering marker.

// WGSL lowering source for `string_similarity.ngram_extract`.

/// Fixed-width n-gram extraction kernel used by GPU parity tests and intrinsic dispatch.
pub const WGSL: &str = concat!(
    include_str!("../wgsl/common_params.wgsl"),
    "\n",
    include_str!("wgsl/ngram_extract.wgsl"),
);