<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
lacpy.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_LACPY_HH
13#define TLAPACK_LACPY_HH
14
16
17namespace tlapack {
18
35template <TLAPACK_UPLO uplo_t,
36 TLAPACK_MATRIX matrixA_t,
37 TLAPACK_MATRIX matrixB_t>
39{
40 // data traits
41 using idx_t = size_type<matrixA_t>;
42
43 // constants
44 const idx_t m = nrows(A);
45 const idx_t n = ncols(A);
46
47 // check arguments
48 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper &&
49 uplo != Uplo::General);
50
51 if (uplo == Uplo::Upper) {
52 // Set the strictly upper triangular or trapezoidal part of B
53 for (idx_t j = 0; j < n; ++j) {
54 const idx_t M = min(m, j + 1);
55 for (idx_t i = 0; i < M; ++i)
56 B(i, j) = A(i, j);
57 }
58 }
59 else if (uplo == Uplo::Lower) {
60 // Set the strictly lower triangular or trapezoidal part of B
61 const idx_t N = min(m, n);
62 for (idx_t j = 0; j < N; ++j)
63 for (idx_t i = j; i < m; ++i)
64 B(i, j) = A(i, j);
65 }
66 else {
67 // Set the whole m-by-n matrix B
68 for (idx_t j = 0; j < n; ++j)
69 for (idx_t i = 0; i < m; ++i)
70 B(i, j) = A(i, j);
71 }
72}
73
74} // namespace tlapack
75
76#endif // TLAPACK_LACPY_HH
#define TLAPACK_UPLO
Macro for tlapack::concepts::Uplo compatible with C++17.
Definition concepts.hpp:942
#define TLAPACK_MATRIX
Macro for tlapack::concepts::Matrix compatible with C++17.
Definition concepts.hpp:896
void lacpy(uplo_t uplo, const matrixA_t &A, matrixB_t &B)
Copies a matrix from A to B.
Definition lacpy.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