<T>LAPACK 0.1.2
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
lacpy.hpp
Go to the documentation of this file.
1
5//
6// Copyright (c) 2025, 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 using TB = type_t<matrixB_t>;
43
44 // constants
45 const idx_t m = nrows(A);
46 const idx_t n = ncols(A);
47
48 // check arguments
49 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper &&
50 uplo != Uplo::General);
51
52 if (uplo == Uplo::Upper) {
53 // Set the strictly upper triangular or trapezoidal part of B
54 for (idx_t j = 0; j < n; ++j) {
55 const idx_t M = min(m, j + 1);
56 for (idx_t i = 0; i < M; ++i)
57 B(i, j) = (TB)A(i, j);
58 }
59 }
60 else if (uplo == Uplo::Lower) {
61 // Set the strictly lower triangular or trapezoidal part of B
62 const idx_t N = min(m, n);
63 for (idx_t j = 0; j < N; ++j)
64 for (idx_t i = j; i < m; ++i)
65 B(i, j) = (TB)A(i, j);
66 }
67 else {
68 // Set the whole m-by-n matrix B
69 for (idx_t j = 0; j < n; ++j)
70 for (idx_t i = 0; i < m; ++i)
71 B(i, j) = (TB)A(i, j);
72 }
73}
74
75} // namespace tlapack
76
77#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