26 #ifndef CRYPTO3_ACCUMULATORS_ZK_SPARSE_HPP
27 #define CRYPTO3_ACCUMULATORS_ZK_SPARSE_HPP
29 #include <boost/container/static_vector.hpp>
31 #include <boost/parameter/value_type.hpp>
33 #include <boost/accumulators/framework/accumulator_base.hpp>
34 #include <boost/accumulators/framework/extractor.hpp>
35 #include <boost/accumulators/framework/depends_on.hpp>
36 #include <boost/accumulators/framework/parameters/sample.hpp>
44 namespace accumulators {
51 typedef std::pair<value_type, std::pair<indicies_type, std::vector<T>>>
result_type;
53 template<
typename Args>
57 template<
typename ArgumentPack>
59 resolve_type(args[boost::accumulators::sample], args[::nil::crypto3::accumulators::offset]);
66 template<
typename SinglePassRange>
68 const std::size_t chunks = 1;
70 std::pair<indicies_type, std::vector<T>> resulting_vector;
73 const std::size_t range_len = r.size();
74 std::size_t first_pos = -1, last_pos = -1;
75 for (std::size_t i = 0; i <
indices.size(); ++i) {
76 const bool matching_pos = (offset <=
indices[i] &&
indices[i] < offset + range_len);
80 if (matching_pos && last_pos == i - 1) {
91 algebra::multiexp<algebra::policies::multiexp_method_bos_coster>(
92 values.begin() + first_pos,
values.begin() + last_pos + 1,
93 std::begin(r) + (
indices[first_pos] - offset),
94 std::begin(r) + (
indices[last_pos] - offset) + 1, chunks);
109 resulting_vector.first.emplace_back(
indices[i]);
110 resulting_vector.second.emplace_back(
values[i]);
116 accumulated_value + algebra::multiexp<algebra::policies::multiexp_method_bos_coster>(
117 values.begin() + first_pos,
118 values.begin() + last_pos + 1,
119 std::begin(r) + (
indices[first_pos] - offset),
120 std::begin(r) + (
indices[last_pos] - offset) + 1,
139 struct sparse : boost::accumulators::depends_on<> {
145 typedef boost::mpl::always<accumulators::detail::sparse_impl<value_type>>
impl;
150 template<
typename Mode,
typename AccumulatorSet>
151 typename boost::mpl::apply<AccumulatorSet, tag::sparse<Mode>>::type::result_type
153 return boost::accumulators::extract_result<tag::sparse<Mode>>(acc);
Definition: sparse.hpp:47
bool in_block
Definition: sparse.hpp:127
result_type result(boost::accumulators::dont_care) const
Definition: sparse.hpp:62
T::value_type value_type
Definition: sparse.hpp:48
std::pair< value_type, std::pair< indicies_type, std::vector< T > > > result_type
Definition: sparse.hpp:51
std::vector< std::size_t > indicies_type
Definition: sparse.hpp:49
indicies_type indices
Definition: sparse.hpp:131
sparse_impl(const Args &args)
Definition: sparse.hpp:54
void operator()(const ArgumentPack &args)
Definition: sparse.hpp:58
value_type accumulated_value
Definition: sparse.hpp:129
result_type resolve_type(const SinglePassRange r, std::size_t offset)
Definition: sparse.hpp:67
std::size_t domain_size_
Definition: sparse.hpp:133
std::vector< value_type > values
Definition: sparse.hpp:132
Definition: sparse.hpp:139
T value_type
Definition: sparse.hpp:140
boost::mpl::always< accumulators::detail::sparse_impl< value_type > > impl
Definition: sparse.hpp:145