Boost logo

Boost Users :

Subject: [Boost-users] [accumulators] Strange behavior while extracting min using UDT
From: dhruva (dhruva_at_[hidden])
Date: 2009-02-25 04:31:44


Hi, The following code when compiled by defining UDT will use a UDT as Sample (without the define, will use double). Some part of code is creating an object (when UDT) is used as acc_sample(0) and that is shown in min. In the following example, I am adding 3 samples and the count confirms that. However, on extracting the min, I get a value that I have not added (and this is created by the following call stack on windows XP using MSVC 2005) ntdll.dll!_DbgBreakPoint_at_0() acc.exe!acc_sample::acc_sample(double v=0.00000000000000000) Line 35 C++ > acc.exe!std::numeric_limits<acc_sample>::max() Line 109 + 0x10 bytes C++ acc.exe!boost::numeric::functional::as_max_base<acc_sample const ,void>::operator()(const acc_sample & __formal={...}) Line 302 + 0x9 bytes C++ acc.exe!boost::detail::function1<boost::numeric::functional::as_max<boost::mpl::arg<-1>,boost::numeric::functional::tag<boost::mpl::arg<-1> > > >::operator()<acc_sample>(const acc_sample & a0={...}) Line 69 + 0x10 bytes C++ acc.exe!boost::accumulators::impl::min_impl<acc_sample>::min_impl<acc_sample><boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator,boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void> >,boost::parameter::aux::empty_arg_list> >(const
 boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator,boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void> >,boost::parameter::aux::empty_arg_list> & args={...}) Line 38 C++ acc.exe!boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min>::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min><boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator,boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void> >,boost::parameter::aux::empty_arg_list> >(const
 boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator,boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void> >,boost::parameter::aux::empty_arg_list> & args={...}) Line 284 C++ acc.exe!boost::accumulators::detail::build_acc_list<boost::fusion::mpl_iterator<boost::mpl::v_iter<boost::mpl::vector2<boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::count_impl,boost::accumulators::tag::count>,boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min> >,1> >,boost::fusion::mpl_iterator<boost::mpl::v_iter<boost::mpl::vector2<boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::count_impl,boost::accumulators::tag::count>,boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min> >,2>
>,0>::call<boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator,boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void> >,boost::parameter::aux::empty_arg_list> >(const
 boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator,boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void> >,boost::parameter::aux::empty_arg_list> & args={...}, const boost::fusion::mpl_iterator<boost::mpl::v_iter<boost::mpl::vector2<boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::count_impl,boost::accumulators::tag::count>,boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min> >,1> > & f={...}, const
 boost::fusion::mpl_iterator<boost::mpl::v_iter<boost::mpl::vector2<boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::count_impl,boost::accumulators::tag::count>,boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min> >,2> > & l={...}) Line 215 + 0xc bytes C++ acc.exe!boost::accumulators::detail::build_acc_list<boost::fusion::mpl_iterator<boost::mpl::v_iter<boost::mpl::vector2<boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::count_impl,boost::accumulators::tag::count>,boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min> >,0> >,boost::fusion::mpl_iterator<boost::mpl::v_iter<boost::mpl::vector2<boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::count_impl,boost::accumulators::tag::count>,boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min> >,2>
>,0>::call<boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator,boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void> >,boost::parameter::aux::empty_arg_list> >(const
 boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator,boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void> >,boost::parameter::aux::empty_arg_list> & args={...}, const boost::fusion::mpl_iterator<boost::mpl::v_iter<boost::mpl::vector2<boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::count_impl,boost::accumulators::tag::count>,boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min> >,0> > & f={...}, const
 boost::fusion::mpl_iterator<boost::mpl::v_iter<boost::mpl::vector2<boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::count_impl,boost::accumulators::tag::count>,boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min> >,2> > & l={...}) Line 215 + 0x2e bytes C++ acc.exe!boost::accumulators::detail::make_acc_list<boost::mpl::vector2<boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::count_impl,boost::accumulators::tag::count>,boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min> >,boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator,boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void> >,boost::parameter::aux::empty_arg_list> >(const
 boost::mpl::vector2<boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::count_impl,boost::accumulators::tag::count>,boost::accumulators::detail::accumulator_wrapper<boost::accumulators::impl::min_impl<acc_sample>,boost::accumulators::tag::min> > & seq={...}, const boost::parameter::aux::arg_list<boost::parameter::aux::tagged_argument<boost::accumulators::tag::accumulator,boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void> >,boost::parameter::aux::empty_arg_list> & args={...}) Line 234 + 0x2f bytes C++ acc.exe!boost::accumulators::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void>::accumulator_set<acc_sample,boost::accumulators::features<boost::accumulators::tag::count,boost::accumulators::tag::min,boost::accumulators::tag::min,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>,void>() Line 146 + 0x31 bytes C++ acc.exe!main(int argc=1, char * * argv=0x00033b18) Line 96 C++ acc.exe!__tmainCRTStartup() Line 327 + 0x12 bytes C kernel32.dll!_BaseProcessStart_at_4() + 0x23 bytes // Sample code starts #include <stdio.h> #include <iostream> #include <vector> #include <boost/accumulators/accumulators.hpp> #include <boost/accumulators/statistics/stats.hpp> #include <boost/accumulators/statistics/count.hpp> #include <boost/accumulators/statistics/min.hpp> #include <boost/accumulators/statistics/max.hpp> using namespace std; namespace bacc = boost::accumulators; using namespace bacc; typedef struct { size_t _time; double _value; } time_val_t; /* Wrapper class as I cannot modify time_val_t */ class acc_sample { public: time_val_t _data; acc_sample() { _data._time = 0; _data._value = 0.0; } /* This should never get called: limits is creating an object with 0 * and this object gets extracted as min */ acc_sample(double v) { abort(); } acc_sample(time_t t, double v) { _data._time = t; _data._value = v; } acc_sample(const time_val_t &i) { _data._time = i._time; _data._value = i._value; } acc_sample(const acc_sample &i) { _data._time = i._data._time; _data._value = i._data._value; } bool operator < (const acc_sample &rhs) const { return _data._value < rhs._data._value; } bool operator > (const acc_sample &rhs) const { return _data._value > rhs._data._value; } bool operator == (const acc_sample &rhs) const { return _data._value == rhs._data._value; } bool operator != (const acc_sample &rhs) const { return _data._value != rhs._data._value; } }; int main(int argc, char *argv[]) { #ifdef UDT typedef acc_sample sample_type; sample_type s1(10, 100); sample_type s2(11, 101); sample_type s3(12, 102); sample_type res; #else typedef int sample_type; sample_type s1 = 100; sample_type s2 = 101; sample_type s3 = 102; sample_type res; #endif #if 0 if (s1 == s1) cout << "==" << endl; if (s1 < s2) cout << "<" << endl; if (s2 > s1) cout << ">" << endl; #endif accumulator_set< sample_type, features< tag::count, tag::max, tag::min > > acc; acc(s1); acc(s2); acc(s3); size_t sz = extract_result< tag::count >(acc); cout << "Count:" << sz << endl; res = extract_result< tag::max >(acc); #ifdef UDT cout << "Max: [" << res._data._time << "," << res._data._value << "]" << endl; #else cout << "Max: [" << res << "]" << endl; #endif res = extract_result< tag::min >(acc); #ifdef UDT cout << "Min: [" << res._data._time << "," << res._data._value << "]" << endl; #else cout << "Min: [" << res << "]" << endl; #endif return 0; } // Sample code ends Looking for any help or leads would be of real help. regards, -dhruva Check out the all-new Messenger 9.0! Go to http://in.messenger.yahoo.com/


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net