29 void mergeTimes(
const std::vector<std::vector<Time> >& times,
30 std::vector<Time>& mergedTimes,
31 std::vector<std::valarray<bool> >& isPresent) {
33 std::vector<Time> allTimes;
34 for (
const auto& time : times) {
35 allTimes.insert(allTimes.end(), time.begin(), time.end());
39 std::sort(allTimes.begin(), allTimes.end());
40 auto end = std::unique(allTimes.begin(), allTimes.end());
42 mergedTimes.insert(mergedTimes.end(),
43 allTimes.begin(), end);
45 isPresent.resize(times.size());
46 for (
Size i=0; i<times.size(); i++) {
47 isPresent[i].resize(allTimes.size());
48 for (
Size j=0; j<allTimes.size(); j++) {
49 isPresent[i][j] = std::binary_search(times[i].begin(),
56 std::valarray<bool>
isInSubset(
const std::vector<Time>& set,
57 const std::vector<Time>& subset) {
59 std::valarray<bool> result(
false,set.size());
60 Size dimsubSet = subset.size();
63 Size dimSet = set.size();
64 Time setElement, subsetElement;
67 "set is required to be larger or equal than subset");
69 for (
Size i=0; i<dimSet; ++i) {
73 subsetElement = subset[j];
76 if (setElement < subsetElement)
79 if (setElement == subsetElement) {
93 Size nTimes = times.size();
95 "at least one time is required");
97 "first time (" << times[0] <<
98 ") must be greater than zero");
99 for (
Size i=0; i<nTimes-1; ++i)
101 "non increasing rate times: "
102 "times[" << i <<
"]=" << times[i] <<
", "
103 "times[" << i+1 <<
"]=" << times[i+1]);
107 std::vector<Time>& taus) {
108 Size nTimes = times.size();
110 "at least two times are required, " << nTimes <<
" provided");
112 "first time (" << times[0] <<
113 ") must be greater than zero");
114 if (taus.size()!=nTimes-1)
115 taus.resize(nTimes-1);
116 for (
Size i=0; i<nTimes-1; ++i) {
117 taus[i]=times[i+1]-times[i];
119 "non increasing rate times: "
120 "times[" << i <<
"]=" << times[i] <<
", "
121 "times[" << i+1 <<
"]=" << times[i+1]);
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
std::valarray< bool > isInSubset(const std::vector< Time > &set, const std::vector< Time > &subset)
void mergeTimes(const std::vector< std::vector< Time > > ×, std::vector< Time > &mergedTimes, std::vector< std::valarray< bool > > &isPresent)
void checkIncreasingTimesAndCalculateTaus(const std::vector< Time > ×, std::vector< Time > &taus)
void checkIncreasingTimes(const std::vector< Time > ×)
check for strictly increasing times, first time greater than zero