24#include <unordered_map>
33 size_t right_expansion = 0,
34 size_t left_expansion = 0)
36 size_t expanded_size = array.
size() + right_expansion + left_expansion;
39 memset(
static_cast<void*
>(backing_clone.
raw_data), 0,
sizeof(
Fr) * left_expansion);
41 memcpy(
static_cast<void*
>(backing_clone.
raw_data + left_expansion),
42 static_cast<const void*
>(array.
data()),
43 sizeof(
Fr) * array.
size());
45 memset(
static_cast<void*
>(backing_clone.
raw_data + left_expansion + array.
size()), 0,
sizeof(
Fr) * right_expansion);
75 BB_BENCH_NAME(
"Polynomial::Polynomial(size_t, size_t, size_t)");
76 allocate_backing_memory(size, virtual_size, start_index);
79 size_t range_per_thread = size / num_threads;
80 size_t leftovers = size - (range_per_thread * num_threads);
83 size_t offset = j * range_per_thread;
84 size_t range = (j == num_threads - 1) ? range_per_thread + leftovers : range_per_thread;
87 memset(
static_cast<void*
>(coefficients_.data() +
offset), 0,
sizeof(
Fr) * range);
101 allocate_backing_memory(size, virtual_size, start_index);
104template <
typename Fr>
113 coefficients_ =
_clone(other.coefficients_, target_size - other.size());
117template <
typename Fr>
123 BB_ASSERT_GT(coefficients_.size(),
static_cast<size_t>(0));
126 evaluations.data(), coefficients_.data(), interpolation_points.data(), coefficients_.size());
131 allocate_backing_memory(coefficients.size(), virtual_size, 0);
133 memcpy(
static_cast<void*
>(
data()),
static_cast<const void*
>(coefficients.data()),
sizeof(
Fr) * coefficients.size());
141 if (
this == &other) {
159 return is_empty() && rhs.
is_empty();
166 for (
size_t i = std::min(coefficients_.start_, rhs.
coefficients_.start_);
181 size_t range_per_thread = other.
size() / num_threads;
182 size_t leftovers = other.
size() - (range_per_thread * num_threads);
185 size_t end = (j == num_threads - 1) ?
offset + range_per_thread + leftovers :
offset + range_per_thread;
195 ASSERT(size() == virtual_size());
201 ASSERT(size() == virtual_size());
207 return _evaluate_mle(evaluation_points, coefficients_, shift);
213 const size_t m = evaluation_points.
size();
223 size_t n_l = 1 << (n - 1);
229 Fr u_l = evaluation_points[m - 1];
231 for (
size_t i = 0; i < n_l; i++) {
233 intermediate.at(i) = get(i) + u_l * (get(i + n_l) - get(i));
236 for (
size_t l = 1; l < m; ++l) {
237 n_l = 1 << (n - l - 1);
238 u_l = evaluation_points[m - l - 1];
239 for (
size_t i = 0; i < n_l; ++i) {
240 intermediate.at(i) = intermediate[i] + u_l * (intermediate[i + n_l] - intermediate[i]);
246 for (
size_t idx = 0; idx < n_l; ++idx) {
247 result.at(idx) = intermediate[idx];
253template <
typename Fr>
260template <
typename Fr>
272 const size_t range_per_thread = other.
size() / num_threads;
273 const size_t leftovers = other.
size() - (range_per_thread * num_threads);
276 const size_t end = (j == num_threads - 1) ?
offset + range_per_thread + leftovers :
offset + range_per_thread;
277 for (
size_t i =
offset; i < end; ++i) {
292 for (
size_t i : chunk.
range(size())) {
293 data()[i] *= scaling_factor;
300 memset(
static_cast<void*
>(p.
coefficients_.data()), 0,
sizeof(
Fr) * size);
306template <
typename Fr>
312 if (new_start_index == start_index() && new_end_index == end_index()) {
317 result.
coefficients_ =
_clone(coefficients_, new_end_index - end_index(), start_index() - new_start_index);
324 coefficients_.end_ = new_end_index;
340 [&other, scaling_factor,
this](
const ThreadChunk& chunk) { add_scaled_chunk(chunk, other, scaling_factor); });
343template <
typename Fr>
347 for (
size_t offset : chunk.range(other.
size())) {
349 at(index) += scaling_factor * other[index];
366 BB_ASSERT_LTE((coefficients_.end_ + magnitude), virtual_size());
376 const size_t end_index = this->end_index();
377 const size_t start_index = this->start_index();
378 const size_t poly_size = this->size();
380 for (
size_t idx = end_index; idx > start_index; --idx) {
381 reversed.
at(end_index - idx) = this->at(idx - 1);
#define BB_ASSERT_GTE(left, right,...)
#define BB_ASSERT_GT(left, right,...)
#define BB_ASSERT_LTE(left, right,...)
#define ASSERT(expression,...)
#define BB_BENCH_NAME(name)
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
std::size_t virtual_size() const
SharedShiftedVirtualZeroesArray< Fr > coefficients_
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
typename Flavor::Polynomial Polynomial
const std::vector< FF > data
constexpr T get_msb(const T in)
constexpr bool is_power_of_two(uint64_t x)
Fr evaluate(const Fr *coeffs, const Fr &z, const size_t n)
fr compute_barycentric_evaluation(const fr *coeffs, const size_t num_coeffs, const fr &z, const EvaluationDomain< fr > &domain)
Fr compute_kate_opening_coefficients(const Fr *src, Fr *dest, const Fr &z, const size_t n)
void compute_efficient_interpolation(const Fr *src, Fr *dest, const Fr *evaluation_points, const size_t n)
Entry point for Barretenberg command-line interface.
SharedShiftedVirtualZeroesArray< Fr > _clone(const SharedShiftedVirtualZeroesArray< Fr > &array, size_t right_expansion=0, size_t left_expansion=0)
size_t calculate_num_threads(size_t num_iterations, size_t min_iterations_per_thread)
calculates number of threads to create based on minimum iterations per thread
Fr_ _evaluate_mle(std::span< const Fr_ > evaluation_points, const SharedShiftedVirtualZeroesArray< Fr_ > &coefficients, bool shift)
Internal implementation to support both native and stdlib circuit field types.
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static BackingMemory allocate(size_t size)
A shared pointer array template that represents a virtual array filled with zeros up to virtual_size_...
size_t start_
The starting index of the memory-backed range.
T * data()
Returns a pointer to the underlying memory array. NOTE: This should be used with care,...
size_t virtual_size_
The total logical size of the array.
size_t end_
The ending index of the memory-backed range.
auto range(size_t size, size_t offset=0) const