lu.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2020 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * David Williams-Young
19  * Computational Research Division, Lawrence Berkeley National Laboratory
20  *
21  * lu.h
22  * Created: 19 June, 2020
23  *
24  */
25 #ifndef TILEDARRAY_MATH_LINALG_NON_DISTRIBUTED_LU_H__INCLUDED
26 #define TILEDARRAY_MATH_LINALG_NON_DISTRIBUTED_LU_H__INCLUDED
27 
28 #include <TiledArray/config.h>
29 
33 
35 
39 template <typename ArrayA, typename ArrayB>
40 auto lu_solve(const ArrayA& A, const ArrayB& B, TiledRange x_trange = TiledRange()) {
43  auto& world = A.world();
44  auto A_eig = detail::make_matrix(A);
45  auto B_eig = detail::make_matrix(B);
46  if (world.rank() == 0) {
47  linalg::rank_local::lu_solve(A_eig, B_eig);
48  }
49  world.gop.broadcast_serializable(B_eig, 0);
50  if (x_trange.rank() == 0) x_trange = B.trange();
51  return eigen_to_array<ArrayB>(world, x_trange, B_eig);
52 }
53 
57 template <typename Array>
58 auto lu_inv(const Array& A, TiledRange ainv_trange = TiledRange()) {
60  auto& world = A.world();
61  auto A_eig = detail::make_matrix(A);
62  if (world.rank() == 0) {
64  }
65  world.gop.broadcast_serializable(A_eig, 0);
66  if (ainv_trange.rank() == 0) ainv_trange = A.trange();
67  return eigen_to_array<Array>(A.world(), ainv_trange, A_eig);
68 }
69 
70 } // namespace TiledArray::math::linalg::lapack
71 
72 #endif // TILEDARRAY_MATH_LINALG_NON_DISTRIBUTED_LU_H__INCLUDED
auto lu_solve(const ArrayA &A, const ArrayB &B, TiledRange x_trange=TiledRange())
Solve a linear system via LU factorization.
Definition: lu.h:40
void lu_solve(Matrix< T > &A, Matrix< T > &B)
Definition: rank-local.cpp:189
Range data of a tiled array.
Definition: tiled_range.h:32
const trange_type & trange() const
Tiled range accessor.
Definition: dist_array.h:917
Forward declarations.
Definition: dist_array.h:57
World & world() const
World accessor.
Definition: dist_array.h:1007
auto lu_inv(const Array &A, TiledRange ainv_trange=TiledRange())
Invert a matrix via LU.
Definition: lu.h:58
auto make_matrix(const DistArray< Tile, Policy > &A)
Definition: util.h:46