]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/accumulators/include/boost/accumulators/statistics/rolling_moment.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / accumulators / include / boost / accumulators / statistics / rolling_moment.hpp
CommitLineData
7c673cae
FG
1///////////////////////////////////////////////////////////////////////////////
2// rolling_moment.hpp
3// Copyright 2005 Eric Niebler.
4// Copyright (C) 2014 Pieter Bastiaan Ober (Integricom).
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005
10#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MOMENT_HPP_EAN_27_11_2005
11
12#include <boost/config/no_tr1/cmath.hpp>
13#include <boost/mpl/int.hpp>
14#include <boost/mpl/assert.hpp>
15#include <boost/mpl/placeholders.hpp>
16#include <boost/accumulators/framework/accumulator_base.hpp>
17#include <boost/accumulators/framework/extractor.hpp>
18#include <boost/accumulators/numeric/functional.hpp>
19#include <boost/accumulators/framework/parameters/sample.hpp>
20#include <boost/accumulators/framework/depends_on.hpp>
21#include <boost/accumulators/statistics_fwd.hpp>
22#include <boost/accumulators/statistics/moment.hpp>
23#include <boost/accumulators/statistics/rolling_count.hpp>
24
25namespace boost { namespace accumulators
26{
27namespace impl
28{
29 ///////////////////////////////////////////////////////////////////////////////
30 // rolling_moment_impl
31 template<typename N, typename Sample>
32 struct rolling_moment_impl
33 : accumulator_base
34 {
35 BOOST_MPL_ASSERT_RELATION(N::value, >, 0);
36 // for boost::result_of
37 typedef typename numeric::functional::fdiv<Sample, std::size_t,void,void>::result_type result_type;
38
39 template<typename Args>
40 rolling_moment_impl(Args const &args)
41 : sum_(args[sample | Sample()])
42 {
43 }
44
45 template<typename Args>
46 void operator ()(Args const &args)
47 {
48 if(is_rolling_window_plus1_full(args))
49 {
50 this->sum_ -= numeric::pow(rolling_window_plus1(args).front(), N());
51 }
52 this->sum_ += numeric::pow(args[sample], N());
53 }
54
55 template<typename Args>
56 result_type result(Args const &args) const
57 {
58 return numeric::fdiv(this->sum_, rolling_count(args));
59 }
60
61 private:
62 result_type sum_;
63 };
64} // namespace impl
65
66///////////////////////////////////////////////////////////////////////////////
67// tag::rolling_moment
68//
69namespace tag
70{
71 template<int N>
72 struct rolling_moment
73 : depends_on< rolling_window_plus1, rolling_count>
74 {
75 /// INTERNAL ONLY
76 ///
77 typedef accumulators::impl::rolling_moment_impl<mpl::int_<N>, mpl::_1> impl;
78
79 #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
80 /// tag::rolling_window::window_size named parameter
81 static boost::parameter::keyword<tag::rolling_window_size> const window_size;
82 #endif
83 };
84}
85
86///////////////////////////////////////////////////////////////////////////////
87// extract::rolling_moment
88//
89namespace extract
90{
91 BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(tag, rolling_moment, (int))
92}
93
94using extract::rolling_moment;
95
96// There is no weighted_rolling_moment (yet)...
97//
98//// So that rolling_moment<N> can be automatically substituted with
99//// weighted_rolling_moment<N> when the weight parameter is non-void
100//template<int N>
101//struct as_weighted_feature<tag::rolling_moment<N> >
102//{
103// typedef tag::weighted_rolling_moment<N> type;
104//};
105//
106//template<int N>
107//struct feature_of<tag::weighted_rolling_moment<N> >
108// : feature_of<tag::rolling_moment<N> >
109//{
110//};
111}} // namespace boost::accumulators
112
113#endif