Skip to main content

tensor4all_core/matrixluci/
scalar.rs

1//! Scalar capability for MatrixLUCI implementations.
2
3use num_complex::{Complex32, Complex64};
4
5use crate::error::Result;
6use crate::matrix_luci::MatrixLuciFactors;
7use crate::matrixlu::RrLUOptions;
8use tensor4all_tensorbackend::{
9    BackendLinalgScalar, Matrix, MatrixSolveScalar, MatrixTriangularSolveScalar,
10};
11
12/// Scalar types supported by MatrixLUCI factorization.
13///
14/// Common arithmetic comes from [`crate::Scalar`]; this trait adds only the
15/// backend solve capabilities and MatrixLUCI dispatch used by the factorizer.
16pub trait MatrixLuciScalar:
17    crate::Scalar + BackendLinalgScalar + MatrixSolveScalar + MatrixTriangularSolveScalar
18{
19    #[doc(hidden)]
20    fn matrix_luci_factors_from_matrix(
21        a: &Matrix<Self>,
22        options: RrLUOptions,
23    ) -> Result<MatrixLuciFactors<Self>>
24    where
25        Self: Sized;
26
27    #[doc(hidden)]
28    fn matrix_luci_factors_from_blocks<F>(
29        nrows: usize,
30        ncols: usize,
31        fill_block: F,
32        options: RrLUOptions,
33    ) -> Result<MatrixLuciFactors<Self>>
34    where
35        F: Fn(&[usize], &[usize], &mut [Self]),
36        Self: Sized;
37}
38
39macro_rules! impl_matrix_luci_scalar {
40    ($($ty:ty),* $(,)?) => {
41        $(
42            impl MatrixLuciScalar for $ty {
43                fn matrix_luci_factors_from_matrix(
44                    a: &Matrix<Self>,
45                    options: RrLUOptions,
46                ) -> Result<MatrixLuciFactors<Self>> {
47                    crate::matrix_luci::dense_matrix_luci_factors_from_matrix(a, options)
48                }
49
50                fn matrix_luci_factors_from_blocks<F>(
51                    nrows: usize,
52                    ncols: usize,
53                    fill_block: F,
54                    options: RrLUOptions,
55                ) -> Result<MatrixLuciFactors<Self>>
56                where
57                    F: Fn(&[usize], &[usize], &mut [Self]),
58                {
59                    crate::matrix_luci::lazy_matrix_luci_factors_from_blocks(
60                        nrows, ncols, fill_block, options,
61                    )
62                }
63            }
64        )*
65    };
66}
67
68impl_matrix_luci_scalar!(f64, f32, Complex64, Complex32);
69
70#[cfg(test)]
71mod tests;