18 vector<double> x,
y, slope;
24 for (
size_t i=0; i<x.size()-1; i++) {
25 slope.push_back((y[i+1]-y[i]) / (x[i+1]-x[i]));
30 if (xfind<=x[0])
return y[0];
31 else if (xfind>=*(--x.end()))
return *(--y.end());
33 i = lower_bound(x.begin(), x.end(), xfind) - x.begin();
34 return y[i]+slope[i]*(xfind-x[i]);
38 if (xfind<=x[0])
return y[0];
39 int i = lower_bound(x.begin(), x.end(), xfind) - x.begin();
54 NumericVector x,
y, slope;
66 for (
int i=0; i<n-1; i++) {
67 slope.push_back((y[i+1]-y[i]) / (x[i+1]-x[i]));
71 x.push_back(xy.first);
72 y.push_back(xy.second);
77 if (xfind<=x[0])
return y[0];
78 else if (xfind>=x[n-1])
return y[n-1]+slope[n-2]*(xfind-x[n-1]);
80 i = lower_bound(x.begin(), x.end(), xfind) - 1 - x.begin();
81 return y[i]+slope[i]*(xfind-x[i]);
85 if (xfind<=x[0])
return y[0];
86 int i = lower_bound(x.begin(), x.end(), xfind) - x.begin();
91 if (yfind<=y[0])
return x[0];
92 else if (yfind>=y[n-1])
return x[n-1]+(yfind-y[n-1])/slope[n-2];
94 i = lower_bound(y.begin(), y.end(), yfind) - 1 - y.begin();
95 return x[i]+(yfind-y[i])/slope[i];
98 double invert(
double yfind,
double xentry) {
99 double yentry = approx(xentry);
100 return invert(yfind - yentry);
104 if (yfind>=y[0])
return x[0];
105 else if (yfind<y[n-1])
return x[n-1]+(yfind-y[n-1])/slope[n-2];
107 i = lower_bound(y.begin(), y.end(), yfind, greater<double>()) - 1 - y.begin();
108 return x[i]+(yfind-y[i])/slope[i];
116 return value<*aset.rbegin() ? *aset.rbegin() : *aset.lower_bound(value);
122 Vector<Rcpp::traits::r_sexptype_traits<T>::rtype>
data;
153 set<I0, greater<I0> >,
154 set<I1, greater<I1> >,
155 set<I2, greater<I2> >,
156 set<I3, greater<I3> >,
157 set<I4, greater<I4> >
159 void insert(I0 key0, I1 key1, I2 key2, I3 key3, I4 key4, Outcome outcome) {
161 get<0>(axis).insert(key0);
162 get<1>(axis).insert(key1);
163 get<2>(axis).insert(key2);
164 get<3>(axis).insert(key3);
165 get<4>(axis).insert(key4);
168 virtual Outcome
operator()(I0 i0, I1 i1, I2 i2, I3 i3, I4 i4) {
175 Table(
const DataFrame & df,
string s0,
string s1,
string s2,
string s3,
string s4,
string s5) {
182 for (
int i=0; i<df0.
size(); i++) {
183 insert(df0[i],df1[i],df2[i],df3[i],df4[i], df5[i]);
188 map<key_type,mapped_type>
data;
191 template<
class I0,
class I1,
class I2,
class I3,
class Outcome>
197 set<I0, greater<I0> >,
198 set<I1, greater<I1> >,
199 set<I2, greater<I2> >,
200 set<I3, greater<I3> >
205 get<0>(axis).insert(key0);
206 get<1>(axis).insert(key1);
207 get<2>(axis).insert(key2);
208 get<3>(axis).insert(key3);
217 Table(
const DataFrame & df,
string s0,
string s1,
string s2,
string s3,
string s4) {
223 for (
int i=0; i<df0.
size(); i++) {
224 insert(df0[i],df1[i],df2[i],df3[i], df4[i]);
229 map<key_type,mapped_type>
data;
232 template<
class I0,
class I1,
class I2,
class Outcome>
238 set<I0, greater<I0> >,
239 set<I1, greater<I1> >,
240 set<I2, greater<I2> >
245 get<0>(axis).insert(key0);
246 get<1>(axis).insert(key1);
247 get<2>(axis).insert(key2);
255 Table(
const DataFrame & df,
string s0,
string s1,
string s2,
string s3) {
260 for (
int i=0; i<df0.
size(); i++) {
261 insert(df0[i],df1[i],df2[i], df3[i]);
266 map<key_type,mapped_type>
data;
269 template<
class I0,
class I1,
class Outcome>
275 set<I0, greater<I0> >,
276 set<I1, greater<I1> >
281 get<0>(axis).insert(key0);
282 get<1>(axis).insert(key1);
289 Table(
const DataFrame & df,
string s0,
string s1,
string s2) {
293 for (
int i=0; i<df0.
size(); i++) {
294 insert(df0[i],df1[i], df2[i]);
299 map<key_type,mapped_type>
data;
302 template<
class key_type,
class mapped_type>
305 typedef set<key_type, greater<key_type> >
Axis;
307 void insert(
const key_type& key,
const mapped_type& outcome) {
314 Table(
const DataFrame & df,
string s0,
string s1) {
317 for (
int i=0; i<df0.
size(); i++) {
318 insert(key_type(df0[i]), mapped_type(df1[i]));
323 map<key_type,mapped_type>
data;