-
Notifications
You must be signed in to change notification settings - Fork 61
Rolling min max #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
qchateau
wants to merge
5
commits into
boostorg:develop
Choose a base branch
from
qchateau:rolling_min_max
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Rolling min max #22
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef28b2b
sorted rolling window
qchateau bf79b09
rolling min and max
qchateau e43575c
Fixed rolling_window extractor beeing declared after use in the TU
qchateau 5f7d12c
Added lazy/immediate implementations for rolling min and max
qchateau 0ee39fb
Merge branch 'develop' into rolling_min_max
qchateau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
99 changes: 99 additions & 0 deletions
99
include/boost/accumulators/statistics/sorted_rolling_window.hpp
This file contains hidden or 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,99 @@ | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // sorted_rolling_window.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_SORTED_ROLLING_WINDOW_HPP_QC_20_12_2018 | ||
| #define BOOST_ACCUMULATORS_STATISTICS_SORTED_ROLLING_WINDOW_HPP_QC_20_12_2018 | ||
|
|
||
| #include <boost/container/set.hpp> | ||
| #include <boost/range/iterator_range.hpp> | ||
| #include <boost/accumulators/accumulators_fwd.hpp> | ||
| #include <boost/accumulators/framework/extractor.hpp> | ||
| #include <boost/accumulators/framework/depends_on.hpp> | ||
| #include <boost/accumulators/framework/accumulator_base.hpp> | ||
| #include <boost/accumulators/framework/parameters/sample.hpp> | ||
| #include <boost/accumulators/framework/parameters/accumulator.hpp> | ||
| #include <boost/accumulators/statistics_fwd.hpp> | ||
| #include <boost/accumulators/statistics/rolling_window.hpp> | ||
|
|
||
| namespace boost { namespace accumulators | ||
| { | ||
|
|
||
| namespace impl | ||
| { | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // sorted_rolling_window | ||
| // stores the latest N samples, where N is specified at construction time | ||
| // with the rolling_window_size named parameter. samples are sorted | ||
| // on insersion | ||
| template<typename Sample> | ||
| struct sorted_rolling_window_impl | ||
| : accumulator_base | ||
| { | ||
| typedef typename container::multiset<Sample>::const_iterator const_iterator; | ||
| typedef iterator_range<const_iterator> result_type; | ||
|
|
||
| template<typename Args> | ||
| sorted_rolling_window_impl(Args const &) | ||
| {} | ||
|
|
||
| template<typename Args> | ||
| void operator ()(Args const &args) | ||
| { | ||
| if(is_rolling_window_plus1_full(args)) | ||
| { | ||
| const_iterator it = this->sorted_buffer_.find(rolling_window_plus1(args).front()); | ||
| this->sorted_buffer_.erase(it); | ||
| } | ||
| this->sorted_buffer_.insert(args[sample]); | ||
| } | ||
|
|
||
| result_type result(dont_care) const | ||
| { | ||
| return result_type(this->sorted_buffer_.begin(), this->sorted_buffer_.end()); | ||
| } | ||
|
|
||
| private: | ||
| container::multiset<Sample> sorted_buffer_; | ||
| }; | ||
|
|
||
| } // namespace impl | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // tag::sorted_rolling_window | ||
| // | ||
| namespace tag | ||
| { | ||
| struct sorted_rolling_window | ||
| : depends_on< rolling_window_plus1 > | ||
| { | ||
| /// INTERNAL ONLY | ||
| /// | ||
| typedef accumulators::impl::sorted_rolling_window_impl< mpl::_1 > impl; | ||
|
|
||
| #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED | ||
| /// tag::sorted_rolling_window::size named parameter | ||
| static boost::parameter::keyword<tag::rolling_window_size> const window_size; | ||
| #endif | ||
| }; | ||
|
|
||
| } // namespace tag | ||
|
|
||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // extract::sorted_rolling_window | ||
| // | ||
| namespace extract | ||
| { | ||
| extractor<tag::sorted_rolling_window> const sorted_rolling_window = {}; | ||
|
|
||
| BOOST_ACCUMULATORS_IGNORE_GLOBAL(sorted_rolling_window) | ||
| } | ||
|
|
||
| using extract::sorted_rolling_window; | ||
|
|
||
| }} // namespace boost::accumulators | ||
|
|
||
| #endif |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.