Boost logo

Boost :

Subject: Re: [boost] accumulators + complex
From: Neal Becker (ndbecker2_at_[hidden])
Date: 2008-12-19 13:14:38


This seems to work:

namespace boost { namespace accumulators { namespace impl {
      template<typename Sample>
      struct abs_sqr_accumulator
        : accumulator_base {
        typedef typename Sample::value_type result_type;

        template<typename Args>
        abs_sqr_accumulator (Args const& args) {}

        template<typename Args>
        void operator () (Args const& args) {
          this->sum += real (args[sample] * conj (args[sample]));
        }

        template<typename Args>
        result_type result (Args const& args) const {
          return boost::numeric::average (this->sum, count (args));
        }

        result_type sum;
      };
    }}}
namespace boost { namespace accumulators { namespace tag {
      struct abs_sqr
        : depends_on< count > // depends_on<> to specify dependencies
      {
        // Define a nested typedef called 'impl' that specifies which
        // accumulator implements this feature.
        typedef accumulators::impl::abs_sqr_accumulator< mpl::_1 > impl;
      };
    }}}

namespace boost {
  namespace accumulators {
    namespace extract {
      extractor< tag::abs_sqr> const abs_sqr = {};
    }
    using extract::abs_sqr;
  }
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk