forked from jMotif/jmotif-R
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
44 lines (40 loc) · 1.04 KB
/
utils.cpp
File metadata and controls
44 lines (40 loc) · 1.04 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
#include <RcppArmadillo.h>
using namespace Rcpp ;
//
#include <jmotif.h>
//
//' Extracts a subseries.
//'
//' @param ts the input timeseries (0-based, left inclusive).
//' @param start the interval start.
//' @param end the interval end.
//' @useDynLib jmotif
//' @export
//' @examples
//' y = c(-1, -2, -1, 0, 2, 1, 1, 0)
//' subseries(y, 0, 3)
// [[Rcpp::export]]
NumericVector subseries(NumericVector ts, int start, int end) {
if(start<0 || end>ts.length()){
stop("provided start and stop indexes are invalid.");
}
NumericVector res(end-start);
for (int i=start; i<end; i++) {
res[i-start] = ts[i];
}
return res;
}
// subseries extraction, more performant way...
//
std::vector<double> _subseries(std::vector<double> *ts, int start, int end) {
std::vector<double>::const_iterator first = ts->begin() + start;
std::vector<double>::const_iterator last = ts->begin() + end;
std::vector<double> res(first, last);
return res;
}
// the random generator wrapper
//
int armaRand() {
arma::ivec x = arma::randi(1);
return x(0);
}