Function burn::tensor::check_closeness
pub fn check_closeness<B, const D: usize>(
output: &Tensor<B, D>,
expected: &Tensor<B, D>,
)where
B: Backend,
Expand description
Checks the closeness of two tensors and prints the results.
Compares tensors by checking the absolute difference between each element. Prints the percentage of elements within specified tolerances.
§Arguments
output
- The output tensor.expected
- The expected tensor.
§Example
use burn_tensor::backend::Backend;
use burn_tensor::{check_closeness, Tensor};
fn example<B: Backend>() {
let device = Default::default();
let tensor1 = Tensor::<B, 1>::from_floats(
[1.0, 2.0, 3.0, 4.0, 5.0, 6.001, 7.002, 8.003, 9.004, 10.1],
&device,
);
let tensor2 = Tensor::<B, 1>::from_floats(
[1.0, 2.0, 3.0, 4.000, 5.0, 6.0, 7.001, 8.002, 9.003, 10.004],
&device,
);
check_closeness(&tensor1, &tensor2);
}
§Output
Tensor Closeness Check Results:
===============================
Epsilon: 1e-1
Close elements: 10/10 (100.00%)
[PASS] All elements are within tolerance
Epsilon: 1e-2
Close elements: 10/10 (100.00%)
[PASS] All elements are within tolerance
Epsilon: 1e-3
Close elements: 9/10 (90.00%)
[WARN] Most elements are within tolerance
Epsilon: 1e-4
Close elements: 6/10 (60.00%)
[FAIL] Significant differences detected
Epsilon: 1e-5
Close elements: 5/10 (50.00%)
[FAIL] Significant differences detected
Epsilon: 1e-6
Close elements: 5/10 (50.00%)
[FAIL] Significant differences detected
Epsilon: 1e-7
Close elements: 5/10 (50.00%)
[FAIL] Significant differences detected
Epsilon: 1e-8
Close elements: 5/10 (50.00%)
[FAIL] Significant differences detected
Closeness check complete.