MCPcopy Create free account
hub / github.com/evilsocket/cake / assert_close

Function assert_close

cake-core/tests/unit_tests/test_backends.rs:164–175  ·  view source on GitHub ↗
(cpu: &Tensor, metal: &Tensor, tol: f32, label: &str)

Source from the content-addressed store, hash-verified

162
163#[cfg(feature = "metal")]
164fn assert_close(cpu: &Tensor, metal: &Tensor, tol: f32, label: &str) {
165 let cpu_vals: Vec<f32> = cpu.to_dtype(DType::F32).unwrap().flatten_all().unwrap().to_vec1().unwrap();
166 let metal_vals: Vec<f32> = metal.to_device(&Device::Cpu).unwrap().to_dtype(DType::F32).unwrap().flatten_all().unwrap().to_vec1().unwrap();
167 assert_eq!(cpu_vals.len(), metal_vals.len(), "{label}: length mismatch");
168 for (i, (c, m)) in cpu_vals.iter().zip(metal_vals.iter()).enumerate() {
169 assert!(
170 (c - m).abs() < tol,
171 "{label}[{i}]: cpu={c} metal={m} diff={}",
172 (c - m).abs()
173 );
174 }
175}
176
177#[cfg(feature = "metal")]
178#[test]

Calls

no outgoing calls

Tested by

no test coverage detected