CASM  1.1.0
A Clusters Approach to Statistical Mechanics
to_real.hh
Go to the documentation of this file.
1 #ifndef CASM_symmetry_to_real
2 #define CASM_symmetry_to_real
3 
5 #include "casm/external/Eigen/Core"
7 
8 namespace CASM {
9 
10 namespace SymRepTools_v2 {
11 
12 template <typename T>
13 struct _RealType;
14 
15 template <typename T>
16 using _Real = typename _RealType<T>::Type;
17 
18 template <typename T>
19 struct _RealType<std::vector<T>> {
20  using Type = std::vector<_Real<T>>;
21 };
22 
23 template <typename Scalar, int RowsAtCompileTime, int ColsAtCompileTime>
24 struct _RealType<Eigen::Matrix<Scalar, RowsAtCompileTime, ColsAtCompileTime>> {
25  using Type = Eigen::Matrix<double, RowsAtCompileTime, ColsAtCompileTime>;
26 };
27 
28 template <typename Derived>
29 _Real<Derived> to_real(Eigen::MatrixBase<Derived> const &mat) {
30  return mat.real().template cast<double>();
31 }
32 
33 template <typename T>
34 _Real<std::vector<T>> to_real(std::vector<T> const &vec) {
35  std::vector<_Real<T>> result;
36  result.reserve(vec.size());
37  for (T const &el : vec) {
38  result.emplace_back(to_real(el));
39  }
40 
41  return result;
42 }
43 
44 } // namespace SymRepTools_v2
45 
46 } // namespace CASM
47 
48 #endif
_Real< Derived > to_real(Eigen::MatrixBase< Derived > const &mat)
Definition: to_real.hh:29
typename _RealType< T >::Type _Real
Definition: to_real.hh:16
Main CASM namespace.
Definition: APICommand.hh:8
Definition: stream_io.hh:24
Eigen::Matrix< double, RowsAtCompileTime, ColsAtCompileTime > Type
Definition: to_real.hh:25