faer/sparse/linalg/
mod.rs1use crate::internal_prelude_sp::*;
2const CHOLESKY_SUPERNODAL_RATIO_FACTOR: f64 = 40.0;
3const QR_SUPERNODAL_RATIO_FACTOR: f64 = 40.0;
4const LU_SUPERNODAL_RATIO_FACTOR: f64 = 40.0;
5#[derive(Copy, Clone, Debug)]
7pub struct SymbolicSupernodalParams<'a> {
8 pub relax: Option<&'a [(usize, f64)]>,
18}
19const DEFAULT_RELAX: &'static [(usize, f64)] =
20 &[(4, 1.0), (16, 0.8), (48, 0.1), (usize::MAX, 0.05)];
21impl Default for SymbolicSupernodalParams<'_> {
22 #[inline]
23 fn default() -> Self {
24 Self {
25 relax: Some(DEFAULT_RELAX),
26 }
27 }
28}
29#[derive(Copy, Clone, Debug, PartialEq)]
37pub struct SupernodalThreshold(pub f64);
38impl Default for SupernodalThreshold {
39 #[inline]
40 fn default() -> Self {
41 Self(1.0)
42 }
43}
44impl SupernodalThreshold {
45 pub const AUTO: Self = Self(1.0);
47 pub const FORCE_SIMPLICIAL: Self = Self(f64::INFINITY);
49 pub const FORCE_SUPERNODAL: Self = Self(0.0);
51}
52#[derive(Copy, Clone, Debug)]
54pub enum LltError {
55 Numeric(linalg::cholesky::llt::factor::LltError),
57 Generic(FaerError),
59}
60impl core::fmt::Display for LltError {
61 #[inline]
62 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
63 core::fmt::Debug::fmt(self, f)
64 }
65}
66impl core::error::Error for LltError {}
67impl From<linalg::cholesky::llt::factor::LltError> for LltError {
68 fn from(value: linalg::cholesky::llt::factor::LltError) -> Self {
69 Self::Numeric(value)
70 }
71}
72#[derive(Copy, Clone, Debug)]
74pub enum LuError {
75 SymbolicSingular {
77 index: usize,
79 },
80 Generic(FaerError),
82}
83impl core::fmt::Display for LuError {
84 #[inline]
85 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
86 core::fmt::Debug::fmt(self, f)
87 }
88}
89impl core::error::Error for LuError {}
90impl<T: Into<FaerError>> From<T> for LltError {
91 fn from(value: T) -> Self {
92 Self::Generic(value.into())
93 }
94}
95impl<T: Into<FaerError>> From<T> for LuError {
96 fn from(value: T) -> Self {
97 Self::Generic(value.into())
98 }
99}
100pub mod amd;
101pub mod cholesky;
102pub mod colamd;
103pub mod lu;
104pub mod matmul;
106pub mod qr;
107#[path = "../solvers.rs"]
109pub mod solvers;
110pub mod triangular_solve;
112mod ghost {
113 use crate::Index;
114 pub use crate::utils::bound::*;
115 pub const NONE_BYTE: u8 = u8::MAX;
116 #[inline]
117 pub fn fill_zero<'n, 'a, I: Index>(
118 slice: &'a mut [I],
119 size: Dim<'n>,
120 ) -> &'a mut [Idx<'n, I>] {
121 let len = slice.len();
122 if len > 0 {
123 assert!(*size > 0);
124 }
125 unsafe {
126 core::ptr::write_bytes(slice.as_mut_ptr(), 0u8, len);
127 &mut *(slice as *mut _ as *mut _)
128 }
129 }
130 #[inline]
131 pub fn fill_none<'n, 'a, I: Index>(
132 slice: &'a mut [I::Signed],
133 size: Dim<'n>,
134 ) -> &'a mut [MaybeIdx<'n, I>] {
135 let _ = size;
136 let len = slice.len();
137 unsafe { core::ptr::write_bytes(slice.as_mut_ptr(), NONE_BYTE, len) };
138 unsafe { &mut *(slice as *mut _ as *mut _) }
139 }
140 #[inline]
141 pub fn copy_slice<'n, 'a, I: Index>(
142 dst: &'a mut [I],
143 src: &[Idx<'n, I>],
144 ) -> &'a mut [Idx<'n, I>] {
145 let dst: &mut [Idx<'_, I>] = unsafe { &mut *(dst as *mut _ as *mut _) };
146 dst.copy_from_slice(src);
147 dst
148 }
149}