tenferro_linalg/result_types/
status.rs

1use super::*;
2
3/// Structured Cholesky result with numerical status information.
4///
5/// `info` contains one entry per batch matrix. Zero means success.
6///
7/// # Examples
8///
9/// ```
10/// use tenferro_linalg::cholesky_ex;
11/// use tenferro_prims::CpuContext;
12/// use tenferro_tensor::{MemoryOrder, Tensor};
13///
14/// let mut ctx = CpuContext::new(1);
15/// let a = Tensor::from_slice(&[4.0_f64, 2.0, 2.0, 3.0], &[2, 2], MemoryOrder::ColumnMajor)
16///     .unwrap();
17/// let result = cholesky_ex(&mut ctx, &a).unwrap();
18/// assert_eq!(result.info.len(), 1);
19/// ```
20#[derive(Debug)]
21pub struct CholeskyExResult<T: Scalar> {
22    /// Lower-triangular Cholesky factor.
23    pub l: Tensor<T>,
24    /// Per-batch numerical status tensor.
25    pub info: Tensor<i32>,
26}
27
28/// Structured inverse result with numerical status information.
29///
30/// # Examples
31///
32/// ```
33/// use tenferro_linalg::inv_ex;
34/// use tenferro_prims::CpuContext;
35/// use tenferro_tensor::{MemoryOrder, Tensor};
36///
37/// let mut ctx = CpuContext::new(1);
38/// let a = Tensor::from_slice(&[1.0_f64, 0.0, 0.0, 1.0], &[2, 2], MemoryOrder::ColumnMajor)
39///     .unwrap();
40/// let result = inv_ex(&mut ctx, &a).unwrap();
41/// assert_eq!(result.info.len(), 1);
42/// ```
43#[derive(Debug)]
44pub struct InvExResult<T: Scalar> {
45    /// Inverse matrix.
46    pub inverse: Tensor<T>,
47    /// Per-batch numerical status tensor.
48    pub info: Tensor<i32>,
49}
50
51/// Structured solve result with numerical status information.
52///
53/// # Examples
54///
55/// ```
56/// use tenferro_linalg::solve_ex;
57/// use tenferro_prims::CpuContext;
58/// use tenferro_tensor::{MemoryOrder, Tensor};
59///
60/// let mut ctx = CpuContext::new(1);
61/// let a = Tensor::from_slice(&[1.0_f64, 0.0, 0.0, 1.0], &[2, 2], MemoryOrder::ColumnMajor)
62///     .unwrap();
63/// let b = Tensor::from_slice(&[2.0_f64, -1.0], &[2], MemoryOrder::ColumnMajor).unwrap();
64/// let result = solve_ex(&mut ctx, &a, &b).unwrap();
65/// assert_eq!(result.info.len(), 1);
66/// ```
67#[derive(Debug)]
68pub struct SolveExResult<T: Scalar> {
69    /// Solution tensor.
70    pub solution: Tensor<T>,
71    /// Per-batch numerical status tensor.
72    pub info: Tensor<i32>,
73}
74
75/// Packed LU factorization result.
76///
77/// # Examples
78///
79/// ```
80/// use tenferro_linalg::lu_factor;
81/// use tenferro_prims::CpuContext;
82/// use tenferro_tensor::{MemoryOrder, Tensor};
83///
84/// let mut ctx = CpuContext::new(1);
85/// let a = Tensor::from_slice(&[2.0_f64, 1.0, 1.0, 3.0], &[2, 2], MemoryOrder::ColumnMajor)
86///     .unwrap();
87/// let result = lu_factor(&mut ctx, &a).unwrap();
88/// assert_eq!(result.pivots.len(), 2);
89/// ```
90#[derive(Debug)]
91pub struct LuFactorResult<T: Scalar> {
92    /// Packed LU factors with the same shape as the input.
93    pub factors: Tensor<T>,
94    /// Backend pivot tensor in 1-indexed step-pivot form.
95    pub pivots: Tensor<i32>,
96}
97
98/// Packed LU factorization result with numerical status information.
99///
100/// # Examples
101///
102/// ```
103/// use tenferro_linalg::lu_factor_ex;
104/// use tenferro_prims::CpuContext;
105/// use tenferro_tensor::{MemoryOrder, Tensor};
106///
107/// let mut ctx = CpuContext::new(1);
108/// let a = Tensor::from_slice(&[2.0_f64, 1.0, 1.0, 3.0], &[2, 2], MemoryOrder::ColumnMajor)
109///     .unwrap();
110/// let result = lu_factor_ex(&mut ctx, &a).unwrap();
111/// assert_eq!(result.info.len(), 1);
112/// ```
113#[derive(Debug)]
114pub struct LuFactorExResult<T: Scalar> {
115    /// Packed LU factors with the same shape as the input.
116    pub factors: Tensor<T>,
117    /// Backend pivot tensor in 1-indexed step-pivot form.
118    pub pivots: Tensor<i32>,
119    /// Per-batch numerical status tensor.
120    pub info: Tensor<i32>,
121}
122
123/// Sign-and-log-determinant result: `det(A) = sign * exp(logabsdet)`.
124///
125/// # Examples
126///
127/// ```
128/// use tenferro_device::LogicalMemorySpace;
129/// use tenferro_linalg::slogdet;
130/// use tenferro_prims::CpuContext;
131/// use tenferro_tensor::{MemoryOrder, Tensor};
132///
133/// let mut ctx = CpuContext::new(1);
134/// let a = Tensor::<f64>::zeros(
135///     &[3, 3],
136///     LogicalMemorySpace::MainMemory,
137///     MemoryOrder::ColumnMajor,
138/// ).unwrap();
139/// let result = slogdet(&mut ctx, &a).unwrap();
140/// assert_eq!(result.sign.ndim(), 0);
141/// ```
142#[derive(Debug)]
143pub struct SlogdetResult<T: Scalar, R: Scalar = T> {
144    /// Sign of the determinant.
145    pub sign: Tensor<T>,
146    /// Log of the absolute determinant.
147    pub logabsdet: Tensor<R>,
148}