Skip to main content

ruda_test_utils/correctness/
print_tensor.rs

1use crate::HostData;
2use crate::config::config;
3use crate::correctness::render::print_tensors as render;
4
5/// Pretty-print one or two tensors through the unified renderer.
6///
7/// Two tensors of the same shape are rendered as a colored diff (cells red
8/// when `|a - b| > epsilon`, green otherwise). One tensor renders without
9/// color. Tensors with different shapes (or rank) are silently skipped.
10///
11/// No-op when `[print] enabled = false` in `ruda-test.toml`.
12///
13/// # Examples
14///
15/// ```ignore
16/// use ruda_test_utils::print_tensors;
17///
18/// // Single tensor — just pretty-print, no color.
19/// print_tensors("input", &[&host], None);
20///
21/// // Two tensors of the same shape — colored diff. Same path is used by
22/// // `assert_equals_approx` for actual-vs-expected.
23/// print_tensors("a vs b", &[&a, &b], Some(1e-3));
24/// ```
25pub fn print_tensors(label: &str, tensors: &[&HostData], epsilon: Option<f32>) {
26    render(&config().print, label, tensors, epsilon);
27}
28
29/// Backwards-compatible single-tensor helper. Delegates to [`print_tensors`].
30pub fn print_tensor(label: &str, host: &HostData) {
31    print_tensors(label, &[host], None);
32}