19 #ifndef ZTIME_VECTOR_HPP
20 #define ZTIME_VECTOR_HPP
24 #include "../vector.hpp"
25 #include "../globals.hpp"
26 #include "../misc.hpp"
27 #include "../pseudovector.hpp"
29 #include "interval.hpp"
51 template <
typename T,
typename U>
54 v(v_p), scalar(v.size() == 1), first_elt(v[0]),
tz(tz_p) { }
55 inline const U operator[](
size_t i)
const {
return scalar ? first_elt : v[i]; }
57 inline const T plus(T t, U u)
const {
return tz::plus(t, u,
tz); }
67 template <
typename I,
typename NANF,
68 typename DS,
typename DE>
75 size_t ix = 0, iy = 0;
79 for (iy=0; iy<y.size(); iy++) {
80 auto ystart = start.plus(y[iy], start[iy]);
81 auto yend = end.plus(y[iy], end[iy]);
85 while (ix <= x.size() && x[ix] < ystart) ++ix;
86 if (ix >= x.size() || x[ix] > yend) {
87 res.push_back(NANF::f());
92 while (ix+1 < x.size() && x[ix+1] <= yend && tz::abs(x[ix] - y[iy]) > tz::abs(x[ix+1] - y[iy])) ++ix;
93 res.push_back(ix + 1);
102 template <
typename T,
typename NANF,
103 typename DS,
typename DE>
111 size_t ix = 0, iy = 0;
113 if (xdata.size() != x.size())
throw std::out_of_range(
"'xdata' must have same size as 'x'");
117 for (iy=0; iy<y.size(); iy++) {
118 auto ystart = start.plus(y[iy], start[iy]);
119 auto yend = end.plus(y[iy], end[iy]);
123 while (ix < x.size() && x[ix] < ystart) ++ix;
124 if (ix >= x.size() || x[ix] > yend) {
125 ydata.push_back(NANF::f());
130 while (ix+1 < x.size() && x[ix+1] <= yend && tz::abs(x[ix] - y[iy]) > tz::abs(x[ix+1] - y[iy]))
132 ydata.push_back(xdata[ix]);
137 template <
typename T,
typename F,
138 typename DS,
typename DE>
146 size_t ix = 0, iy = 0;
148 if (xdata.size() != x.size())
throw std::out_of_range(
"'xdata' must have same size as 'x'");
152 for (iy=0; iy<y.size(); iy++) {
153 auto ystart = start.plus(y[iy], start[iy]);
154 auto yend = end.plus(y[iy], end[iy]);
158 auto iter = std::lower_bound(x.begin() + ix, x.end(), ystart);
159 ix = iter - x.begin();
161 if (ix >= x.size() || x[ix] >= yend) {
162 ydata.push_back(F::f(xdata.end(), xdata.end()));
169 iter = std::lower_bound(x.begin() + ix, x.end(), yend);
170 ix = iter - x.begin();
171 while (ix < x.size() && x[ix] < yend) ++ix;
174 ydata.push_back(F::f(istart, iend));
182 template <
typename T,
typename F>
190 if (xdata.size() != x.size())
throw std::out_of_range(
"'xdata' must have same size as 'x'");
194 auto from_yiter = y.begin();
195 for (ix=0; ix<x.size(); ix++) {
196 auto to_yiter = std::lower_bound(from_yiter, y.end(), x[ix]);
197 if (to_yiter == y.end())
continue;
199 auto iy_s = from_yiter-y.begin();
200 auto iy_e = to_yiter-y.begin();
201 F::f(xdata[ix], ydata.begin() + iy_s, ydata.begin() + iy_e);
203 from_yiter = to_yiter;