Xped
Loading...
Searching...
No Matches
TensorInterface_Eigen_impl.hpp
Go to the documentation of this file.
1#ifndef TENSOR_INTERFACE_EIGEN_IMPL_H_
2#define TENSOR_INTERFACE_EIGEN_IMPL_H_
3
4#include <Eigen/Dense>
5#include <unsupported/Eigen/CXX11/Tensor>
6
7#include "Xped/Util/Mpi.hpp"
8
9namespace Xped {
10
11struct TensorInterface
12{
13 // typedefs
14 template <typename Scalar, std::size_t Rank>
15 using TType = Eigen::Tensor<Scalar, Rank>;
16 template <typename Scalar, std::size_t Rank>
17 using cTType = const Eigen::Tensor<Scalar, Rank>;
18
19 template <typename Scalar, std::size_t Rank>
20 using MapTType = Eigen::TensorMap<TType<Scalar, Rank>>;
21 template <typename Scalar, std::size_t Rank>
22 using cMapTType = Eigen::TensorMap<cTType<Scalar, Rank>>;
23
24 // template<typename Scalar, std::size_t Rank> using Indextype = typename Eigen::Tensor<Scalar,Rank>::Index;
25 using Indextype = Eigen::Index;
26
27 // constructors
28 template <typename Scalar, std::size_t Rank>
29 static TType<Scalar, Rank> construct(const std::array<Indextype, Rank>& dims, const mpi::XpedWorld& = mpi::getUniverse());
30
31 template <typename Scalar, int Rank>
33
34 template <typename Scalar, int Rank>
36
37 // map constructors
38 template <typename Scalar, std::size_t Rank>
39 static cMapTType<Scalar, Rank> cMap(const Scalar* data, const std::array<Indextype, Rank>& dims);
40
41 template <typename Scalar, std::size_t Rank>
42 static MapTType<Scalar, Rank> Map(Scalar* data, const std::array<Indextype, Rank>& dims);
43
44 // initialization
45 template <typename Scalar, int Rank>
47
48 template <typename Scalar, int Rank>
50
51 template <typename Scalar, int Rank>
52 static void setConstant(TType<Scalar, Rank>& T, const Scalar& val);
53
54 template <typename Scalar, int Rank>
55 static void setVal(TType<Scalar, Rank>& T, const std::array<Indextype, Rank>& index, const Scalar& val);
56
57 template <typename Scalar, int Rank>
58 static Scalar getVal(const TType<Scalar, Rank>& T, const std::array<Indextype, Rank>& index);
59
60 // raw data
61 template <typename Scalar, int Rank>
62 static const Scalar* get_raw_data(const TType<Scalar, Rank>& T);
63
64 template <typename Scalar, int Rank>
66
67 // shape info
68 template <typename Scalar, int Rank>
69 static std::array<Indextype, Rank> dimensions(const TType<Scalar, Rank>& T);
70
71 // tensorProd
72 template <typename Scalar, int Rank>
74
75 template <typename Scalar, std::size_t Rank, typename Expr1, typename Expr2>
76 static void addScale(const Expr1& src, Expr2& dst, const Scalar& scale);
77
78 // methods rvalue
79 template <typename Scalar, std::size_t Rank1, std::size_t Rank2, Indextype... Is>
80 static TType<Scalar, Rank1 + Rank2 - sizeof...(Is)> contract(const TType<Scalar, Rank1>& T1, const TType<Scalar, Rank2>& T2);
81
82 template <typename Scalar, std::size_t Rank, Indextype... p>
84
85 template <typename Scalar, std::size_t Rank, Indextype... p>
86 static TType<Scalar, Rank> shuffle(const TType<Scalar, Rank>& T, seq::iseq<Indextype, p...> s);
87
88 template <typename Expr, Indextype... p>
89 static const Eigen::TensorShufflingOp<const std::array<Indextype, Eigen::internal::traits<Expr>::NumDimensions>, const Expr>
90 shuffle_view(const Expr& T);
91
92 // template<typename Scalar, std::size_t Rank, Indextype... p>
93 // static auto shuffle_view(const cMapTType<Scalar,Rank>& T)
94 // {
95 // static_assert(Rank == sizeof...(p));
96 // std::array<Indextype, Rank> dims = {p...};
97 // return T.shuffle(dims);
98 // }
99
100 template <typename Scalar, int Rank1, std::size_t Rank2>
101 static TType<Scalar, Rank2> reshape(const TType<Scalar, Rank1>& T, const std::array<Indextype, Rank2>& dims);
102
103 // methods lvalue
104 template <typename Scalar, std::size_t Rank1, std::size_t Rank2>
106 const std::array<Indextype, Rank2>& offsets,
107 const std::array<Indextype, Rank2>& extents,
108 const TType<Scalar, Rank1>& S);
109
110 template <typename Scalar, int Rank1, std::size_t Rank2>
111 static const Eigen::TensorSlicingOp<const std::array<Indextype, Rank2>, const std::array<Indextype, Rank2>, const TType<Scalar, Rank1>>
112 slice(TType<Scalar, Rank1>& T, const std::array<Indextype, Rank2>& offsets, const std::array<Indextype, Rank2>& extents);
113
114 template <typename Scalar, int Rank1, std::size_t Rank2>
115 static const Eigen::TensorReshapingOp<const std::array<Indextype, Rank2>, const TType<Scalar, Rank1>>
116 reshape(TType<Scalar, Rank1>& T, const std::array<Indextype, Rank2>& dims);
117
118 template <typename Scalar, int Rank>
119 static std::string print(const TType<Scalar, Rank>& T);
120};
121
122} // namespace Xped
123
124#ifndef XPED_COMPILED_LIB
126#endif
127
128#endif
XpedWorld & getUniverse()
Definition: Mpi.hpp:49
Definition: bench.cpp:62
static auto shuffle_view(const Expr &T)
Definition: TensorInterface_Array_impl.hpp:300
nda::dense_array< Scalar, Rank > TType
Definition: TensorInterface_Array_impl.hpp:44
static void setZero(TType< Scalar, Rank > &T)
const nda::dense_array< Scalar, Rank > cTType
Definition: TensorInterface_Array_impl.hpp:46
static void setConstant(TType< Scalar, Rank > &T, const Scalar &val)
static TType< Scalar, Rank > construct(const MapTType< Scalar, Rank > &map)
static cTType< Scalar, Rank > construct(const cMapTType< Scalar, Rank > &map)
static Scalar * get_raw_data(TType< Scalar, Rank > &T)
static void addScale(const Expr1 &src, Expr2 &dst, const Scalar &scale)
static std::array< Indextype, Rank > dimensions(const TType< Scalar, Rank > &T)
static TType< Scalar, Rank2 > reshape(const TType< Scalar, Rank1 > &T, const std::array< Indextype, Rank2 > &dims)
static void setSubTensor(TType< Scalar, Rank1 > &T, const std::array< Indextype, Rank2 > &offsets, const std::array< Indextype, Rank2 > &extents, const TType< Scalar, Rank1 > &S)
static void setVal(TType< Scalar, Rank > &T, const std::array< Indextype, Rank > &index, const Scalar &val)
nda::index_t Indextype
Definition: TensorInterface_Array_impl.hpp:54
static std::string print(const TType< Scalar, Rank > &T)
static TType< Scalar, Rank > shuffle(const TType< Scalar, Rank > &T)
static auto slice(TType< Scalar, Rank1 > &T, const std::array< Indextype, Rank2 > &offsets, const std::array< Indextype, Rank2 > &extents)
Definition: TensorInterface_Array_impl.hpp:358
static const Scalar * get_raw_data(const TType< Scalar, Rank > &T)
static Scalar getVal(const TType< Scalar, Rank > &T, const std::array< Indextype, Rank > &index)
nda::dense_array_ref< Scalar, Rank > MapTType
Definition: TensorInterface_Array_impl.hpp:49
static MapTType< Scalar, Rank > Map(Scalar *data, const std::array< Indextype, Rank > &dims)
static void setRandom(TType< Scalar, Rank > &T)
static TType< Scalar, Rank > tensorProd(const TType< Scalar, Rank > &T1, const TType< Scalar, Rank > &T2)
static TType< Scalar, Rank > construct(const std::array< Indextype, Rank > &dims, mpi::XpedWorld &world=mpi::getUniverse())
Definition: TensorInterface_Array_impl.hpp:58
static TType< Scalar, Rank1+Rank2 - sizeof...(Is)> contract(const TType< Scalar, Rank1 > &T1, const TType< Scalar, Rank2 > &T2)
static TType< Scalar, Rank > shuffle(const TType< Scalar, Rank > &T, seq::iseq< Indextype, p... > s)
static TType< Scalar, Rank2 > reshape(const TType< Scalar, Rank1 > &T, const std::array< Indextype, Rank2 > &dims)
Definition: TensorInterface_Array_impl.hpp:350
static cMapTType< Scalar, Rank > cMap(const Scalar *data, const std::array< Indextype, Rank > &dims)
nda::const_dense_array_ref< Scalar, Rank > cMapTType
Definition: TensorInterface_Array_impl.hpp:51
Definition: Mpi.hpp:34