<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
getrf_level0.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_GETRF_LV0_HH
11#define TLAPACK_GETRF_LV0_HH
12
14namespace tlapack {
15
49template <TLAPACK_MATRIX matrix_t, TLAPACK_VECTOR piv_t>
51{
52 using idx_t = size_type<matrix_t>;
53 using T = type_t<matrix_t>;
54 using real_t = real_type<T>;
55
56 // constants
57 const idx_t m = nrows(A);
58 const idx_t n = ncols(A);
59 const idx_t end = min(m, n);
60
61 // check arguments
62 tlapack_check((idx_t)size(piv) >= end);
63
64 // quick return
65 if (m <= 0 || n <= 0) return 0;
66
67 for (idx_t j = 0; j < end; j++) {
68 // find pivot and swap the row with pivot row
69 piv[j] = j;
70 for (idx_t i = j + 1; i < m; i++) {
71 if (abs1(A(i, j)) > abs1(A(piv[j], j))) piv[j] = i;
72 }
73
74 // if nonzero pivot does not exist, return
75 if (A(piv[j], j) == real_t(0)) {
76 return j + 1;
77 }
78
79 // if the pivot happens to be a piv[j]>j(piv[j] not equal to j), then
80 // swap j-th row and piv[j] row of A
81 if ((idx_t)piv[j] != j) {
82 for (idx_t i = 0; i < n; i++) {
83 T tmp = A(j, i);
84 A(j, i) = A(piv[j], i);
85 A(piv[j], i) = tmp;
86 }
87 }
88
89 // divide below diagonal part of j-th column by the element on the
90 // diagonal(A(j,j))
91 // This is a level 0 routine, so we do not use tlapack::rscl.
92 for (idx_t i = j + 1; i < m; i++) {
93 A(i, j) /= A(j, j);
94 }
95
96 // update the submatrix A(j+1:m-1,j+1:n-1)
97 for (idx_t row = j + 1; row < m; row++) {
98 for (idx_t col = j + 1; col < n; col++) {
99 A(row, col) -= A(row, j) * A(j, col);
100 }
101 }
102 }
103
104 return 0;
105}
106
107} // namespace tlapack
108
109#endif // TLAPACK_GETRF_LV0_HH
constexpr real_type< T > abs1(const T &x)
1-norm absolute value, |Re(x)| + |Im(x)|
Definition utils.hpp:133
int getrf_level0(matrix_t &A, piv_t &piv)
getrf computes an LU factorization of a general m-by-n matrix A using partial pivoting with row inter...
Definition getrf_level0.hpp:50
#define tlapack_check(cond)
Throw an error if cond is false.
Definition exceptionHandling.hpp:98
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