Cosan  1.0
Data Analytics Library
templateTest.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <vector>
3 #include <type_traits>
4 #include <numeric>
5 #include <string>
6 #include <gsl/gsl>
7 #include <Eigen/Dense>
8 namespace Cosan
9 {
10 // MISSING VALUES, STRING, NUMERICAL
11  template<typename NumericType,
12  typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type
13  >
14  using vec = std::vector<NumericType> ;
15 
16  template<typename NumericType,
17  typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type
18  >
19  using CosanMatrix = Eigen::Matrix<NumericType, Eigen::Dynamic, Eigen::Dynamic> ;
20 
21  template <typename NumericType=std::string>
22  NumericType StringToNum(std::string arg) {
23  if constexpr (std::is_same_v<NumericType, unsigned long>) {
24  return std::stoul(arg);
25  }
26  else if constexpr (std::is_same_v<NumericType, unsigned long long>){
27  return std::stoull(arg);
28  }
29  else if constexpr (std::is_same_v<NumericType, int>){
30  return std::stoi(arg);
31  }
32  else if constexpr (std::is_same_v<NumericType, long>){
33  return std::stol(arg);
34  }
35  else if constexpr (std::is_same_v<NumericType, long long>){
36  return std::stoll(arg);
37  }
38  else if constexpr (std::is_same_v<NumericType, float>){
39  return std::stof(arg);
40  }
41  else if constexpr (std::is_same_v<NumericType, double>){
42  return std::stod(arg);
43  }
44  else{
45  return std::stold(arg);
46  }
47  }
48 
49  template<typename NumericType,
50  typename = typename std::enable_if<std::is_arithmetic<NumericType>::value,NumericType>::type>
51  class Test {
52  public:
53  Test()=default;
55  static_assert(std::is_arithmetic<NumericType>::value, "NumericType must be numeric");
56  b = inputX;
57  a = sumfunction(b);
58  }
60  static_assert(std::is_arithmetic<NumericType>::value, "NumericType must be numeric");
61  b = inputX;
62  a = sumfunction(b);
63  }
67  private:
69  CosanMatrix<NumericType> X = Eigen::Map<const CosanMatrix<NumericType>>(a.data(), 1, a.size());
70  std::cout<<X<<std::endl;
71  return std::accumulate(a.begin(), a.end(), 0);
72  }
73 
74  } ;
75 }
76 
77 int main(){
78 
79  // std::vector<bool> myVec = {0,1,1,0,0,1,0,1,0,1};
80  // Eigen::Matrix<bool,2,5,Eigen::RowMajor> X1,X2;
81  // for (gsl::index i =0;i<myVec.size();i++){
82  // X1(i/5,i%5)=myVec[i];
83  // }
84  // std::copy(myVec.begin(),myVec.end(),X2.data());
85  // std::cout<<X1<<std::endl;
86  // X2.resize(2, 5);
87  // std::cout<<X2<<std::endl;
88  // std::string a = "nan";
89  // std::cout<<Cosan::StringToNum<int>(a)<<std::endl;
91  a.face.resize(2,2);
92  a.face<<1,2,3,4;
93  std::cout<<a.face<<std::endl;
94  static_assert(std::is_same_v<decltype(a.face)::Scalar, int>);
95  std::cout<<typeid(decltype(a.face)::Scalar).name()<<std::endl;
96  return 0;
97 }
Cosan
Definition: CosanBO.h:29
Cosan::Test::a
NumericType a
Definition: templateTest.cpp:64
NumericType
double NumericType
Definition: onehotencodingTest.cpp:20
Cosan::vec
std::vector< NumericType > vec
Definition: templateTest.cpp:14
Cosan::CosanMatrix
Eigen::Matrix< NumericType, Eigen::Dynamic, Eigen::Dynamic > CosanMatrix
Definition: CosanBO.h:37
Cosan::Test::sumfunction
NumericType sumfunction(vec< NumericType > &a)
Definition: templateTest.cpp:68
Cosan::Test::Test
Test(vec< NumericType > inputX)
Definition: templateTest.cpp:59
Cosan::Test::b
vec< NumericType > b
Definition: templateTest.cpp:65
Cosan::Test::Test
Test(vec< NumericType > &inputX)
Definition: templateTest.cpp:54
Cosan::Test::Test
Test()=default
Cosan::Test
Definition: templateTest.cpp:51
Cosan::Test::face
CosanMatrix< NumericType > face
Definition: templateTest.cpp:66
main
int main()
Definition: templateTest.cpp:77
Cosan::StringToNum
NumericType StringToNum(const std::string &arg, std::size_t *pos=0)
General string to number conversion function.
Definition: utils.h:25