heig.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  * Eduard Valeyev
19  *
20  * heig.h
21  * Created: 19 October, 2020
22  *
23  */
24 #ifndef TILEDARRAY_MATH_LINALG_NON_DISTRIBUTED_HEIG_H__INCLUDED
25 #define TILEDARRAY_MATH_LINALG_NON_DISTRIBUTED_HEIG_H__INCLUDED
26 
27 #include <TiledArray/config.h>
28 
32 
34 
53 template <typename Array>
54 auto heig(const Array& A, TiledRange evec_trange = TiledRange()) {
55  using numeric_type = typename detail::array_traits<Array>::numeric_type;
56  World& world = A.world();
57  auto A_eig = detail::make_matrix(A);
58  std::vector<numeric_type> evals;
59  if (world.rank() == 0) {
60  linalg::rank_local::heig(A_eig, evals);
61  }
62  world.gop.broadcast_serializable(A_eig, 0);
63  world.gop.broadcast_serializable(evals, 0);
64  if (evec_trange.rank() == 0) evec_trange = A.trange();
65  return std::tuple(
66  evals,
67  eigen_to_array<Array>(world, evec_trange, A_eig)
68  );
69 }
70 
94 template <typename ArrayA, typename ArrayB, typename EVecType = ArrayA>
95 auto heig(const ArrayA& A, const ArrayB& B, TiledRange evec_trange = TiledRange()) {
96  using numeric_type = typename detail::array_traits<ArrayA>::numeric_type;
98  World& world = A.world();
99  auto A_eig = detail::make_matrix(A);
100  auto B_eig = detail::make_matrix(B);
101  std::vector<numeric_type> evals;
102  if (world.rank() == 0) {
103  linalg::rank_local::heig(A_eig, B_eig, evals);
104  }
105  world.gop.broadcast_serializable(A_eig, 0);
106  world.gop.broadcast_serializable(evals, 0);
107  if (evec_trange.rank() == 0) evec_trange = A.trange();
108  return std::tuple(
109  evals,
110  eigen_to_array<ArrayA>(A.world(), evec_trange, A_eig)
111  );
112 }
113 
114 } // namespace TiledArray::math::linalg
115 
116 #endif // TILEDARRAY_MATH_LINALG_NON_DISTRIBUTED_HEIG_H__INCLUDED
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
typename A::numeric_type numeric_type
Definition: util.h:38
auto heig(const Array &A, TiledRange evec_trange=TiledRange())
Solve the standard eigenvalue problem with LAPACK.
Definition: heig.h:54
void heig(Matrix< T > &A, std::vector< T > &W)
Definition: rank-local.cpp:116
auto make_matrix(const DistArray< Tile, Policy > &A)
Definition: util.h:46