<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
getri_uxli.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
5//
6// This file is part of <T>LAPACK.
7// <T>LAPACK is free software: you can redistribute it and/or modify it under
8// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
9
10#ifndef TLAPACK_GETRI_UXLI_HH
11#define TLAPACK_GETRI_UXLI_HH
12
14#include "tlapack/blas/copy.hpp"
15#include "tlapack/blas/dotu.hpp"
16#include "tlapack/blas/gemv.hpp"
17
18namespace tlapack {
19
28template <class T, TLAPACK_SMATRIX matrix_t>
30{
31 if constexpr (is_same_v<T, type_t<matrix_t>>)
32 return WorkInfo(ncols(A) - 1);
33 else
34 return WorkInfo(0);
35}
36
45template <TLAPACK_SMATRIX matrix_t, TLAPACK_WORKSPACE work_t>
47{
48 using idx_t = size_type<matrix_t>;
49 using T = type_t<matrix_t>;
51
52 // constant n, number of rows and also columns of A
53 const idx_t n = ncols(A);
54
55 // check arguments
56 tlapack_check(nrows(A) == n);
57
58 // Vector W
59 auto [W, work2] = reshape(work, n - 1);
60
61 // A has L and U in it, we will create X such that UXL=A in place of
62 for (idx_t j = n - idx_t(1); j != idx_t(-1); j--) {
63 // if A(j,j) is zero, then the matrix is not invertible
64 if (A(j, j) == T(0)) return j + 1;
65
66 if (j == n - 1) {
67 A(j, j) = T(1) / A(j, j);
68 }
69 else {
70 // X22, l21, u12 are as in method C Nick Higham
71 auto X22 = tlapack::slice(A, range(j + 1, n), range(j + 1, n));
72 auto l21 = tlapack::slice(A, range(j + 1, n), j);
73 auto u12 = tlapack::slice(A, j, range(j + 1, n));
74 auto w = tlapack::slice(W, range(0, n - j - 1));
75
76 // first step of the algorithm, w holds x12
77 tlapack::gemv(TRANSPOSE, T(-1) / A(j, j), X22, u12, w);
78
79 // second line of the algorithm, update A(j, j)
80 A(j, j) = (T(1) / A(j, j)) - tlapack::dotu(l21, w);
81
82 // u12 updated, w available for use again
84
85 // third line of the algorithm
86 tlapack::gemv(NO_TRANS, T(-1), X22, l21, w);
87
88 // update l21
90 }
91 }
92
93 return 0;
94} // getri_uxli
95
114template <TLAPACK_SMATRIX matrix_t>
116{
117 using T = type_t<matrix_t>;
118
119 // Functor
121
122 // Allocates workspace
124 std::vector<T> work_;
125 auto work = new_matrix(work_, workinfo.m, workinfo.n);
126
127 return getri_uxli_work(A, work);
128} // getri_uxli
129
130} // namespace tlapack
131
132#endif // TLAPACK_GETRI_UXLI_HH
constexpr internal::Transpose TRANSPOSE
transpose
Definition types.hpp:257
constexpr internal::NoTranspose NO_TRANS
no transpose
Definition types.hpp:255
int getri_uxli(matrix_t &A)
getri computes inverse of a general n-by-n matrix A by solving for X in the following equation
Definition getri_uxli.hpp:115
auto dotu(const vectorX_t &x, const vectorY_t &y)
Definition dotu.hpp:32
void copy(const vectorX_t &x, vectorY_t &y)
Copy vector, .
Definition copy.hpp:31
void gemv(Op trans, const alpha_t &alpha, const matrixA_t &A, const vectorX_t &x, const beta_t &beta, vectorY_t &y)
General matrix-vector multiply:
Definition gemv.hpp:57
int getri_uxli_work(matrix_t &A, work_t &work)
getri computes inverse of a general n-by-n matrix A by solving for X in the following equation Work...
Definition getri_uxli.hpp:46
#define tlapack_check(cond)
Throw an error if cond is false.
Definition exceptionHandling.hpp:98
constexpr WorkInfo getri_uxli_worksize(const matrix_t &A)
Worspace query of getri()
Definition getri_uxli.hpp:29
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113
Output information in the workspace query.
Definition workspace.hpp:16