1#ifndef FUSED_ALGORITHMS_LU_H
2#define FUSED_ALGORITHMS_LU_H
66 template <
typename T, my_
size_t N>
88 result(i, j) =
LU(i, j);
108 result(i, j) =
LU(i, j);
150 template <
typename T, my_
size_t N>
155 static_assert(is_floating_point_v<T>,
156 "lu requires a floating-point scalar type");
191 T tmp = result.
LU(j, k);
192 result.
LU(j, k) = result.
LU(pivot, k);
193 result.
LU(pivot, k) = tmp;
198 result.
perm(j) = result.
perm(pivot);
199 result.
perm(pivot) = tmp_perm;
205 T diag = result.
LU(j, j);
215 T factor = result.
LU(i, j) / diag;
216 result.
LU(i, j) = factor;
220 result.
LU(i, k) -= factor * result.
LU(j, k);
238 template <
typename T, my_
size_t N>
243 if (!result.has_value())
248 return move(result.value());
static void error(const T &msg)
Definition error_handler.h:30
A discriminated union holding either a success value or an error.
Definition expected.h:86
Definition fused_matrix.h:12
Definition fused_vector.h:9
Global configuration for the tesseract tensor library.
#define my_size_t
Size/index type used throughout the library.
Definition config.h:126
#define PRECISION_TOLERANCE
Tolerance for floating-point comparisons (e.g. symmetry checks, Cholesky).
Definition config.h:117
A minimal, STL-free expected/result type for failable operations.
Runtime property descriptors and error codes for matrices.
constexpr T abs(T x) noexcept
Compute the absolute value of a numeric value.
Definition math_utils.h:48
Expected< LUResult< T, N >, MatrixStatus > lu(const FusedMatrix< T, N, N > &A, T tol=T(PRECISION_TOLERANCE))
Compute the LU decomposition of a square matrix with partial pivoting.
Definition lu.h:151
LUResult< T, N > lu_or_die(const FusedMatrix< T, N, N > &A)
LU decomposition — abort on failure.
Definition lu.h:239
MatrixStatus
Error codes for matrix decomposition and solver algorithms.
Definition matrix_traits.h:33
constexpr remove_reference_t< T > && move(T &&t) noexcept
Cast to rvalue reference (replacement for std::move).
Definition simple_type_traits.h:178
Tag type for constructing an Expected in the error state.
Definition expected.h:30
Result of LU decomposition with partial pivoting.
Definition lu.h:68
FusedMatrix< T, N, N > U() const
Extract the upper-triangular factor U.
Definition lu.h:100
FusedMatrix< T, N, N > LU
Compact L+U storage.
Definition lu.h:69
FusedVector< my_size_t, N > perm
Row permutation: perm(i) = original row index.
Definition lu.h:70
int sign
Permutation sign: +1 (even) or -1 (odd).
Definition lu.h:71
FusedMatrix< T, N, N > L() const
Extract the lower-triangular factor L with unit diagonal.
Definition lu.h:78