-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// rolling_max.hpp | ||
// | ||
// Copyright 2018 Quentin Chateau. Distributed under the Boost | ||
// Software License, Version 1.0. (See accompanying file | ||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_MAX_HPP_QC_20_12_2018 | ||
#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MAX_HPP_QC_20_12_2018 | ||
|
||
#include <boost/accumulators/framework/accumulator_base.hpp> | ||
#include <boost/accumulators/framework/extractor.hpp> | ||
#include <boost/accumulators/framework/parameters/sample.hpp> | ||
#include <boost/accumulators/framework/depends_on.hpp> | ||
#include <boost/accumulators/statistics_fwd.hpp> | ||
#include <boost/accumulators/statistics/sorted_rolling_window.hpp> | ||
|
||
namespace boost { namespace accumulators | ||
{ | ||
|
||
namespace impl | ||
{ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// rolling_max_impl | ||
template<typename Sample> | ||
struct rolling_max_impl | ||
: accumulator_base | ||
{ | ||
// for boost::result_of | ||
typedef Sample result_type; | ||
|
||
rolling_max_impl(dont_care) | ||
{ | ||
} | ||
|
||
template<typename Args> | ||
result_type result(Args const &args) const | ||
{ | ||
if (sorted_rolling_window(args).empty()) | ||
{ | ||
return numeric::as_min(Sample()); | ||
} | ||
return sorted_rolling_window(args).back(); | ||
} | ||
}; | ||
|
||
} // namespace impl | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// tag::rolling_max | ||
// | ||
namespace tag | ||
{ | ||
struct rolling_max | ||
: depends_on< sorted_rolling_window > | ||
{ | ||
/// INTERNAL ONLY | ||
/// | ||
typedef accumulators::impl::rolling_max_impl<mpl::_1> impl; | ||
}; | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// extract::rolling_max | ||
// | ||
namespace extract | ||
{ | ||
extractor<tag::rolling_max> const rolling_max = {}; | ||
|
||
BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_max) | ||
} | ||
|
||
using extract::rolling_max; | ||
|
||
}} // namespace boost::accumulators | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// rolling_min.hpp | ||
// | ||
// Copyright 2018 Quentin Chateau. Distributed under the Boost | ||
// Software License, Version 1.0. (See accompanying file | ||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#ifndef BOOST_ACCUMULATORS_STATISTICS_ROLLING_MIN_HPP_QC_20_12_2018 | ||
#define BOOST_ACCUMULATORS_STATISTICS_ROLLING_MIN_HPP_QC_20_12_2018 | ||
|
||
#include <boost/accumulators/framework/accumulator_base.hpp> | ||
#include <boost/accumulators/framework/extractor.hpp> | ||
#include <boost/accumulators/framework/parameters/sample.hpp> | ||
#include <boost/accumulators/framework/depends_on.hpp> | ||
#include <boost/accumulators/statistics_fwd.hpp> | ||
#include <boost/accumulators/statistics/sorted_rolling_window.hpp> | ||
|
||
namespace boost { namespace accumulators | ||
{ | ||
|
||
namespace impl | ||
{ | ||
/////////////////////////////////////////////////////////////////////////////// | ||
// rolling_min_impl | ||
template<typename Sample> | ||
struct rolling_min_impl | ||
: accumulator_base | ||
{ | ||
// for boost::result_of | ||
typedef Sample result_type; | ||
|
||
rolling_min_impl(dont_care) | ||
{ | ||
} | ||
|
||
template<typename Args> | ||
result_type result(Args const &args) const | ||
{ | ||
if (sorted_rolling_window(args).empty()) | ||
{ | ||
return numeric::as_max(Sample()); | ||
} | ||
return sorted_rolling_window(args).front(); | ||
} | ||
}; | ||
|
||
} // namespace impl | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// tag::rolling_min | ||
// | ||
namespace tag | ||
{ | ||
struct rolling_min | ||
: depends_on< sorted_rolling_window > | ||
{ | ||
/// INTERNAL ONLY | ||
/// | ||
typedef accumulators::impl::rolling_min_impl<mpl::_1> impl; | ||
}; | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// extract::rolling_min | ||
// | ||
namespace extract | ||
{ | ||
extractor<tag::rolling_min> const rolling_min = {}; | ||
|
||
BOOST_ACCUMULATORS_IGNORE_GLOBAL(rolling_min) | ||
} | ||
|
||
using extract::rolling_min; | ||
|
||
}} // namespace boost::accumulators | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// (C) Copyright Eric Niebler 2008. | ||
// Use, modification and distribution are subject to the | ||
// Boost Software License, Version 1.0. (See accompanying file | ||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include <boost/test/unit_test.hpp> | ||
#include <boost/container/set.hpp> | ||
#include <boost/accumulators/accumulators.hpp> | ||
#include <boost/accumulators/statistics/stats.hpp> | ||
#include <boost/accumulators/statistics/rolling_max.hpp> | ||
|
||
using namespace boost; | ||
using namespace unit_test; | ||
using namespace accumulators; | ||
using namespace container; | ||
|
||
typedef accumulator_set<int, stats<tag::rolling_max> > RollingmaxAccumulator; | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// test_stat | ||
// | ||
void test_stat() | ||
{ | ||
accumulator_set<int, stats<tag::rolling_max> > acc(tag::rolling_window::window_size = 3); | ||
|
||
BOOST_CHECK_EQUAL(numeric::as_min(int()), rolling_max(acc)); | ||
|
||
acc(1); | ||
BOOST_CHECK_EQUAL(1, rolling_max(acc)); | ||
|
||
acc(3); | ||
BOOST_CHECK_EQUAL(3, rolling_max(acc)); | ||
|
||
acc(5); | ||
BOOST_CHECK_EQUAL(5, rolling_max(acc)); | ||
|
||
acc(7); | ||
BOOST_CHECK_EQUAL(7, rolling_max(acc)); | ||
|
||
acc(6); | ||
BOOST_CHECK_EQUAL(7, rolling_max(acc)); | ||
|
||
acc(1); | ||
BOOST_CHECK_EQUAL(7, rolling_max(acc)); | ||
|
||
acc(3); | ||
BOOST_CHECK_EQUAL(6, rolling_max(acc)); | ||
|
||
acc(2); | ||
BOOST_CHECK_EQUAL(3, rolling_max(acc)); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// init_unit_test_suite | ||
// | ||
test_suite* init_unit_test_suite( int argc, char* argv[] ) | ||
{ | ||
test_suite *test = BOOST_TEST_SUITE("rolling max test"); | ||
|
||
test->add(BOOST_TEST_CASE(&test_stat)); | ||
|
||
return test; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// (C) Copyright Eric Niebler 2008. | ||
// Use, modification and distribution are subject to the | ||
// Boost Software License, Version 1.0. (See accompanying file | ||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
|
||
#include <boost/test/unit_test.hpp> | ||
#include <boost/container/set.hpp> | ||
#include <boost/accumulators/accumulators.hpp> | ||
#include <boost/accumulators/statistics/stats.hpp> | ||
#include <boost/accumulators/statistics/rolling_min.hpp> | ||
|
||
using namespace boost; | ||
using namespace unit_test; | ||
using namespace accumulators; | ||
using namespace container; | ||
|
||
typedef accumulator_set<int, stats<tag::rolling_min> > RollingMinAccumulator; | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// test_stat | ||
// | ||
void test_stat() | ||
{ | ||
accumulator_set<int, stats<tag::rolling_min> > acc(tag::rolling_window::window_size = 3); | ||
|
||
BOOST_CHECK_EQUAL(numeric::as_max(int()), rolling_min(acc)); | ||
|
||
acc(1); | ||
BOOST_CHECK_EQUAL(1, rolling_min(acc)); | ||
|
||
acc(3); | ||
BOOST_CHECK_EQUAL(1, rolling_min(acc)); | ||
|
||
acc(5); | ||
BOOST_CHECK_EQUAL(1, rolling_min(acc)); | ||
|
||
acc(7); | ||
BOOST_CHECK_EQUAL(3, rolling_min(acc)); | ||
|
||
acc(6); | ||
BOOST_CHECK_EQUAL(5, rolling_min(acc)); | ||
|
||
acc(7); | ||
BOOST_CHECK_EQUAL(6, rolling_min(acc)); | ||
|
||
acc(1); | ||
BOOST_CHECK_EQUAL(1, rolling_min(acc));\ | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// init_unit_test_suite | ||
// | ||
test_suite* init_unit_test_suite( int argc, char* argv[] ) | ||
{ | ||
test_suite *test = BOOST_TEST_SUITE("rolling min test"); | ||
|
||
test->add(BOOST_TEST_CASE(&test_stat)); | ||
|
||
return test; | ||
} |