17 static constexpr double c[7] =
18 {1.0, 0.5, 5.0 / 44.0, 1.0 / 66.0, 1.0 / 792.0, 1.0 / 15840.0, 1.0 / 665280.0};
20 double norm_inf = 0.0;
21 for (
idx i = 0; i < m; i++) {
23 for (
idx j = 0; j < m; j++) {
24 row_sum += std::abs(A(i, j));
26 norm_inf = std::max(norm_inf, row_sum);
31 s = (int)std::max(0.0, std::ceil(std::log2(norm_inf / 0.5)));
34 double scale = std::ldexp(1.0, -s);
36 for (
idx i = 0; i < m; i++) {
37 for (
idx j = 0; j < m; j++) {
38 As(i, j) = A(i, j) *
scale;
52 for (
idx i = 0; i < m; i++) {
53 for (
idx j = 0; j < m; j++) {
54 V_mat(i, j) = (c[6] * B3(i, j)) + (c[4] * B2(i, j)) + (c[2] * B(i, j));
60 for (
idx i = 0; i < m; i++) {
61 for (
idx j = 0; j < m; j++) {
62 W(i, j) = (c[5] * B2(i, j)) + (c[3] * B(i, j));
72 for (
idx i = 0; i < m; i++) {
73 for (
idx j = 0; j < m; j++) {
74 VpU(i, j) = V_mat(i, j) + U(i, j);
75 VmU(i, j) = V_mat(i, j) - U(i, j);
83 for (
int i = 0; i < s; i++) {
97 return expv(t, op, v, m_max, tol);
constexpr idx rows() const noexcept
Sparse matrix in Compressed Sparse Row (CSR) format.
Krylov subspace matrix exponential-vector product: compute exp(t*A)*v.
LU factorization with partial pivoting.
Dense row-major matrix templated over scalar type T.
Matrix dense_expm_pade6(const Matrix &A)
void scale(Vector &v, real alpha, Backend b=default_backend)
Compute .
Vector expv(real t, const Op &A, const Vector &v, int m_max=30, real tol=1e-8)
Compute for any adapter.
void matmul(const Matrix &A, const Matrix &B, Matrix &C, Backend b=default_backend)
C = A * B.
void lu_solve(const LUResult &f, const Vector &b, Vector &x)
Solve from a precomputed factorization.
LUResult lu(const Matrix &A, Backend backend=lapack_backend)
Umbrella include for operator concepts and adapters.
Adapt a SparseMatrix to the operator protocol.
Dense vector storage and operations.