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

@ -12,6 +12,7 @@
#include <sprout/config.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/utility/pair/pair.hpp>
#include <sprout/type_traits/identity.hpp>
namespace sprout {
namespace fixed {
@ -20,22 +21,33 @@ namespace sprout {
// algorithm
//
template<typename Result>
struct algorithm {
public:
typedef typename sprout::container_construct_traits<Result>::copied_type type;
};
struct algorithm
: public sprout::identity<typename sprout::container_construct_traits<Result>::copied_type>
{};
//
// resized_relative
//
template<typename Result, typename sprout::container_traits<Result>::difference_type RelativeSize>
struct resized_relative
: public sprout::identity<
typename sprout::container_transform_traits<Result>
::template rebind_size<sprout::container_traits<Result>::static_size + RelativeSize>::type
>
{};
//
// shuffle
//
template<typename Container, typename UniformRandomNumberGenerator>
struct shuffle {
public:
typedef sprout::pair<
typename sprout::fixed::results::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
> type;
};
struct shuffle
: public sprout::identity<
sprout::pair<
typename sprout::fixed::results::algorithm<Container>::type,
typename std::decay<UniformRandomNumberGenerator>::type
>
>
{};
} // namespace results
} // namespace fixed

View file

@ -11,5 +11,6 @@
#include <sprout/config.hpp>
#include <sprout/numeric/fixed/adjacent_difference.hpp>
#include <sprout/numeric/fit/adjacent_difference.hpp>
#include <sprout/numeric/cxx14/adjacent_difference.hpp>
#endif // #ifndef SPROUT_NUMERIC_ADJACENT_DIFFERENCE_HPP

View file

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

View file

@ -0,0 +1,54 @@
/*=============================================================================
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_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP
#define SPROUT_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/numeric/cxx14/partial_sum.hpp>
namespace sprout {
//
// 29.8.7 Exclusive scan
//
template<
typename InputIterator, typename OutputIterator, typename T, typename BinaryOperation,
typename sprout::enabler_if<sprout::is_iterator_outputable<OutputIterator>::value>::type = sprout::enabler
>
inline SPROUT_CXX14_CONSTEXPR OutputIterator
exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryOperation binary_op) {
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
value_type sum = sprout::move(init);
*result = sum;
if (first == last) {
return ++result;
}
value_type temp = *first;
while (++first != last) {
sum = binary_op(sum, temp);
*++result = sum;
temp = *first;
}
return ++result;
}
template<
typename InputIterator, typename OutputIterator, typename T,
typename sprout::enabler_if<sprout::is_iterator_outputable<OutputIterator>::value>::type = sprout::enabler
>
inline SPROUT_CXX14_CONSTEXPR OutputIterator
exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init) {
return sprout::exclusive_scan(
first, last, result, init,
NS_SSCRISK_CEL_OR_SPROUT::plus<typename std::iterator_traits<InputIterator>::value_type>()
);
}
} // namespace sprout
#endif // #ifndef SPROUT_NUMERIC_CXX14_EXCLUSIVE_SCAN_HPP

View file

@ -0,0 +1,59 @@
/*=============================================================================
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_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP
#define SPROUT_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/utility/move.hpp>
#include <sprout/iterator/type_traits/is_iterator_of.hpp>
#include <sprout/type_traits/enabler_if.hpp>
#include <sprout/numeric/cxx14/partial_sum.hpp>
namespace sprout {
//
// 29.8.8 Inclusive scan
//
template<
typename InputIterator, typename OutputIterator, typename BinaryOperation, typename T,
typename sprout::enabler_if<sprout::is_iterator_outputable<OutputIterator>::value>::type = sprout::enabler
>
inline SPROUT_CXX14_CONSTEXPR OutputIterator
inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op, T init) {
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
value_type sum = sprout::move(init);
*result = sum;
if (first == last) {
return ++result;
}
sum = binary_op(sum, *first);
*++result = sum;
while (++first != last) {
sum = binary_op(sum, *first);
*++result = sum;
}
return ++result;
}
template<
typename InputIterator, typename OutputIterator, typename BinaryOperation,
typename sprout::enabler_if<sprout::is_iterator_outputable<OutputIterator>::value>::type = sprout::enabler
>
inline SPROUT_CXX14_CONSTEXPR OutputIterator
inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op) {
return sprout::partial_sum(first, last, result, binary_op);
}
template<
typename InputIterator, typename OutputIterator,
typename sprout::enabler_if<sprout::is_iterator_outputable<OutputIterator>::value>::type = sprout::enabler
>
inline SPROUT_CXX14_CONSTEXPR OutputIterator
inclusive_scan(InputIterator first, InputIterator last, OutputIterator result) {
return sprout::partial_sum(first, last, result);
}
} // namespace sprout
#endif // #ifndef SPROUT_NUMERIC_CXX14_INCLUSIVE_SCAN_HPP

View file

@ -0,0 +1,16 @@
/*=============================================================================
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_NUMERIC_EXCLUSIVE_SCAN_HPP
#define SPROUT_NUMERIC_EXCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/numeric/fixed/exclusive_scan.hpp>
#include <sprout/numeric/fit/exclusive_scan.hpp>
#include <sprout/numeric/cxx14/exclusive_scan.hpp>
#endif // #ifndef SPROUT_NUMERIC_EXCLUSIVE_SCAN_HPP

View file

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

View file

@ -0,0 +1,77 @@
/*=============================================================================
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_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP
#define SPROUT_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/iterator/distance.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/numeric/fixed/exclusive_scan.hpp>
#include <sprout/algorithm/fit/results.hpp>
#include <sprout/sub_array/sub_array.hpp>
#include <sprout/sub_array/sub.hpp>
#include <sprout/iterator/type_traits/category.hpp>
namespace sprout {
namespace fit {
namespace detail {
template<typename InputIterator, typename Result, typename T>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
exclusive_scan_impl(
InputIterator const& first, InputIterator const& last, Result const& result, T init,
typename sprout::container_traits<Result>::difference_type offset
)
{
typedef typename std::iterator_traits<InputIterator>::difference_type diff_type;
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::exclusive_scan(first, last, result, init)),
offset,
offset + NS_SSCRISK_CEL_OR_SPROUT::min<diff_type>(sprout::distance(first, last), sprout::size(result))
);
}
} // namespace detail
//
// exclusive_scan
//
template<typename InputIterator, typename Result, typename T>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
exclusive_scan(InputIterator first, InputIterator last, Result const& result, T init) {
static_assert(sprout::is_forward_iterator<InputIterator>::value, "Sorry, not implemented.");
return sprout::fit::detail::exclusive_scan_impl(first, last, result, init, sprout::internal_begin_offset(result));
}
namespace detail {
template<typename InputIterator, typename Result, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
exclusive_scan_impl(
InputIterator const& first, InputIterator const& last, Result const& result, T init, BinaryOperation binary_op,
typename sprout::container_traits<Result>::difference_type offset
)
{
typedef typename std::iterator_traits<InputIterator>::difference_type diff_type;
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::exclusive_scan(first, last, result, init, binary_op)),
offset,
offset + NS_SSCRISK_CEL_OR_SPROUT::min<diff_type>(sprout::distance(first, last), sprout::size(result))
);
}
} // namespace detail
//
// exclusive_scan
//
template<typename InputIterator, typename Result, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
exclusive_scan(InputIterator first, InputIterator last, Result const& result, T init, BinaryOperation binary_op) {
static_assert(sprout::is_forward_iterator<InputIterator>::value, "Sorry, not implemented.");
return sprout::fit::detail::exclusive_scan_impl(first, last, result, init, binary_op, sprout::internal_begin_offset(result));
}
} // namespace fit
} // namespace sprout
#endif // #ifndef SPROUT_NUMERIC_FIT_EXCLUSIVE_SCAN_HPP

View file

@ -0,0 +1,102 @@
/*=============================================================================
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_NUMERIC_FIT_INCLUSIVE_SCAN_HPP
#define SPROUT_NUMERIC_FIT_INCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/iterator/distance.hpp>
#include <sprout/container/traits.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/numeric/fixed/inclusive_scan.hpp>
#include <sprout/algorithm/fit/results.hpp>
#include <sprout/sub_array/sub_array.hpp>
#include <sprout/sub_array/sub.hpp>
#include <sprout/iterator/type_traits/category.hpp>
namespace sprout {
namespace fit {
namespace detail {
template<typename InputIterator, typename Result>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan_impl(
InputIterator const& first, InputIterator const& last, Result const& result,
typename sprout::container_traits<Result>::difference_type offset
)
{
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::inclusive_scan(first, last, result)),
offset,
offset + sprout::fit_size(result, sprout::distance(first, last))
);
}
} // namespace detail
//
// inclusive_scan
//
template<typename InputIterator, typename Result>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last, Result const& result) {
static_assert(sprout::is_forward_iterator<InputIterator>::value, "Sorry, not implemented.");
return sprout::fit::detail::inclusive_scan_impl(first, last, result, sprout::internal_begin_offset(result));
}
namespace detail {
template<typename InputIterator, typename Result, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan_impl(
InputIterator const& first, InputIterator const& last, Result const& result, BinaryOperation binary_op,
typename sprout::container_traits<Result>::difference_type offset
)
{
typedef typename std::iterator_traits<InputIterator>::difference_type diff_type;
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::inclusive_scan(first, last, result, binary_op)),
offset,
offset + NS_SSCRISK_CEL_OR_SPROUT::min<diff_type>(sprout::distance(first, last), sprout::size(result))
);
}
} // namespace detail
//
// inclusive_scan
//
template<typename InputIterator, typename Result, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op) {
static_assert(sprout::is_forward_iterator<InputIterator>::value, "Sorry, not implemented.");
return sprout::fit::detail::inclusive_scan_impl(first, last, result, binary_op, sprout::internal_begin_offset(result));
}
namespace detail {
template<typename InputIterator, typename Result, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan_impl(
InputIterator const& first, InputIterator const& last, Result const& result, BinaryOperation binary_op, T init,
typename sprout::container_traits<Result>::difference_type offset
)
{
typedef typename std::iterator_traits<InputIterator>::difference_type diff_type;
return sprout::sub_copy(
sprout::get_internal(sprout::fixed::inclusive_scan(first, last, result, binary_op, init)),
offset,
offset + NS_SSCRISK_CEL_OR_SPROUT::min<diff_type>(sprout::distance(first, last) + 1, sprout::size(result))
);
}
} // namespace detail
//
// inclusive_scan
//
template<typename InputIterator, typename Result, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename sprout::fit::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op, T init) {
static_assert(sprout::is_forward_iterator<InputIterator>::value, "Sorry, not implemented.");
return sprout::fit::detail::inclusive_scan_impl(first, last, result, binary_op, init, sprout::internal_begin_offset(result));
}
} // namespace fit
} // namespace sprout
#endif // #ifndef SPROUT_NUMERIC_FIT_INCLUSIVE_SCAN_HPP

View file

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

View file

@ -0,0 +1,229 @@
/*=============================================================================
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_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP
#define SPROUT_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/pit/pit.hpp>
#include <sprout/detail/container_complate.hpp>
#include <sprout/numeric/fixed/exclusive_scan.hpp>
namespace sprout {
namespace fixed {
namespace detail {
template<typename InputIterator, typename Result, typename... Args>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == sizeof...(Args) + 1,
typename sprout::fixed::results::algorithm<Result>::type
>::type
exclusive_scan_impl_1(
InputIterator const&, InputIterator const&, Result const& result,
typename sprout::container_traits<Result>::size_type,
typename sprout::container_traits<Result>::value_type const& value,
typename sprout::container_traits<Result>::value_type const& temp,
Args const&... args
)
{
return sprout::remake<Result>(result, sprout::size(result), args..., value);
}
template<typename InputIterator, typename Result, typename... Args>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size != sizeof...(Args) + 1,
typename sprout::fixed::results::algorithm<Result>::type
>::type
exclusive_scan_impl_1(
InputIterator const& first, InputIterator const& last, Result const& result,
typename sprout::container_traits<Result>::size_type size,
typename sprout::container_traits<Result>::value_type const& value,
typename sprout::container_traits<Result>::value_type const& temp,
Args const&... args
)
{
return first != last && sizeof...(Args) + 1 < size
? exclusive_scan_impl_1(sprout::next(first), last, result, size, value + temp, *first, args..., value)
: sprout::detail::container_complate(result, args..., value)
;
}
template<typename InputIterator, typename Result, typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == 0,
typename sprout::fixed::results::algorithm<Result>::type
>::type
exclusive_scan_impl(
InputIterator, InputIterator, Result const& result, T,
typename sprout::container_traits<Result>::size_type
)
{
return sprout::detail::container_complate(result);
}
template<typename InputIterator, typename Result, typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == 1,
typename sprout::fixed::results::algorithm<Result>::type
>::type
exclusive_scan_impl(
InputIterator, InputIterator, Result const& result, T init,
typename sprout::container_traits<Result>::size_type
)
{
return sprout::detail::container_complate(result, init);
}
template<typename InputIterator, typename Result, typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<
(sprout::container_traits<Result>::static_size > 1),
typename sprout::fixed::results::algorithm<Result>::type
>::type
exclusive_scan_impl(
InputIterator const& first, InputIterator const& last, Result const& result, T init,
typename sprout::container_traits<Result>::size_type size
)
{
return first != last
? exclusive_scan_impl_1(sprout::next(first), last, result, size, init, *first)
: sprout::detail::container_complate(result, init)
;
}
} // namespace detail
//
// exclusive_scan
//
template<typename InputIterator, typename Result, typename T>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
exclusive_scan(InputIterator first, InputIterator last, Result const& result, T init) {
return sprout::fixed::detail::exclusive_scan_impl(first, last, result, init, sprout::size(result));
}
template<typename Result, typename InputIterator, typename T>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
exclusive_scan(InputIterator first, InputIterator last, T init) {
return sprout::fixed::exclusive_scan<Result>(first, last, sprout::pit<Result>(), init);
}
namespace detail {
template<typename InputIterator, typename Result, typename BinaryOperation, typename... Args>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == sizeof...(Args) + 1,
typename sprout::fixed::results::algorithm<Result>::type
>::type
exclusive_scan_impl_1(
InputIterator const&, InputIterator const&, Result const& result, BinaryOperation,
typename sprout::container_traits<Result>::size_type,
typename sprout::container_traits<Result>::value_type const& value,
typename sprout::container_traits<Result>::value_type const& temp,
Args const&... args
)
{
return sprout::remake<Result>(result, sprout::size(result), args..., value);
}
template<typename InputIterator, typename Result, typename BinaryOperation, typename... Args>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size != sizeof...(Args) + 1,
typename sprout::fixed::results::algorithm<Result>::type
>::type
exclusive_scan_impl_1(
InputIterator const& first, InputIterator const& last, Result const& result, BinaryOperation binary_op,
typename sprout::container_traits<Result>::size_type size,
typename sprout::container_traits<Result>::value_type const& value,
typename sprout::container_traits<Result>::value_type const& temp,
Args const&... args
)
{
return first != last && sizeof...(Args) + 1 < size
? exclusive_scan_impl_1(sprout::next(first), last, result, binary_op, size, binary_op(value, temp), *first, args..., value)
: sprout::detail::container_complate(result, args..., value)
;
}
template<typename InputIterator, typename Result, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == 0,
typename sprout::fixed::results::algorithm<Result>::type
>::type
exclusive_scan_impl(
InputIterator, InputIterator, Result const& result, T, BinaryOperation,
typename sprout::container_traits<Result>::size_type
)
{
return sprout::detail::container_complate(result);
}
template<typename InputIterator, typename Result, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == 1,
typename sprout::fixed::results::algorithm<Result>::type
>::type
exclusive_scan_impl(
InputIterator, InputIterator, Result const& result, T init, BinaryOperation,
typename sprout::container_traits<Result>::size_type
)
{
return sprout::detail::container_complate(result, init);
}
template<typename InputIterator, typename Result, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename std::enable_if<
(sprout::container_traits<Result>::static_size > 1),
typename sprout::fixed::results::algorithm<Result>::type
>::type
exclusive_scan_impl(
InputIterator const& first, InputIterator const& last, Result const& result, T init, BinaryOperation binary_op,
typename sprout::container_traits<Result>::size_type size
)
{
return first != last
? exclusive_scan_impl_1(sprout::next(first), last, result, binary_op, size, init, *first)
: sprout::detail::container_complate(result, init)
;
}
} // namespace detail
//
// exclusive_scan
//
template<typename InputIterator, typename Result, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
exclusive_scan(InputIterator first, InputIterator last, Result const& result, T init, BinaryOperation binary_op) {
return sprout::fixed::detail::exclusive_scan_impl(first, last, result, init, binary_op, sprout::size(result));
}
template<typename Result, typename InputIterator, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
exclusive_scan(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) {
return sprout::fixed::exclusive_scan(first, last, sprout::pit<Result>(), init, binary_op);
}
} // namespace fixed
template<
typename InputIterator, 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(InputIterator first, InputIterator last, Result const& result, T init) {
return sprout::fixed::exclusive_scan(first, last, result, init);
}
template<typename Result, typename InputIterator, typename T>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
exclusive_scan(InputIterator first, InputIterator last, T init) {
return sprout::fixed::exclusive_scan<Result>(first, last, init);
}
template<
typename InputIterator, 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(InputIterator first, InputIterator last, Result const& result, T init, BinaryOperation binary_op) {
return sprout::fixed::exclusive_scan(first, last, result, init, binary_op);
}
template<typename Result, typename InputIterator, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
exclusive_scan(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) {
return sprout::fixed::exclusive_scan<Result>(first, last, init, binary_op);
}
} // namespace sprout
#endif // #ifndef SPROUT_NUMERIC_FIXED_EXCLUSIVE_SCAN_HPP

View file

@ -0,0 +1,147 @@
/*=============================================================================
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_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP
#define SPROUT_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/pit/pit.hpp>
#include <sprout/detail/container_complate.hpp>
#include <sprout/numeric/fixed/partial_sum.hpp>
namespace sprout {
namespace fixed {
//
// inclusive_scan
//
template<typename InputIterator, typename Result>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last, Result const& result) {
return sprout::fixed::partial_sum(first, last, result);
}
template<typename Result, typename InputIterator>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last) {
return sprout::fixed::partial_sum<Result>(first, last);
}
template<typename InputIterator, typename Result, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op) {
return sprout::fixed::partial_sum(first, last, result, binary_op);
}
template<typename Result, typename InputIterator, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last, BinaryOperation binary_op) {
return sprout::fixed::partial_sum<Result>(first, last, binary_op);
}
namespace detail {
template<typename InputIterator, typename Result, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == 0,
typename sprout::fixed::results::algorithm<Result>::type
>::type
inclusive_scan_impl(
InputIterator, InputIterator, Result const& result, BinaryOperation, T,
typename sprout::container_traits<Result>::size_type
)
{
return sprout::remake<Result>(result, sprout::size(result));
}
template<typename InputIterator, typename Result, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<
sprout::container_traits<Result>::static_size == 1,
typename sprout::fixed::results::algorithm<Result>::type
>::type
inclusive_scan_impl(
InputIterator, InputIterator, Result const& result, BinaryOperation, T init,
typename sprout::container_traits<Result>::size_type
)
{
return sprout::remake<Result>(result, sprout::size(result), init);
}
template<typename InputIterator, typename Result, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename std::enable_if<
(sprout::container_traits<Result>::static_size > 1),
typename sprout::fixed::results::algorithm<Result>::type
>::type
inclusive_scan_impl(
InputIterator const& first, InputIterator const& last, Result const& result, BinaryOperation binary_op, T init,
typename sprout::container_traits<Result>::size_type size
)
{
return first != last
? partial_sum_impl_1(first, last, result, binary_op, size, init)
: sprout::detail::container_complate(result, init)
;
}
} // namespace detail
//
// inclusive_scan
//
template<typename InputIterator, typename Result, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op, T init) {
return sprout::fixed::detail::inclusive_scan_impl(first, last, result, binary_op, init, sprout::size(result));
}
template<typename Result, typename InputIterator, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last, BinaryOperation binary_op, T init) {
return sprout::fixed::inclusive_scan(first, last, sprout::pit<Result>(), binary_op, init);
}
} // namespace fixed
template<
typename InputIterator, 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(InputIterator first, InputIterator last, Result const& result) {
return sprout::fixed::inclusive_scan(first, last, result);
}
template<typename Result, typename InputIterator>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last) {
return sprout::fixed::inclusive_scan<Result>(first, last);
}
template<
typename InputIterator, 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(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op) {
return sprout::fixed::inclusive_scan(first, last, result, binary_op);
}
template<typename Result, typename InputIterator, typename BinaryOperation>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last, BinaryOperation binary_op) {
return sprout::fixed::inclusive_scan<Result>(first, last, binary_op);
}
template<
typename InputIterator, 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(InputIterator first, InputIterator last, Result const& result, BinaryOperation binary_op, T init) {
return sprout::fixed::inclusive_scan(first, last, result, binary_op, init);
}
template<typename Result, typename InputIterator, typename BinaryOperation, typename T>
inline SPROUT_CONSTEXPR typename sprout::fixed::results::algorithm<Result>::type
inclusive_scan(InputIterator first, InputIterator last, BinaryOperation binary_op, T init) {
return sprout::fixed::inclusive_scan<Result>(first, last, binary_op, init);
}
} // namespace sprout
#endif // #ifndef SPROUT_NUMERIC_FIXED_INCLUSIVE_SCAN_HPP

View file

@ -0,0 +1,16 @@
/*=============================================================================
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_NUMERIC_INCLUSIVE_SCAN_HPP
#define SPROUT_NUMERIC_INCLUSIVE_SCAN_HPP
#include <sprout/config.hpp>
#include <sprout/numeric/fixed/inclusive_scan.hpp>
#include <sprout/numeric/fit/inclusive_scan.hpp>
#include <sprout/numeric/cxx14/inclusive_scan.hpp>
#endif // #ifndef SPROUT_NUMERIC_INCLUSIVE_SCAN_HPP

View file

@ -11,5 +11,6 @@
#include <sprout/config.hpp>
#include <sprout/numeric/fixed/iota.hpp>
#include <sprout/numeric/fit/iota.hpp>
#include <sprout/numeric/cxx14/iota.hpp>
#endif // #ifndef SPROUT_NUMERIC_IOTA_HPP

View file

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

View file

@ -11,5 +11,6 @@
#include <sprout/config.hpp>
#include <sprout/numeric/fixed/partial_sum.hpp>
#include <sprout/numeric/fit/partial_sum.hpp>
#include <sprout/numeric/cxx14/partial_sum.hpp>
#endif // #ifndef SPROUT_NUMERIC_PARTIAL_SUM_HPP

42
sprout/numeric/reduce.hpp Normal file
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_NUMERIC_REDUCE_HPP
#define SPROUT_NUMERIC_REDUCE_HPP
#include <iterator>
#include <sprout/config.hpp>
#include <sprout/container/functions.hpp>
#include <sprout/numeric/accumulate.hpp>
namespace sprout {
//
// reduce
//
// recursion depth:
// O(log N)
//
template<typename InputIterator>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::value_type
reduce(InputIterator first, InputIterator last) {
return sprout::accumulate(first, last, typename std::iterator_traits<InputIterator>::value_type());
}
template<typename InputIterator, typename T>
inline SPROUT_CONSTEXPR T
reduce(InputIterator first, InputIterator last, T init) {
return sprout::accumulate(first, last, init);
}
template<typename InputIterator, typename T, typename BinaryOperation>
inline SPROUT_CONSTEXPR T
reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) {
return sprout::accumulate(first, last, init, binary_op);
}
} // namespace sprout
#endif // #ifndef SPROUT_NUMERIC_REDUCE_HPP

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

View file

@ -85,7 +85,7 @@ namespace sprout {
public:
typedef sprout::sub_array<
typename sprout::container_transform_traits<
typename std::remove_reference<Container>::type
typename sprout::container_construct_traits<Container>::copied_type
>::template rebind_size<Size>::type
> type;
};
@ -94,7 +94,7 @@ namespace sprout {
public:
typedef sprout::sub_array<
typename sprout::container_transform_traits<
typename std::remove_reference<Container>::type
typename sprout::container_construct_traits<Container>::copied_type
>::template rebind_type<Type>::type
> type;
};

View file

@ -155,14 +155,18 @@ namespace testspr {
SPROUT_NON_CONSTEXPR comparable_function(function_type const& f)
: func_(f)
{}
SPROUT_NON_CONSTEXPR bool operator()(trace_stack const& t) {
SPROUT_NON_CONSTEXPR bool operator()(trace_stack const& t) const {
return func_(t);
}
SPROUT_NON_CONSTEXPR bool operator==(function_type const& rhs) {
return func_.target_type() == rhs.target_type();
SPROUT_NON_CONSTEXPR bool operator==(function_type const& rhs) const {
return func_ == nullptr ? rhs == nullptr
: rhs == nullptr ? false
: func_.target_type() == rhs.target_type()
&& func_.target<bool (testspr::trace_stack const&)>() == rhs.target<bool (testspr::trace_stack const&)>()
;
}
SPROUT_NON_CONSTEXPR bool operator!=(function_type const& rhs) {
return func_.target_type() != rhs.target_type();
SPROUT_NON_CONSTEXPR bool operator!=(function_type const& rhs) const {
return !(*this == rhs);
}
};
private: