Latin Hypercube Samples (lhs)  1.0
R, C++, and Rcpp code to generate Latin hypercube samples
All Classes Namespaces Files Functions Variables Typedefs Macros Pages
oa_r_utils.h
Go to the documentation of this file.
1 
21 #ifndef OA_R_UTILS_H
22 #define OA_R_UTILS_H
23 
24 #include <stdexcept>
25 #include <Rcpp.h>
26 #include "matrix.h"
27 #include "rutils.h"
28 
32 namespace oarutils {
33 
41  template <class T>
42  void convertToIntegerMatrix(const bclib::matrix<T> & A, Rcpp::IntegerMatrix & rcppA)
43  {
44  size_t nrows = A.rowsize();
45  size_t ncols = A.colsize();
46  if (rcppA.rows() != static_cast<int>(nrows) || rcppA.cols() != static_cast<int>(ncols))
47  {
48  rcppA = Rcpp::IntegerMatrix(nrows, ncols);
49  }
50  for (size_t i = 0; i < nrows; i++)
51  {
52  for (size_t j = 0; j < ncols; j++)
53  {
54  rcppA(i,j) = static_cast<int>(A(i,j));
55  }
56  }
57  }
58 
67  template <class T, class U>
68  void convertToRcppMatrix(const bclib::matrix<T> & A, U & rcppA)
69  {
70  size_t nrows = A.rowsize();
71  size_t ncols = A.colsize();
72  if (rcppA.rows() != static_cast<int>(nrows) || rcppA.cols() != static_cast<int>(ncols))
73  {
74  rcppA = U(nrows, ncols);
75  }
76  for (size_t i = 0; i < nrows; i++)
77  {
78  for (size_t j = 0; j < ncols; j++)
79  {
80  rcppA(i,j) = A(i,j);
81  }
82  }
83  }
84 
93  template <class T, class U>
94  void convertToMatrix(const U & rcppA, bclib::matrix<T> & A)
95  {
96  int nrows = rcppA.rows();
97  int ncols = rcppA.cols();
98  if (nrows != static_cast<int>(A.rowsize()) || ncols != static_cast<int>(A.colsize()))
99  {
100  A = bclib::matrix<T>(static_cast<size_t>(nrows), static_cast<size_t>(ncols));
101  }
102  for (size_t i = 0; i < static_cast<size_t>(nrows); i++)
103  {
104  for (size_t j = 0; j < static_cast<size_t>(ncols); j++)
105  {
106  A(i,j) = rcppA(i,j);
107  }
108  }
109  }
110 
116  void randomizeOA(Rcpp::IntegerMatrix & oa, int q);
117 
118 } // end namespace
119 
120 #endif /* OA_R_UTILS_H */
121 
oarutils::convertToMatrix
void convertToMatrix(const U &rcppA, bclib::matrix< T > &A)
Definition: oa_r_utils.h:94
oarutils::convertToIntegerMatrix
void convertToIntegerMatrix(const bclib::matrix< T > &A, Rcpp::IntegerMatrix &rcppA)
Definition: oa_r_utils.h:42
oarutils::randomizeOA
void randomizeOA(Rcpp::IntegerMatrix &oa, int q)
Definition: oa_r_utils.cpp:25
rutils.h
oarutils::convertToRcppMatrix
void convertToRcppMatrix(const bclib::matrix< T > &A, U &rcppA)
Definition: oa_r_utils.h:68
oarutils
Definition: oa_r_utils.cpp:23