echelon  0.8.0
Eigen3.hpp
1 // Copyright (c) 2015 Christopher Hinz
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef ECHELON_EIGEN3_HPP
7 #define ECHELON_EIGEN3_HPP
8 
9 #include <echelon/hdf5/container_adaption.hpp>
10 
11 #include <Eigen/Dense>
12 #include <cassert>
13 
14 namespace echelon
15 {
16 namespace hdf5
17 {
18 
19 template <typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
20 inline std::vector<std::size_t>
21 shape(const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>& container, adl_enabler)
22 {
23  return {static_cast<std::size_t>(container.rows()), static_cast<std::size_t>(container.cols())};
24 }
25 
26 template <typename Scalar, int Options, int MaxRows, int MaxCols>
27 inline void reshape(Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Options, MaxRows, MaxCols>& container,
28  const std::vector<std::size_t>& new_shape, adl_enabler)
29 {
30  assert(new_shape.size() == 2);
31 
32  container.resize(new_shape[0], new_shape[1]);
33 }
34 
35 template <typename Scalar, int Cols, int Options, int MaxRows, int MaxCols>
36 inline void reshape(Eigen::Matrix<Scalar, Eigen::Dynamic, Cols, Options, MaxRows, MaxCols>& container,
37  const std::vector<std::size_t>& new_shape, adl_enabler)
38 {
39  assert(new_shape.size() == 1);
40 
41  container.resize(new_shape[0], Eigen::NoChange);
42 }
43 
44 template <typename Scalar, int Rows, int Options, int MaxRows, int MaxCols>
45 inline void reshape(Eigen::Matrix<Scalar, Rows, Eigen::Dynamic, Options, MaxRows, MaxCols>& container,
46  const std::vector<std::size_t>& new_shape, adl_enabler)
47 {
48  assert(new_shape.size() == 1);
49 
50  container.resize(Eigen::NoChange, new_shape[0]);
51 }
52 
53 }
54 }
55 
56 #endif
echelon&#39;s core namespace
Definition: attribute.cpp:10
auto reshape(C &container, const std::vector< std::size_t > &new_shape) -> decltype(reshape(container, new_shape, adl_enabler
Reshapes the container.
Definition: container_adaption.hpp:64