rsvs3D  0.0.0
Codes for the c++ implementation of the 3D RSVS
matrixtools.hpp
Go to the documentation of this file.
1 
6 #ifndef MATRIXTOOLS_H_INCLUDED
7 #define MATRIXTOOLS_H_INCLUDED
8 
9 //=================================
10 // forward declared dependencies
11 // class foo; //when you only need a pointer not the actual object
12 // and to avoid circular dependencies
13 
14 //=================================
15 // included dependencies
16 
17 #include <Eigen>
18 #include <fstream>
19 #include <iostream>
20 #include <string>
21 #include <vector>
22 
23 #include "vectorarray.hpp"
24 
25 template <class T> void PrintMatrixFile(const std::vector<T> &mat, const char *name);
26 void Deriv1stChainScalar(const Eigen::MatrixXd &dSdc, const Eigen::MatrixXd &dcdd, Eigen::MatrixXd &dSdd);
27 void Deriv2ndChainScalar(const Eigen::MatrixXd &dSdc, const Eigen::MatrixXd &dcdd, const Eigen::MatrixXd &HSc,
28  const Eigen::MatrixXd &Hcd, Eigen::MatrixXd &HSd);
29 void VecBy3DimArray(const Eigen::MatrixXd &vec, const Eigen::MatrixXd &arr3dim, Eigen::MatrixXd &retArray);
30 void ArrayVec2MatrixXd(const ArrayVec<double> &arrayIn, Eigen::MatrixXd &matOut);
31 void PrintMatrix(const Eigen::MatrixXd &mat);
32 void PrintMatrixFile(const Eigen::MatrixXd &mat, const char *name);
33 void PrintMatrixFile(const Eigen::MatrixXd &mat, std::ostream &myfile);
34 void PrintMatrix(const Eigen::RowVectorXd &mat);
35 void PrintMatrix(const Eigen::VectorXd &mat);
36 double StreamStatistics(const Eigen::VectorXd &&vec, std::ostream &out, const std::string &&sep = std::string(", "));
37 void StreamOutVector(const Eigen::VectorXd &&vec, std::ostream &out, const std::string &&sep = std::string(", "));
38 
39 int Test_Matrix3D();
40 
41 //==================================
42 // Code
43 // NOTE: function in a class definition are IMPLICITELY INLINED
44 // ie replaced by their code at compile time
45 
46 template <class T> void PrintMatrixFile(const std::vector<T> &mat, const char *name)
47 {
48  int ii, ni;
49  std::ofstream myfile;
50  ni = mat.size();
51 
52  myfile.open(name, std::ios::app);
53  myfile.precision(16);
54  myfile << std::scientific;
55  for (ii = 0; ii < ni; ++ii)
56  {
57  myfile << mat[ii] << " ";
58  }
59  myfile << std::endl;
60  myfile.close();
61 }
62 
63 #endif
Provides a 2D std::vector based container.