tensor4all_core/matrixluci/
scalar.rs1use num_complex::{Complex32, Complex64};
4
5use crate::error::Result;
6use crate::matrix_luci::MatrixLuciFactors;
7use crate::matrixlu::RrLUOptions;
8use tensor4all_tensorbackend::{
9 explicit::Session, BackendLinalgError, BackendLinalgScalar, Matrix, MatrixSolveScalar,
10 MatrixTriangularSolveScalar,
11};
12
13pub trait MatrixLuciScalar:
18 crate::Scalar + BackendLinalgScalar + MatrixSolveScalar + MatrixTriangularSolveScalar
19{
20 #[doc(hidden)]
21 fn matrix_luci_factors_from_matrix(
22 a: &Matrix<Self>,
23 options: RrLUOptions,
24 ) -> Result<MatrixLuciFactors<Self>>
25 where
26 Self: Sized;
27
28 #[doc(hidden)]
29 fn matrix_luci_factors_from_blocks<F>(
30 nrows: usize,
31 ncols: usize,
32 fill_block: F,
33 options: RrLUOptions,
34 ) -> Result<MatrixLuciFactors<Self>>
35 where
36 F: Fn(&[usize], &[usize], &mut [Self]),
37 Self: Sized;
38
39 #[doc(hidden)]
41 fn matrix_luci_triangular_solve_in(
42 session: &mut Session<'_>,
43 a: &Matrix<Self>,
44 b: &Matrix<Self>,
45 left_side: bool,
46 lower: bool,
47 ) -> std::result::Result<Matrix<Self>, BackendLinalgError>
48 where
49 Self: Sized;
50}
51
52macro_rules! impl_matrix_luci_scalar {
53 ($($ty:ty),* $(,)?) => {
54 $(
55 impl MatrixLuciScalar for $ty {
56 fn matrix_luci_factors_from_matrix(
57 a: &Matrix<Self>,
58 options: RrLUOptions,
59 ) -> Result<MatrixLuciFactors<Self>> {
60 crate::matrix_luci::dense_matrix_luci_factors_from_matrix(a, options)
61 }
62
63 fn matrix_luci_factors_from_blocks<F>(
64 nrows: usize,
65 ncols: usize,
66 fill_block: F,
67 options: RrLUOptions,
68 ) -> Result<MatrixLuciFactors<Self>>
69 where
70 F: Fn(&[usize], &[usize], &mut [Self]),
71 {
72 crate::matrix_luci::lazy_matrix_luci_factors_from_blocks(
73 nrows, ncols, fill_block, options,
74 )
75 }
76
77 fn matrix_luci_triangular_solve_in(
78 session: &mut Session<'_>,
79 a: &Matrix<Self>,
80 b: &Matrix<Self>,
81 left_side: bool,
82 lower: bool,
83 ) -> std::result::Result<Matrix<Self>, BackendLinalgError> {
84 session.triangular_solve_matrix(a, b, left_side, lower, false, false)
85 }
86 }
87 )*
88 };
89}
90
91impl_matrix_luci_scalar!(f64, f32, Complex64, Complex32);
92
93#[cfg(test)]
94mod tests;