Skip to main content

broadcast_error_to_validation

Function broadcast_error_to_validation 

Source
pub fn broadcast_error_to_validation(error: BroadcastError) -> ValidationError
Expand description

Convert a broadcast-planning failure to the shared validation vocabulary.

Every eager, traced, and direct broadcast surface uses this mapping so the same invalid shapes have the same machine-readable payload regardless of where the check is discovered.

ยงExamples

use tenferro_ops::broadcast::{broadcast_error_to_validation, BroadcastError};
use tenferro_tensor::{ShapeMismatch, ValidationError};

let error = broadcast_error_to_validation(BroadcastError::IncompatibleInput {
    input: vec![2, 3],
    output: vec![2, 4],
});
assert!(matches!(
    error,
    ValidationError::ShapeMismatch(source)
        if matches!(source.as_ref(), ShapeMismatch::ExpectedActual { expected, actual }
            if expected.as_slice() == [2, 4] && actual.as_slice() == [2, 3])
));