7 #include <boost/tuple/tuple.hpp>
8 #include <boost/tuple/tuple_comparison.hpp>
19 vector<double> x,
y, slope;
25 for (
size_t i=0; i<x.size()-1; i++) {
26 slope.push_back((y[i+1]-y[i]) / (x[i+1]-x[i]));
31 if (xfind<=x[0])
return y[0];
32 else if (xfind>=*(--x.end()))
return *(--y.end());
34 i = lower_bound(x.begin(), x.end(), xfind) - x.begin();
35 return y[i]+slope[i]*(xfind-x[i]);
39 if (xfind<=x[0])
return y[0];
40 int i = lower_bound(x.begin(), x.end(), xfind) - x.begin();
55 NumericVector x,
y, slope;
67 for (
int i=0; i<n-1; i++) {
68 slope.push_back((y[i+1]-y[i]) / (x[i+1]-x[i]));
72 x.push_back(xy.first);
73 y.push_back(xy.second);
78 if (xfind<=x[0])
return y[0];
79 else if (xfind>=x[n-1])
return y[n-1]+slope[n-2]*(xfind-x[n-1]);
81 i = lower_bound(x.begin(), x.end(), xfind) - 1 - x.begin();
82 return y[i]+slope[i]*(xfind-x[i]);
86 if (xfind<=x[0])
return y[0];
87 int i = lower_bound(x.begin(), x.end(), xfind) - x.begin();
92 if (yfind<=y[0])
return x[0];
93 else if (yfind>=y[n-1])
return x[n-1]+(yfind-y[n-1])/slope[n-2];
95 i = lower_bound(y.begin(), y.end(), yfind) - 1 - y.begin();
96 return x[i]+(yfind-y[i])/slope[i];
99 double invert(
double yfind,
double xentry) {
100 double yentry = approx(xentry);
101 return invert(yfind - yentry);
105 if (yfind>=y[0])
return x[0];
106 else if (yfind<y[n-1])
return x[n-1]+(yfind-y[n-1])/slope[n-2];
108 i = lower_bound(y.begin(), y.end(), yfind, greater<double>()) - 1 - y.begin();
109 return x[i]+(yfind-y[i])/slope[i];
117 return value<*aset.rbegin() ? *aset.rbegin() : *aset.lower_bound(value);
123 Vector<Rcpp::traits::r_sexptype_traits<T>::rtype>
data;
153 typedef boost::tuple<
154 set<I0, greater<I0> >,
155 set<I1, greater<I1> >,
156 set<I2, greater<I2> >,
157 set<I3, greater<I3> >,
158 set<I4, greater<I4> >
160 void insert(I0 key0, I1 key1, I2 key2, I3 key3, I4 key4, Outcome outcome) {
162 get<0>(axis).insert(key0);
163 get<1>(axis).insert(key1);
164 get<2>(axis).insert(key2);
165 get<3>(axis).insert(key3);
166 get<4>(axis).insert(key4);
169 virtual Outcome
operator()(I0 i0, I1 i1, I2 i2, I3 i3, I4 i4) {
176 Table(
const DataFrame & df,
string s0,
string s1,
string s2,
string s3,
string s4,
string s5) {
183 for (
int i=0; i<df0.
size(); i++) {
184 insert(df0[i],df1[i],df2[i],df3[i],df4[i], df5[i]);
189 map<key_type,mapped_type>
data;
192 template<
class I0,
class I1,
class I2,
class I3,
class Outcome>
197 typedef boost::tuple<
198 set<I0, greater<I0> >,
199 set<I1, greater<I1> >,
200 set<I2, greater<I2> >,
201 set<I3, greater<I3> >
206 get<0>(axis).insert(key0);
207 get<1>(axis).insert(key1);
208 get<2>(axis).insert(key2);
209 get<3>(axis).insert(key3);
218 Table(
const DataFrame & df,
string s0,
string s1,
string s2,
string s3,
string s4) {
224 for (
int i=0; i<df0.
size(); i++) {
225 insert(df0[i],df1[i],df2[i],df3[i], df4[i]);
230 map<key_type,mapped_type>
data;
233 template<
class I0,
class I1,
class I2,
class Outcome>
238 typedef boost::tuple<
239 set<I0, greater<I0> >,
240 set<I1, greater<I1> >,
241 set<I2, greater<I2> >
246 get<0>(axis).insert(key0);
247 get<1>(axis).insert(key1);
248 get<2>(axis).insert(key2);
256 Table(
const DataFrame & df,
string s0,
string s1,
string s2,
string s3) {
261 for (
int i=0; i<df0.
size(); i++) {
262 insert(df0[i],df1[i],df2[i], df3[i]);
267 map<key_type,mapped_type>
data;
270 template<
class I0,
class I1,
class Outcome>
275 typedef boost::tuple<
276 set<I0, greater<I0> >,
277 set<I1, greater<I1> >
282 get<0>(axis).insert(key0);
283 get<1>(axis).insert(key1);
290 Table(
const DataFrame & df,
string s0,
string s1,
string s2) {
294 for (
int i=0; i<df0.
size(); i++) {
295 insert(df0[i],df1[i], df2[i]);
300 map<key_type,mapped_type>
data;
303 template<
class key_type,
class mapped_type>
306 typedef set<key_type, greater<key_type> >
Axis;
308 void insert(
const key_type& key,
const mapped_type& outcome) {
315 Table(
const DataFrame & df,
string s0,
string s1) {
318 for (
int i=0; i<df0.
size(); i++) {
319 insert(key_type(df0[i]), mapped_type(df1[i]));
324 map<key_type,mapped_type>
data;