1#ifndef FUSED_ALGORITHMS_LINEAR_SOLVE_H
2#define FUSED_ALGORITHMS_LINEAR_SOLVE_H
70 template <
typename T, my_
size_t N>
75 static_assert(is_floating_point_v<T>,
76 "lu_solve requires a floating-point scalar type");
79 auto lu_result =
lu(A);
81 if (!lu_result.has_value())
86 auto &decomp = lu_result.value();
93 b_perm(i) = b(decomp.perm(i));
101 auto fwd_result = forward_substitute<true>(L, b_perm);
103 if (!fwd_result.has_value())
108 auto &y = fwd_result.value();
141 template <
typename T, my_
size_t N>
146 static_assert(is_floating_point_v<T>,
147 "solve requires a floating-point scalar type");
152 if (chol_result.has_value())
Solve Ax = b for symmetric positive-definite A via Cholesky decomposition.
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
A minimal, STL-free expected/result type for failable operations.
LU decomposition with partial pivoting for square matrices.
Runtime property descriptors and error codes for matrices.
Expected< FusedVector< T, N >, MatrixStatus > back_substitute(const FusedMatrix< T, N, N > &U, const FusedVector< T, N > &b)
Solve the upper-triangular system Ux = b by back substitution.
Definition triangular_solve.h:216
Expected< FusedVector< T, N >, MatrixStatus > solve(const FusedMatrix< T, N, N > &A, const FusedVector< T, N > &b)
Solve Ax = b with automatic algorithm selection.
Definition linear_solve.h:142
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
Expected< FusedVector< T, N >, MatrixStatus > lu_solve(const FusedMatrix< T, N, N > &A, const FusedVector< T, N > &b)
Solve Ax = b via LU decomposition with partial pivoting.
Definition linear_solve.h:71
Expected< FusedVector< T, N >, MatrixStatus > cholesky_solve(const FusedMatrix< T, N, N > &A, const FusedVector< T, N > &b)
Solve Ax = b for symmetric positive-definite A via Cholesky decomposition.
Definition cholesky_solve.h:81
MatrixStatus
Error codes for matrix decomposition and solver algorithms.
Definition matrix_traits.h:33
Tag type for constructing an Expected in the error state.
Definition expected.h:30
E error
The error value.
Definition expected.h:31
Forward/back substitution for triangular systems.