-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
seq.cpp
92 lines (84 loc) · 3.77 KB
/
seq.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <r2arma.h>
//' @title Generate an integer sequence of values
//' @description Creates a vector containing a sequence of values starting at the initial point and going to the terminal point.
//' @param a A \code{long int} that denotes the starting point.
//' @param b A \code{long int} that denotes the ending point.
//' @return A \code{vector} containing integer values from
//' @seealso \code{\link{rwishart}}
//' @author James J Balamuta
//' @backref src/seq.cpp
//' @backref inst/include/seq.h
//' @examples
//' # Call with the following data:
//' seq_int(3, 5)
//' seq_int(5, 3)
// [[Rcpp::export]]
arma::vec seq_int(long int a, long int b){
long int d = std::abs(b-a)+1;
return arma::linspace(a, b, d);
}
//' @title Generate a sequence of values ranging from a to b given a fixed amount of points.
//' @description Creates a vector containing a sequence of values starting at the initial point and going to the terminal point.
//' @param from A \code{long double} that denotes the starting point.
//' @param to A \code{long double} indicating the end point.
//' @param length_out A \code{long unsigned int} that denotes the number of points to use.
//' @return A \code{vector} containing values moving from \eqn{[from,to]}.
//' @seealso \code{\link{seq}}
//' @author Anthony R. Colombo, James J Balamuta
//' @backref src/seq.cpp
//' @backref inst/include/seq.h
//' @examples
//' # Call with the following data:
//' seq_default(1, 2, 10)
//' seq_default(2, 1, 10)
// [[Rcpp::export]]
arma::vec seq_default(long double from, long double to, long unsigned int length_out){
return arma::linspace(from, to, length_out);
}
//' @title Generate a sequence of values ranging from -a to a given a fixed amount of points.
//' @description Creates a vector containing a sequence of values starting at the initial point and going to the terminal point.
//' @param a A \code{long double} that denotes the starting point.
//' @param length_out A \code{long unsigned int} that denotes the number of points to use.
//' @return A \code{vector} of length \code{length_out} that contains values in \eqn{[-a,a]}.
//' @seealso \code{\link{seq}}
//' @author Anthony R. Colombo, James J Balamuta
//' @examples
//' # Call with the following data:
//' seq_default_a(1, 10)
//' seq_default_a(1, 10)
// [[Rcpp::export]]
arma::vec seq_default_a(long double a, long double length_out){
return seq_default(-a, a, length_out);
}
//' @title Generate a sequence of values ranging from vector start to vector end
//' @description Creates a vector containing a sequence of values starting at the beginning and going to the end.
//' @param along_with A \code{vec} with length \eqn{n}.
//' @return A \code{vector} of length \eqn{n} that contains integer values in \eqn{[0, n - 1]}.
//' @seealso \code{\link{seq}}
//' @author James J Balamuta
//' @backref src/seq.cpp
//' @backref inst/include/seq.h
//' @examples
//' # Call with the following data:
//' seq_along_cpp(1:10)
//' seq_along_cpp(5:10)
// [[Rcpp::export]]
arma::vec seq_along_cpp(const arma::vec& along_with){
return seq_len_cpp(along_with.n_elem);
}
//' @title Generate a sequence of values ranging from 0 to n-1
//' @description Creates a vector containing a sequence of values starting at the initial point and going to the terminal point.
//' @param length_out An \code{long unsigned int} that denotes the number of points to use.
//' @return A \code{vector} of length \code{length_out} that contains integer values in \eqn{[0, length_out - 1]}.
//' @seealso \code{\link{seq}}
//' @author James J Balamuta
//' @backref src/seq.cpp
//' @backref inst/include/seq.h
//' @examples
//' # Call with the following data:
//' seq_len_cpp(2)
//' seq_len_cpp(4)
// [[Rcpp::export]]
arma::vec seq_len_cpp(long unsigned int length_out){
return arma::linspace(0, length_out - 1, length_out);
}