svod-tensor 0.1.0-alpha.3

High-level lazy tensor API for the Svod ML compiler
Documentation
//! Test helpers for realize() validation.

use crate::{PrepareConfig, Tensor};

/// Convenience extension for tests: realize in-place and return `&Self` for chaining reads.
pub trait RealizeTestExt {
    fn realize_with_and(&mut self, config: &PrepareConfig) -> &Self;
}

impl RealizeTestExt for Tensor {
    /// Realize with explicit config, panic on error, return `&self` for reading.
    fn realize_with_and(&mut self, config: &PrepareConfig) -> &Self {
        self.realize_with(config).unwrap();
        self
    }
}

/// Setup function to call at the start of each test.
///
/// Buffer UOp IDs are globally unique (monotonic counter via `Op::Unique`),
/// so buffer entries never collide across parallel tests — no registry
/// clearing or mutex serialization needed.
///
/// The kernel name dedup counter is the only non-RAII global state that
/// needs reset between tests.
pub fn test_setup() {
    svod_runtime::kernel_cache::clear_all();
}

/// Compare float slices with tolerance.
#[track_caller]
pub fn assert_close_f32(actual: &[f32], expected: &[f32], tol: f32) {
    assert_eq!(actual.len(), expected.len(), "Length mismatch: {} != {}", actual.len(), expected.len());

    for (i, (a, e)) in actual.iter().zip(expected).enumerate() {
        assert!((a - e).abs() < tol, "Mismatch at index {}: {} != {} (diff: {})", i, a, e, (a - e).abs());
    }
}