Skip to main content

diffsol_la/context/
faer.rs

1use faer::Par;
2
3/// Context for the faer backend.
4#[derive(Copy, Clone, Debug, PartialEq)]
5pub struct FaerContext {
6    pub par: Par,
7    nbatch: usize,
8}
9
10impl FaerContext {
11    pub fn new() -> Self {
12        Self {
13            par: Par::Seq,
14            nbatch: 1,
15        }
16    }
17
18    pub fn with_nbatch(nbatch: usize) -> Self {
19        assert!(nbatch > 0, "nbatch must be > 0");
20        Self {
21            par: Par::Seq,
22            nbatch,
23        }
24    }
25}
26
27impl Default for FaerContext {
28    fn default() -> Self {
29        Self::new()
30    }
31}
32
33impl crate::Context for FaerContext {
34    fn nbatch(&self) -> usize {
35        self.nbatch
36    }
37
38    fn clone_with_nbatch(&self, nbatch: usize) -> Result<Self, crate::LaError> {
39        assert!(nbatch > 0, "nbatch must be > 0");
40        Ok(Self {
41            par: self.par,
42            nbatch,
43        })
44    }
45}