<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
laset.hpp
Go to the documentation of this file.
1
5//
6// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
7//
8// This file is part of <T>LAPACK.
9// <T>LAPACK is free software: you can redistribute it and/or modify it under
10// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
11
12#ifndef TLAPACK_LASET_HH
13#define TLAPACK_LASET_HH
14
16
17namespace tlapack {
18
37template <TLAPACK_UPLO uplo_t, TLAPACK_MATRIX matrix_t>
41 matrix_t& A)
42{
43 using idx_t = size_type<matrix_t>;
44
45 // constants
46 const idx_t m = nrows(A);
47 const idx_t n = ncols(A);
48
49 // check arguments
50 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper &&
51 uplo != Uplo::General);
52
53 if (uplo == Uplo::Upper) {
54 // Set the strictly upper triangular or trapezoidal part of
55 // the array to alpha.
56 for (idx_t j = 1; j < n; ++j) {
57 const idx_t M = min(m, j);
58 for (idx_t i = 0; i < M; ++i)
59 A(i, j) = alpha;
60 }
61 }
62 else if (uplo == Uplo::Lower) {
63 // Set the strictly lower triangular or trapezoidal part of
64 // the array to alpha.
65 const idx_t N = min(m, n);
66 for (idx_t j = 0; j < N; ++j) {
67 for (idx_t i = j + 1; i < m; ++i)
68 A(i, j) = alpha;
69 }
70 }
71 else {
72 // Set all elements in A to alpha.
73 for (idx_t j = 0; j < n; ++j)
74 for (idx_t i = 0; i < m; ++i)
75 A(i, j) = alpha;
76 }
77
78 // Set the first min(m,n) diagonal elements to beta.
79 const idx_t N = min(m, n);
80 for (idx_t i = 0; i < N; ++i)
81 A(i, i) = beta;
82}
83
84} // namespace tlapack
85
86#endif // TLAPACK_LASET_HH
void laset(uplo_t uplo, const type_t< matrix_t > &alpha, const type_t< matrix_t > &beta, matrix_t &A)
Initializes a matrix to diagonal and off-diagonal values.
Definition laset.hpp:38
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
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