1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2025-08-03 12:49:50 +00:00

add numeric algorithm reduce, exclusive_scan, inclusize_scan

This commit is contained in:
bolero-MURAKAMI 2017-10-10 02:13:04 +09:00
parent 715cb40734
commit 2052058357
34 changed files with 1195 additions and 18 deletions

View file

@ -9,10 +9,12 @@
#define SPROUT_RANGE_NUMERIC_ACCUMLATE_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/numeric/accumulate.hpp>
namespace sprout {
namespace range {
// 26.7.2 Accumulate
template<typename InputRange, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR T

View file

@ -10,6 +10,8 @@
#include <sprout/config.hpp>
#include <sprout/range/numeric/cxx14/partial_sum.hpp>
#include <sprout/range/numeric/cxx14/exclusive_scan.hpp>
#include <sprout/range/numeric/cxx14/inclusive_scan.hpp>
#include <sprout/range/numeric/cxx14/adjacent_difference.hpp>
#include <sprout/range/numeric/cxx14/iota.hpp>

View file

@ -0,0 +1,42 @@
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
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 SPROUT_RANGE_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP
#define SPROUT_RANGE_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/numeric/cxx14/exclusive_scan.hpp>
namespace sprout {
namespace range {
//
// exclusive_scan
//
template<
typename InputRange, typename OutputIterator, typename T,
typename sprout::enabler_if<sprout::is_iterator_outputable<OutputIterator>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR OutputIterator
exclusive_scan(InputRange const& rng, OutputIterator result, T init) {
return sprout::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init);
}
template<
typename InputRange, typename OutputIterator, typename T, typename BinaryOperation,
typename sprout::enabler_if<sprout::is_iterator_outputable<OutputIterator>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR OutputIterator
exclusive_scan(InputRange const& rng, OutputIterator result, T init, BinaryOperation binary_op) {
return sprout::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init, binary_op);
}
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP

View file

@ -0,0 +1,50 @@
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
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 SPROUT_RANGE_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP
#define SPROUT_RANGE_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/numeric/cxx14/inclusive_scan.hpp>
namespace sprout {
namespace range {
//
// inclusive_scan
//
template<
typename InputRange, typename OutputIterator,
typename sprout::enabler_if<sprout::is_iterator_outputable<OutputIterator>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR OutputIterator
inclusive_scan(InputRange const& rng, OutputIterator result) {
return sprout::inclusive_scan(sprout::begin(rng), sprout::end(rng), result);
}
template<
typename InputRange, typename OutputIterator, typename BinaryOperation,
typename sprout::enabler_if<sprout::is_iterator_outputable<OutputIterator>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR OutputIterator
inclusive_scan(InputRange const& rng, OutputIterator result, BinaryOperation binary_op) {
return sprout::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op);
}
template<
typename InputRange, typename OutputIterator, typename BinaryOperation, typename T,
typename sprout::enabler_if<sprout::is_iterator_outputable<OutputIterator>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR OutputIterator
inclusive_scan(InputRange const& rng, OutputIterator result, BinaryOperation binary_op, T init) {
return sprout::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op, init);
}
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP

View file

@ -0,0 +1,15 @@
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
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 SPROUT_RANGE_NUMERIC_EXCLUSIVE_SCAN_HPP
#define SPROUT_RANGE_NUMERIC_EXCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/range/numeric/fixed/exclusive_scan.hpp>
#include <sprout/range/numeric/fit/exclusive_scan.hpp>
#endif // #ifndef SPROUT_RANGE_NUMERIC_EXCLUSIVE_SCAN_HPP

View file

@ -10,6 +10,8 @@
#include <sprout/config.hpp>
#include <sprout/range/numeric/fit/partial_sum.hpp>
#include <sprout/range/numeric/fit/exclusive_scan.hpp>
#include <sprout/range/numeric/fit/inclusive_scan.hpp>
#include <sprout/range/numeric/fit/adjacent_difference.hpp>
#endif // #ifndef SPROUT_RANGE_NUMERIC_FIT_HPP

View file

@ -0,0 +1,48 @@
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
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 SPROUT_RANGE_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP
#define SPROUT_RANGE_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/fit/results.hpp>
#include <sprout/numeric/fit/exclusive_scan.hpp>
namespace sprout {
namespace range {
namespace fit {
//
// exclusive_scan
//
template<typename InputRange, typename Result, typename T>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
exclusive_scan(InputRange const& rng, Result const& result, T init) {
return sprout::fit::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init);
}
template<typename InputRange, typename Result, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
exclusive_scan(InputRange const& rng, Result const& result, T init, BinaryOperation binary_op) {
return sprout::fit::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init, binary_op);
}
template<typename Result, typename InputRange, typename T>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
exclusive_scan(InputRange const& rng, T init) {
return sprout::fit::exclusive_scan<Result>(sprout::begin(rng), sprout::end(rng), init);
}
template<typename Result, typename InputRange, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
exclusive_scan(InputRange const& rng, T init, BinaryOperation binary_op) {
return sprout::fit::exclusive_scan<Result>(sprout::begin(rng), sprout::end(rng), init, binary_op);
}
} // namespace fit
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP

View file

@ -0,0 +1,58 @@
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
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 SPROUT_RANGE_NUMERIC_FIT_INCLUSIVE_SCAN_HPP
#define SPROUT_RANGE_NUMERIC_FIT_INCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/algorithm/fit/results.hpp>
#include <sprout/numeric/fit/inclusive_scan.hpp>
namespace sprout {
namespace range {
namespace fit {
//
// inclusive_scan
//
template<typename InputRange, typename Result>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng, Result const& result) {
return sprout::fit::inclusive_scan(sprout::begin(rng), sprout::end(rng), result);
}
template<typename InputRange, typename Result, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng, Result const& result, BinaryOperation binary_op) {
return sprout::fit::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op);
}
template<typename InputRange, typename Result, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng, Result const& result, BinaryOperation binary_op, T init) {
return sprout::fit::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op, init);
}
template<typename Result, typename InputRange>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng) {
return sprout::fit::inclusive_scan<Result>(sprout::begin(rng), sprout::end(rng));
}
template<typename Result, typename InputRange, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng, BinaryOperation binary_op) {
return sprout::fit::inclusive_scan<Result>(sprout::begin(rng), sprout::end(rng), binary_op);
}
template<typename Result, typename InputRange, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng, BinaryOperation binary_op, T init) {
return sprout::fit::inclusive_scan<Result>(sprout::begin(rng), sprout::end(rng), binary_op, init);
}
} // namespace fit
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_NUMERIC_FIT_INCLUSIVE_SCAN_HPP

View file

@ -10,6 +10,8 @@
#include <sprout/config.hpp>
#include <sprout/range/numeric/fixed/partial_sum.hpp>
#include <sprout/range/numeric/fixed/exclusive_scan.hpp>
#include <sprout/range/numeric/fixed/inclusive_scan.hpp>
#include <sprout/range/numeric/fixed/adjacent_difference.hpp>
#endif // #ifndef SPROUT_RANGE_NUMERIC_FIXED_HPP

View file

@ -0,0 +1,58 @@
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
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 SPROUT_RANGE_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP
#define SPROUT_RANGE_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/algorithm/fixed/results.hpp>
#include <sprout/numeric/fixed/exclusive_scan.hpp>
namespace sprout {
namespace range {
namespace fixed {
//
// exclusive_scan
//
template<
typename InputRange, typename Result, typename T,
typename sprout::enabler_if<!sprout::is_iterator_outputable<Result>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
exclusive_scan(InputRange const& rng, Result const& result, T init) {
return sprout::fixed::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init);
}
template<
typename InputRange, typename Result, typename T, typename BinaryOperation,
typename sprout::enabler_if<!sprout::is_iterator_outputable<Result>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
exclusive_scan(InputRange const& rng, Result const& result, T init, BinaryOperation binary_op) {
return sprout::fixed::exclusive_scan(sprout::begin(rng), sprout::end(rng), result, init, binary_op);
}
template<typename Result, typename InputRange, typename T>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
exclusive_scan(InputRange const& rng, T init) {
return sprout::fixed::exclusive_scan<Result>(sprout::begin(rng), sprout::end(rng), init);
}
template<typename Result, typename InputRange, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
exclusive_scan(InputRange const& rng, T init, BinaryOperation binary_op) {
return sprout::fixed::exclusive_scan<Result>(sprout::begin(rng), sprout::end(rng), init, binary_op);
}
} // namespace fixed
using sprout::range::fixed::exclusive_scan;
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP

View file

@ -0,0 +1,71 @@
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
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 SPROUT_RANGE_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP
#define SPROUT_RANGE_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/algorithm/fixed/results.hpp>
#include <sprout/numeric/fixed/inclusive_scan.hpp>
namespace sprout {
namespace range {
namespace fixed {
//
// inclusive_scan
//
template<
typename InputRange, typename Result,
typename sprout::enabler_if<!sprout::is_iterator_outputable<Result>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng, Result const& result) {
return sprout::fixed::inclusive_scan(sprout::begin(rng), sprout::end(rng), result);
}
template<
typename InputRange, typename Result, typename BinaryOperation,
typename sprout::enabler_if<!sprout::is_iterator_outputable<Result>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng, Result const& result, BinaryOperation binary_op) {
return sprout::fixed::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op);
}
template<
typename InputRange, typename Result, typename BinaryOperation, typename T,
typename sprout::enabler_if<!sprout::is_iterator_outputable<Result>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng, Result const& result, BinaryOperation binary_op, T init) {
return sprout::fixed::inclusive_scan(sprout::begin(rng), sprout::end(rng), result, binary_op, init);
}
template<typename Result, typename InputRange>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng) {
return sprout::fixed::inclusive_scan<Result>(sprout::begin(rng), sprout::end(rng));
}
template<typename Result, typename InputRange, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng, BinaryOperation binary_op) {
return sprout::fixed::inclusive_scan<Result>(sprout::begin(rng), sprout::end(rng), binary_op);
}
template<typename Result, typename InputRange, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputRange const& rng, BinaryOperation binary_op, T init) {
return sprout::fixed::inclusive_scan<Result>(sprout::begin(rng), sprout::end(rng), binary_op, init);
}
} // namespace fixed
using sprout::range::fixed::inclusive_scan;
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP

View file

@ -0,0 +1,15 @@
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
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 SPROUT_RANGE_NUMERIC_INCLUSIVE_SCAN_HPP
#define SPROUT_RANGE_NUMERIC_INCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/range/numeric/fixed/inclusive_scan.hpp>
#include <sprout/range/numeric/fit/inclusive_scan.hpp>
#endif // #ifndef SPROUT_RANGE_NUMERIC_INCLUSIVE_SCAN_HPP

View file

@ -9,10 +9,12 @@
#define SPROUT_RANGE_NUMERIC_INNER_PRODUCT_HPP
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/numeric/inner_product.hpp>
namespace sprout {
namespace range {
// 26.7.3 Inner product
template<typename InputRange1, typename InputRange2, typename T, typename BinaryOperation1, typename BinaryOperation2>
inline SPROUT_CONSTEXPR T

View file

@ -10,6 +10,7 @@
#include <sprout/config.hpp>
#include <sprout/range/numeric/accumulate.hpp>
#include <sprout/range/numeric/reduce.hpp>
#include <sprout/range/numeric/inner_product.hpp>
#endif // #ifndef SPROUT_RANGE_NUMERIC_NON_MODIFYIING_HPP

View file

@ -0,0 +1,41 @@
/*=============================================================================
Copyright (c) 2011-2017 Bolero MURAKAMI
https://github.com/bolero-MURAKAMI/Sprout
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 SPROUT_RANGE_NUMERIC_REDUCE_HPP
#define SPROUT_RANGE_NUMERIC_REDUCE_HPP
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/container/container_traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/numeric/reduce.hpp>
namespace sprout {
namespace range {
// 29.8.3 Reduce
template<typename InputRange, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR T
reduce(InputRange const& range, T init, BinaryOperation binary_op) {
return sprout::reduce(sprout::begin(range), sprout::end(range), init, binary_op);
}
template<typename InputRange, typename T>
inline SPROUT_CONSTEXPR T
reduce(InputRange const& range, T init) {
return sprout::reduce(sprout::begin(range), sprout::end(range), init);
}
template<typename InputRange>
inline SPROUT_CONSTEXPR typename std::iterator_traits<typename sprout::container_traits<InputRange>::iterator>::value_type
reduce(InputRange const& range) {
return sprout::reduce(sprout::begin(range), sprout::end(range));
}
} // namespace range
} // namespace sprout
#endif // #ifndef SPROUT_RANGE_NUMERIC_REDUCE_HPP