TEST(tagged, float_32) { ASSERT_EQ(sizeof(uint32_t), sizeof(float32_t)); value_t one = new_float_32(1.0); ASSERT_TRUE(get_float_32_value(one) == 1.0); value_t zero = new_float_32(0.0); ASSERT_TRUE(get_float_32_value(zero) == 0.0); value_t minus_one = new_float_32(-1.0); ASSERT_TRUE(get_float_32_value(minus_one) == -1.0); ASSERT_VALEQ(equal(), value_ordering_compare(one, one)); ASSERT_VALEQ(equal(), value_ordering_compare(zero, zero)); ASSERT_VALEQ(equal(), value_ordering_compare(minus_one, minus_one)); ASSERT_VALEQ(less_than(), value_ordering_compare(minus_one, zero)); ASSERT_VALEQ(less_than(), value_ordering_compare(zero, one)); ASSERT_VALEQ(greater_than(), value_ordering_compare(zero, minus_one)); ASSERT_VALEQ(greater_than(), value_ordering_compare(one, zero)); value_t nan = float_32_nan(); ASSERT_VALEQ(unordered(), value_ordering_compare(nan, nan)); ASSERT_VALEQ(unordered(), value_ordering_compare(nan, one)); ASSERT_VALEQ(unordered(), value_ordering_compare(nan, zero)); ASSERT_VALEQ(unordered(), value_ordering_compare(zero, nan)); ASSERT_VALEQ(unordered(), value_ordering_compare(one, nan)); ASSERT_SAME(nan, nan); value_t inf = float_32_infinity(); value_t minf = float_32_minus_infinity(); ASSERT_VALEQ(unordered(), value_ordering_compare(nan, inf)); ASSERT_VALEQ(unordered(), value_ordering_compare(inf, nan)); ASSERT_VALEQ(unordered(), value_ordering_compare(nan, minf)); ASSERT_VALEQ(unordered(), value_ordering_compare(minf, nan)); ASSERT_VALEQ(less_than(), value_ordering_compare(one, inf)); ASSERT_VALEQ(greater_than(), value_ordering_compare(inf, one)); ASSERT_VALEQ(greater_than(), value_ordering_compare(one, minf)); ASSERT_VALEQ(less_than(), value_ordering_compare(minf, one)); ASSERT_VALEQ(equal(), value_ordering_compare(inf, inf)); ASSERT_VALEQ(greater_than(), value_ordering_compare(inf, minf)); ASSERT_VALEQ(less_than(), value_ordering_compare(minf, inf)); ASSERT_TRUE(is_float_32_nan(nan)); ASSERT_FALSE(is_float_32_nan(minus_one)); ASSERT_FALSE(is_float_32_nan(zero)); ASSERT_FALSE(is_float_32_nan(one)); ASSERT_FALSE(is_float_32_nan(inf)); ASSERT_FALSE(is_float_32_nan(minf)); ASSERT_FALSE(is_float_32_finite(nan)); ASSERT_TRUE(is_float_32_finite(minus_one)); ASSERT_TRUE(is_float_32_finite(zero)); ASSERT_TRUE(is_float_32_finite(one)); ASSERT_FALSE(is_float_32_finite(inf)); ASSERT_FALSE(is_float_32_finite(minf)); }
void RTree::Trunk::insert( Leaf *leaf ) { int i; for( i = 1; i < num_children; ++i ) { if( greater_than( leaf, children[i] ) ) { break; } } children[i-1]->insert( leaf ); }
TEST(tagged, relation) { ASSERT_TRUE(test_relation(less_than(), reLessThan)); ASSERT_TRUE(test_relation(less_than(), reLessThan | reEqual)); ASSERT_FALSE(test_relation(less_than(), reEqual)); ASSERT_FALSE(test_relation(less_than(), reGreaterThan)); ASSERT_FALSE(test_relation(less_than(), reGreaterThan | reEqual)); ASSERT_FALSE(test_relation(less_than(), reUnordered)); ASSERT_FALSE(test_relation(equal(), reLessThan)); ASSERT_TRUE(test_relation(equal(), reLessThan | reEqual)); ASSERT_TRUE(test_relation(equal(), reEqual)); ASSERT_FALSE(test_relation(equal(), reGreaterThan)); ASSERT_TRUE(test_relation(equal(), reGreaterThan | reEqual)); ASSERT_FALSE(test_relation(equal(), reUnordered)); ASSERT_FALSE(test_relation(greater_than(), reLessThan)); ASSERT_FALSE(test_relation(greater_than(), reLessThan | reEqual)); ASSERT_FALSE(test_relation(greater_than(), reEqual)); ASSERT_TRUE(test_relation(greater_than(), reGreaterThan)); ASSERT_TRUE(test_relation(greater_than(), reGreaterThan | reEqual)); ASSERT_FALSE(test_relation(greater_than(), reUnordered)); ASSERT_FALSE(test_relation(unordered(), reLessThan)); ASSERT_FALSE(test_relation(unordered(), reLessThan | reEqual)); ASSERT_FALSE(test_relation(unordered(), reEqual)); ASSERT_FALSE(test_relation(unordered(), reGreaterThan)); ASSERT_FALSE(test_relation(unordered(), reGreaterThan | reEqual)); ASSERT_TRUE(test_relation(unordered(), reUnordered)); }
/* *-------------------------------------------------------------------------------------- * Class: RTree::Root * Method: RTree::Root :: insert * Description: Root inserts leaves by sending it to the correct child to be inserted * into the first branch that it hits. *-------------------------------------------------------------------------------------- */ void RTree::Root::insert( RTree::Leaf *leaf ) { if( num_children == 0 ) { // Root should never have any leaves as children so a Branch is created // if there isn't one already children[0] = new Branch(); children[0]->adopt( this ); num_children = 1; children[0]->insert( leaf ); } else { //if( num_children == 1 ) { int i; for( i = 1; i < num_children; ++i ) { if( greater_than( leaf, children[i] ) ) { break; } } children[i-1]->insert( leaf ); } }
/*! * @brief Displays rate info about the timer. * * This function prints a load of information about the rate of a timer's start times * to the console. * * @param timer The timer for which info should be shown. * @param show_all After the average, etc. show all periods, 1 per line. Set false if * only a summary of the times is needed. * * @return 0 if successful */ void timing_print_rate_info(TIMING_TIMER_T * timer, bool show_all) { int i; struct timeval lowest_elapsed_time = {100000000, 0}; int lowest_elapsed_time_index = 0; struct timeval highest_elapsed_time = {0, 0}; int highest_elapsed_time_index = 0; int rate; unsigned long std_dev = 0; int elapsed_usec; int average_usec; struct timeval elapsed_time = {0, 0}; struct timeval total_elapsed_time = {0, 0}; struct timeval average_elapsed_time = {0, 0}; struct timeval delta; /* Since we are looking at the start times for rate information, we need two times stored * for one period, three times for two periods, etc. */ int num_periods = timer->num_times_recorded - 1; /* There's no point in continuing if there is insufficient information available * to show period information. */ if(num_periods <= 0) { tracemsg(_a("Rate info: %d timer start/stops is insufficient for rate analysis."), timer->num_times_recorded); return; } tracemsg(_a("Rate info: number of periods captured: %d"), num_periods); /* Go figure out some info about the timers captured. */ for(i = 0; i < num_periods; i++) { /* Get elapsed_time between the two start times. */ subtract(&(timer->times[i].start_time), &(timer->times[i+1].start_time), &elapsed_time); /* Check elapsed time against highest. */ if(greater_than(&elapsed_time, &highest_elapsed_time)) { highest_elapsed_time.tv_sec = elapsed_time.tv_sec; highest_elapsed_time.tv_usec = elapsed_time.tv_usec; highest_elapsed_time_index = i; } /* Check elapsed time against lowest. */ if(less_than(&elapsed_time, &lowest_elapsed_time)) { lowest_elapsed_time.tv_sec = elapsed_time.tv_sec; lowest_elapsed_time.tv_usec = elapsed_time.tv_usec; lowest_elapsed_time_index = i; } /* Add this elapsed time to total. */ add(&elapsed_time, &total_elapsed_time, &total_elapsed_time); if(false) { tracemsg(_a(" result %4d: elapsed time %2lds, %6ld usec"), i, elapsed_time.tv_sec, elapsed_time.tv_usec); } } /* Figure out the average elapsed time. */ average(&total_elapsed_time, timer->num_times_recorded, &average_elapsed_time); rate = rate_per_sec(&average_elapsed_time); tracemsg(_a(" Average period %2lds, %6ld usec (%d/sec)"), average_elapsed_time.tv_sec, average_elapsed_time.tv_usec, rate); /* Figure out standard deviation for the set of periods. */ average_usec = USECS(average_elapsed_time); for(i = 0; i < num_periods; i++) { /* Get elapsed_time between the two start times. */ subtract(&(timer->times[i].start_time), &(timer->times[i+1].start_time), &elapsed_time); elapsed_usec = USECS(elapsed_time); std_dev += ((elapsed_usec - average_usec) * (elapsed_usec - average_usec)); } std_dev = std_dev / i; /* Rounding error shouldn't matter too much.*/ std_dev = square_root(std_dev); tracemsg(_a(" Approx std dev %6ld usec"), std_dev); /* For highest time recorded, figure out delta between this and average. */ subtract(&average_elapsed_time, &highest_elapsed_time, &delta); rate = rate_per_sec(&highest_elapsed_time); tracemsg(_a(" Highest period %2lds, %6ld usec (%3d/sec, delta from avg %lds, %6ld us, result %d)"), highest_elapsed_time.tv_sec, highest_elapsed_time.tv_usec, rate, delta.tv_sec, delta.tv_usec, highest_elapsed_time_index); /* Same for lowest. */ subtract(&lowest_elapsed_time, &average_elapsed_time, &delta); rate = rate_per_sec(&lowest_elapsed_time); tracemsg(_a(" Lowest period %2lds, %6ld usec (%3d/sec, delta from avg %lds, %6ld us, result %d)"), lowest_elapsed_time.tv_sec, lowest_elapsed_time.tv_usec, rate, delta.tv_sec, delta.tv_usec, lowest_elapsed_time_index); /* If told to show everything, dump all of the values to text in units of microseconds. * Put commas before and after each value to make this easier to import into excel or * whatever as CSV as there's some sort of timestamp prepended to every printk these days... */ if(show_all) { tracemsg(_a("")); tracemsg(_a(" All periods recorded (usecs):")); for(i = 0; i < num_periods; i++) { subtract(&(timer->times[i].start_time), &(timer->times[i+1].start_time), &elapsed_time); tracemsg(",%ld,\n", USECS(elapsed_time)); } } } /* End of rate info. */
/*! * @brief Displays info about the timer. * * This function prints a load of information about the captured timing information * to the console. * * @param timer The timer for which info should be shown. * @param show_all After the average, etc. show all elapsed times, 1 per line. * Set false if only a summary of the times is needed. * * @return 0 if successful */ void timing_print_info(TIMING_TIMER_T * timer, bool show_all) { int i; struct timeval lowest_elapsed_time = {100000000, 0}; int lowest_elapsed_time_index = 0; struct timeval highest_elapsed_time = {0, 0}; int highest_elapsed_time_index = 0; unsigned long std_dev = 0; int elapsed_usec; int average_usec; struct timeval elapsed_time = {0, 0}; struct timeval total_elapsed_time = {0, 0}; struct timeval average_elapsed_time = {0, 0}; struct timeval delta; if(timer != NULL) { if(timer->num_times_recorded == 0) { tracemsg(_a("\nTiming: no results captured.")); return; } tracemsg(_a("Timing: number of results captured: %d"), timer->num_times_recorded); /* Go figure out some info about the timers captured. */ for(i = 0; i < timer->num_times_recorded; i++) { /* Get elapsed_time. */ subtract(&(timer->times[i].start_time), &(timer->times[i].stop_time), &elapsed_time); /* Check elapsed time against highest. */ if(greater_than(&elapsed_time, &highest_elapsed_time)) { highest_elapsed_time.tv_sec = elapsed_time.tv_sec; highest_elapsed_time.tv_usec = elapsed_time.tv_usec; highest_elapsed_time_index = i; } /* Check elapsed time against lowest. */ if(less_than(&elapsed_time, &lowest_elapsed_time)) { lowest_elapsed_time.tv_sec = elapsed_time.tv_sec; lowest_elapsed_time.tv_usec = elapsed_time.tv_usec; lowest_elapsed_time_index = i; } /* Add this elapsed time to total. */ add(&elapsed_time, &total_elapsed_time, &total_elapsed_time); if(show_all) { tracemsg(_a(" result %4d: elapsed time %2lds, %6ld usec"), i, elapsed_time.tv_sec, elapsed_time.tv_usec); } } /* Figure out the average elapsed time. */ average(&total_elapsed_time, timer->num_times_recorded, &average_elapsed_time); tracemsg(_a("Average elapsed %2lds, %6ld usec"), average_elapsed_time.tv_sec, average_elapsed_time.tv_usec); /* Figure out standard deviation for the set of elapsed times. This needs to be * done after the average is calculated. */ average_usec = USECS(average_elapsed_time); for(i = 0; i < timer->num_times_recorded; i++) { /* Get elapsed_time between the start and stop. */ subtract(&(timer->times[i].start_time), &(timer->times[i].stop_time), &elapsed_time); elapsed_usec = USECS(elapsed_time); std_dev += ((elapsed_usec - average_usec) * (elapsed_usec - average_usec)); } std_dev = std_dev / i; /* Rounding error shouldn't matter too much.*/ std_dev = square_root(std_dev); tracemsg(_a(" Approx std dev %6ld usec"), std_dev); /* For highest time recorded, figure out delta between this and average. */ subtract(&average_elapsed_time, &highest_elapsed_time, &delta); tracemsg(_a("Highest elapsed %2lds, %6ld usec (delta from avg %lds, %6ldus, result %d)"), highest_elapsed_time.tv_sec, highest_elapsed_time.tv_usec, delta.tv_sec, delta.tv_usec, highest_elapsed_time_index); /* Same for lowest. */ subtract(&lowest_elapsed_time, &average_elapsed_time, &delta); tracemsg(_a(" Lowest elapsed %2lds, %6ld usec (delta from avg %lds, %6ldus, result %d)"), lowest_elapsed_time.tv_sec, lowest_elapsed_time.tv_usec, delta.tv_sec, delta.tv_usec, lowest_elapsed_time_index); } }
bool operator()(Tag tag1, Tag tag2) //const { return greater_than((*parent_ptr).relevance( tag1), (*parent_ptr).relevance( tag2)); }
// positive starts from end of direction // negative starts from base of direction point<T,D> extrapolate( T distance ) const { T t = distance / base_t::m_vector.length( ); if( greater_than( distance, 0 ) ) { t += 1; } point<T,D> result = base_t::m_point + t * base_t::m_vector; return result; }
point<T,2> extrapolate_y( T y ) const { T t = y / base_t::m_vector[1]; if( greater_than( y, 0 ) ) { t += 1; } return point<T,2>{ base_t::m_point + t * base_t::m_vector }; }
point<T,2> extrapolate_x( T x ) const { T t = x / base_t::m_vector[0]; if( greater_than( x, 0 ) ) { t += 1; } return point<T,2>{ base_t::m_point + t * base_t::m_vector }; }
//////////////////////////////////////////////// // positive starts from end of direction // negative starts from base of direction // for all interpolate/extrapolate functions point<T,2> extrapolate( T distance ) const { T t = distance / base_t::m_vector.length( ); if( greater_than( distance, 0 ) ) { t += 1; } return point<T,2>{ base_t::m_point + t * base_t::m_vector }; }
constexpr bool less_than_equal(const T & lhs, const U & rhs) { return ! greater_than(lhs, rhs); }
bool GreaterThan::execute(const AnyAtomicType::Ptr &atom1, const AnyAtomicType::Ptr &atom2, DynamicContext *context) const { return greater_than(atom1, atom2, context->getDefaultCollation(this), context, this); }
int main() { static_assert(greater_than(1, 0), "Oops"); // static_assert(greater_than(1, 4), "Oops"); // this fails }
/* * Clips segments agains a box */ void clip(Route& src, Route& sink, const Box& bounds) { LOG_DEBUG(src.size()); for (const SegmentPtr segPtr : segments(src)) { Segment& seg = *segPtr.get(); double width = bounds.width(); double height = bounds.height(); Segment leftBedBorder(Point(0, 0), Point(0, height - 1)); Segment bottomBedBorder(Point(0, height - 1), Point(width - 1, height - 1)); Segment rightBedBorder(Point(width - 1, height - 1), Point(width - 1, 0)); Segment topBedBorder(Point(width - 1, 0), Point(0, 0)); Point intersection; Segment clipped = seg; if (clipped.first.x < 0 || clipped.second.x < 0 || clipped.first.y < 0 || clipped.second.y < 0 || clipped.first.x > width - 1 || clipped.second.x > width - 1 || clipped.first.y > height - 1 || clipped.second.y > height - 1) { if (clipped.first.x < 0 || clipped.second.x < 0) { // out of bounds; if (clipped.first.x < 0 && clipped.second.x < 0) { continue; } if (intersects(clipped, leftBedBorder, intersection) == ALIGN_INTERSECT) { if (clipped.first.x >= clipped.second.x) clipped.second = clipped.first; clipped.first = intersection; intersection = Point(); } } if (clipped.first.y < 0 || clipped.second.y < 0) { if (clipped.first.y < 0 && clipped.second.y < 0) { continue; } if (intersects(clipped, topBedBorder, intersection) == ALIGN_INTERSECT) { if (clipped.first.y >= clipped.second.y) clipped.second = clipped.first; clipped.first = intersection; intersection = Point(); } } if (greater_than(clipped.first.x, width - 1) || greater_than(clipped.second.x, width - 1)) { if (greater_than(clipped.first.x, width - 1) && greater_than(clipped.second.x, width - 1)) { continue; } if (intersects(clipped, rightBedBorder, intersection) == ALIGN_INTERSECT) { if (clipped.first.x <= clipped.second.x) clipped.second = clipped.first; clipped.first = intersection; intersection = Point(); } } if (clipped.first.y > height - 1 || clipped.second.y > height - 1) { if (clipped.first.y > height - 1 && clipped.second.y > height - 1) { continue; } if (intersects(clipped, bottomBedBorder, intersection) == ALIGN_INTERSECT) { if (clipped.first.y <= clipped.second.y) clipped.second = clipped.first; clipped.first = intersection; } } } add(sink, clipped); } LOG_DEBUG(sink.size()); }
void ComputeOrImprovePath() { while (1) { if (timesExpanded > MAX_TIMES_EXPANDED) { planningFailed = true; return; } Node *s1 = open->peekTop(); if (s1 == 0) { planningFailed = true; return; } if (less_than(s1->key.k1, startNode->key.k1) || (equals(s1->key.k1, startNode->key.k1) && less_than(s1->key.k2, startNode->key.k2)) || (greater_than(startNode->rhs, startNode->g)) || (startNode->rhs == DOUBLE_INF && startNode->g == DOUBLE_INF)) ; else break; Node *s = open->removeTop(); if (greater_than(s->g, s->rhs)) { s->g = s->rhs; if (!s->inClosed) { s->inClosed = true; closed.push_back(s); } for (int i = 0; i < lattice.n; ++i) { int x = s->x + lattice.dx[i]; int y = s->y + lattice.dy[i]; if (!isInMap(x, y)) continue; Node *v = GetOrCreateNode(x, y); if (s->bptr == v) continue; double newRhs = ComputeCost(v, s->x, s->y); if (greater_than(v->rhs, newRhs)) { v->bptr = s; v->rhs = newRhs; UpdateState(v); } } ++timesExpanded; } else { s->g = DOUBLE_INF; UpdateState(s); for (int i = 0; i < lattice.n; ++i) { int x = s->x + lattice.dx[i]; int y = s->y + lattice.dy[i]; Node *v = GetOrCreateNode(x, y); if (v != goalNode && v->bptr == s) { UpdateRHSandBptr(v); UpdateState(v); } } ++timesExpanded; } } }