(cpu: &Tensor, metal: &Tensor, tol: f32, label: &str)
| 162 | |
| 163 | #[cfg(feature = "metal")] |
| 164 | fn 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] |
no outgoing calls
no test coverage detected