-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_array.cpp
More file actions
51 lines (44 loc) · 1.64 KB
/
read_array.cpp
File metadata and controls
51 lines (44 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "read_array.h"
array_2d readEntrantPrev(SEXP entrantPrev) {
std::vector<double> eP = Rcpp::as< std::vector<double> >(entrantPrev);
array_2d entPrev(boost::extents[PROJECTION_YEARS][SEXES]);
std::copy(eP.begin(), eP.end(), entPrev.data());
return entPrev;
}
array_2d readEntrantArtCoverage(SEXP entrantArtCoverage) {
array_2d entPrev(boost::extents[PROJECTION_YEARS][SEXES]);
if (entrantArtCoverage != R_NilValue) {
std::vector<double> artCov = Rcpp::as< std::vector<double> >(entrantArtCoverage);
std::copy(artCov.begin(), artCov.end(), entPrev.data());
} else {
std::fill_n(entPrev.data(), entPrev.num_elements(), 0);
}
return entPrev;
}
array_1d read_1d_array(std::vector<double> arr, int dimensions) {
array_1d A(boost::extents[dimensions]);
std::copy(arr.begin(), arr.end(), A.data());
return A;
}
array_2d read_2d_array(std::vector<double> arr, int dim1, int dim2) {
array_2d A(boost::extents[dim1][dim2]);
std::copy(arr.begin(), arr.end(), A.data());
return A;
}
array_3d read_3d_array(std::vector<double> arr, int dim1, int dim2, int dim3) {
array_3d A(boost::extents[dim1][dim2][dim3]);
std::copy(arr.begin(), arr.end(), A.data());
return A;
}
array_4d read_4d_array(std::vector<double> arr, int dim1, int dim2, int dim3, int dim4) {
array_4d A(boost::extents[dim1][dim2][dim3][dim4]);
std::copy(arr.begin(), arr.end(), A.data());
return A;
}
std::list<array_3d> read_arrays_list(std::list< std::vector<double> > arr_list) {
std::list<array_3d> arrays;
for (std::list< std::vector<double> >::iterator it = arr_list.begin(); it != arr_list.end(); it++) {
arrays.push_back(read_3d_array(*it, 3, 4, 2));
}
return arrays;
}