Hello,
Date: Thu, 25 Jun 2009 03:41:49 -0700 (PDT) From: adish Subject: Re: [Boost-users] [Accumulators] Questions about the library To: boost-users@lists.boost.org
? ?2. If my platform does not support HW floating point ops, and all my ? ?sample values are, e.g. ints, is there a way to specify that the *computation ? ?*and *return value itself* (i.e. result_type, e.g. the mean) will be done ? ?in ints (naturally, at the cost of precision)?
I have used UDT as I needed some extra information from the results (as I was
working on data from a time series). The reverse, using a POD like int must be possible. Instead of the first argument being float/double, use an int. If that does not work, you can wrap an int in a UDT, implement some of the operators like '=', '<', '/' depending on the accumulator you plan to use (I did that as I needed to send a UDT).
Using an int still returns a float -- which is quite sensible.
You might be able to write a custom extractor which can return an int. I have not explored it. I always thought the type you give as input is the type that gets returned.
By UDT do you mean User Defined Type? This is an interesting approach. I didn't realize that the result_type depends on the value type in that way, I didn't see any UDTs mentioned in the docs.
Yes, I mean writing a class/struct. I had to overload '<', '>', '+=' and '/' and I use it for variance, mean, median, min, max and my implementation of percentile. Remember to specialize std::numeric_limits for the UDT you write. Else, the min and/or max will have values that you have not added in the accumulator (garbage values). I had a tough time debugging it and finding the solution. Also, on Windows, you need to derive your specialization from _Num_base. As for implementing a generic rolling type: 1. You need to store your values in a circular buffer. 2. Each time you add a value into the buffer, pass the contents to a pristine accumulator. This may be sub optimal but works. Especially for those calculations where it is not easy to remove the effect of the first data that you want to pop. I had to do it this way because I was dealing with time series. If I want a rolling computation for a 1 hour window, I might add 1 sample and may have to remove more than 1 sample to ensure first-last is 1 hour window in the buffer. -dhruva Love Cricket? Check out live scores, photos, video highlights and more. Click here http://cricket.yahoo.com