WaveBlocksND
matrix.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <yaml-cpp/yaml.h>
4 
5 
6 namespace YAML {
7  template<class _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
8  struct convert<Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>> {
9 
10  static Node encode(const Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> & M) {
11  YAML::Node matrixnode;
12  for (int r = 0; r < M.rows(); r++) {
13  YAML::Node rownode;
14  for (int c = 0; c < M.cols(); c++) {
15  rownode[c] = M(r,c);
16  }
17  matrixnode[r] = rownode;
18  }
19  return matrixnode;
20  }
21 
22  static bool decode(const Node& matrixnode, Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> & M) {
23  if (matrixnode.size() != (std::size_t)M.rows()) throw std::runtime_error("Matrix row size mismatch.");
24  for (int r = 0; r < M.rows(); r++) {
25  YAML::Node const& rownode = matrixnode[r];
26  if (rownode.size() != (std::size_t)M.cols()) throw std::runtime_error("Matrix col size mismatch.");
27  for (int c = 0; c < M.cols(); c++) {
28  M(r,c) = rownode[c].as<_Scalar>();
29  }
30  }
31  return true;
32  }
33  };
34 }
static bool decode(const Node &matrixnode, Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &M)
Definition: matrix.hpp:22
Basis< N, D, 1 > Eigen
Collection of types associated with a matrix potential in eigen basis.
Definition: bases.hpp:47
var c
Definition: jquery.js:23
Definition: complex.hpp:10
static Node encode(const Eigen::Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &M)
Definition: matrix.hpp:10