eigen.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2019 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  * Edward Valeev
19  * Department of Chemistry, Virginia Tech
20  *
21  * eigen.h
22  * Oct 1, 2019
23  *
24  */
25 
26 #ifndef TILEDARRAY_EXTERNAL_EIGEN_H__INCLUDED
27 #define TILEDARRAY_EXTERNAL_EIGEN_H__INCLUDED
28 
29 //
30 // Configure Eigen and include Eigen/Core, all dependencies should include this
31 // before including any Eigen headers
32 //
33 
34 #include <TiledArray/config.h>
35 #include <madness/config.h>
36 
37 TILEDARRAY_PRAGMA_GCC(diagnostic push)
38 TILEDARRAY_PRAGMA_GCC(system_header)
39 
40 // If EIGEN_USE_LAPACKE_STRICT is defined, Eigen doesn't check if
41 // EIGEN_USE_LAPACKE is defined before setting it, leading to a warning when it
42 // is already set, so we unset here to avoid that warning
43 #if defined(EIGEN_USE_LAPACKE_STRICT) && defined(EIGEN_USE_LAPACKE)
44 #undef EIGEN_USE_LAPACKE
45 #endif
46 
47 #include <Eigen/Core>
48 
49 #if defined(EIGEN_USE_LAPACKE) || defined(EIGEN_USE_LAPACKE_STRICT)
50 #if !EIGEN_VERSION_AT_LEAST(3, 3, 7)
51 #error "Eigen3 < 3.3.7 with LAPACKE enabled may give wrong eigenvalue results"
52 #error "Either turn off EIGEN_USE_LAPACKE/EIGEN_USE_LAPACKE_STRICT or use Eigen3 3.3.7"
53 #endif
54 #endif // EIGEN_USE_LAPACKE || EIGEN_USE_LAPACKE_STRICT
55 
56 TILEDARRAY_PRAGMA_GCC(diagnostic pop)
57 
58 namespace madness {
59 namespace archive {
60 
61 template <class>
63 template <class T>
64 inline archive_array<T> wrap(const T*, unsigned int);
65 template <class Archive, typename Data>
66 struct ArchiveStoreImpl;
67 template <class Archive, typename Data>
68 struct ArchiveLoadImpl;
69 
70 template <class Archive, typename Scalar, int RowsAtCompileTime,
71  int ColsAtCompileTime, int Options, int MaxRowsAtCompileTime,
72  int MaxColsAtCompileTime>
74  Archive,
75  Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
76  MaxRowsAtCompileTime, MaxColsAtCompileTime>> {
77  static inline void store(
78  const Archive& ar,
79  const Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
80  MaxRowsAtCompileTime, MaxColsAtCompileTime>& t) {
81  ar& t.rows() & t.cols();
82  if (t.size()) ar& madness::archive::wrap(t.data(), t.size());
83  }
84 };
85 
86 template <class Archive, typename Scalar, int RowsAtCompileTime,
87  int ColsAtCompileTime, int Options, int MaxRowsAtCompileTime,
88  int MaxColsAtCompileTime>
90  Archive,
91  Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
92  MaxRowsAtCompileTime, MaxColsAtCompileTime>> {
93  static inline void load(
94  const Archive& ar,
95  Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime, Options,
96  MaxRowsAtCompileTime, MaxColsAtCompileTime>& t) {
97  typename Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime,
98  Options, MaxRowsAtCompileTime,
99  MaxColsAtCompileTime>::Index nrows(0),
100  ncols(0);
101  ar& nrows& ncols;
102  t.resize(nrows, ncols);
103  if (t.size()) ar& madness::archive::wrap(t.data(), t.size());
104  }
105 };
106 
107 } // namespace archive
108 } // namespace madness
109 
110 #endif // TILEDARRAY_EXTERNAL_EIGEN_H__INCLUDED
archive_array< T > wrap(const T *, unsigned int)
Forward declarations.
Definition: foreach.h:34
static void load(const Archive &ar, Eigen::Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime > &t)
Definition: eigen.h:93
::Eigen::Matrix< T, ::Eigen::Dynamic, ::Eigen::Dynamic, Options > Matrix
Definition: blas.h:63
static void store(const Archive &ar, const Eigen::Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime > &t)
Definition: eigen.h:77