Skip to main content

runmat_analysis_fea/solve/backend/
cpu_reference.rs

1use super::linear_algebra::LinearAlgebraBackend;
2
3#[derive(Debug, Clone, Copy, Default)]
4pub struct CpuReferenceBackend;
5
6impl LinearAlgebraBackend for CpuReferenceBackend {
7    fn dot(&self, a: &[f64], b: &[f64]) -> f64 {
8        a.iter().zip(b.iter()).map(|(x, y)| x * y).sum()
9    }
10
11    fn axpy(&self, alpha: f64, x: &[f64], y: &mut [f64]) {
12        for (yi, xi) in y.iter_mut().zip(x.iter()) {
13            *yi += alpha * xi;
14        }
15    }
16
17    fn vec_sub(&self, a: &[f64], b: &[f64]) -> Vec<f64> {
18        a.iter().zip(b.iter()).map(|(x, y)| x - y).collect()
19    }
20}