23#include <unordered_map>
32 size_t right_expansion = 0,
33 size_t left_expansion = 0)
35 size_t expanded_size = array.
size() + right_expansion + left_expansion;
38 memset(
static_cast<void*
>(backing_clone.
raw_data), 0,
sizeof(
Fr) * left_expansion);
40 memcpy(
static_cast<void*
>(backing_clone.
raw_data + left_expansion),
41 static_cast<const void*
>(array.
data()),
42 sizeof(
Fr) * array.
size());
44 memset(
static_cast<void*
>(backing_clone.
raw_data + left_expansion + array.
size()), 0,
sizeof(
Fr) * right_expansion);
74 BB_BENCH_NAME(
"Polynomial::Polynomial(size_t, size_t, size_t)");
75 allocate_backing_memory(size, virtual_size, start_index);
78 auto range = chunk.
range(size);
80 size_t start = *range.begin();
81 size_t range_size = range.size();
82 BB_ASSERT(start < size || size == 0);
83 BB_ASSERT_LTE((start + range_size), size);
84 memset(static_cast<void*>(coefficients_.data() + start), 0, sizeof(Fr) * range_size);
99 allocate_backing_memory(size, virtual_size, start_index);
102template <
typename Fr>
108template <
typename Fr> Polynomial<Fr>::Polynomial(
const Polynomial<Fr>& other,
const size_t target_size)
111 coefficients_ = _clone(other.coefficients_, target_size - other.size());
115template <
typename Fr>
119 :
Polynomial(interpolation_points.size(), virtual_size)
129 allocate_backing_memory(coefficients.size(), virtual_size, 0);
131 memcpy(
static_cast<void*
>(
data()),
static_cast<const void*
>(coefficients.data()),
sizeof(
Fr) * coefficients.size());
139 if (
this == &other) {
157 return is_empty() && rhs.
is_empty();
164 for (
size_t i = std::min(coefficients_.start_, rhs.
coefficients_.start_);
201 return _evaluate_mle(evaluation_points, coefficients_, shift);
204template <
typename Fr>
232 for (
size_t i : chunk.
range(size())) {
233 data()[i] *= scaling_factor;
240 memset(
static_cast<void*
>(p.
coefficients_.data()), 0,
sizeof(
Fr) * size);
247 coefficients_.end_ = new_end_index;
263 [&other, scaling_factor,
this](
const ThreadChunk& chunk) { add_scaled_chunk(chunk, other, scaling_factor); });
266template <
typename Fr>
270 for (
size_t offset : chunk.range(other.
size())) {
289 BB_ASSERT_LTE((coefficients_.end_ + magnitude), virtual_size());
299 const size_t end_index = this->end_index();
300 const size_t start_index = this->start_index();
301 const size_t poly_size = this->size();
303 for (
size_t idx = end_index; idx > start_index; --idx) {
304 reversed.
at(end_index - idx) = this->at(idx - 1);
#define BB_ASSERT(expression,...)
#define BB_ASSERT_GTE(left, right,...)
#define BB_ASSERT_GT(left, right,...)
#define BB_ASSERT_LTE(left, right,...)
#define BB_BENCH_NAME(name)
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
Polynomial & operator=(Polynomial &&other) noexcept=default
Polynomial shifted() const
Returns a Polynomial the left-shift of self.
Polynomial & operator*=(Fr scaling_factor)
sets this = p(X) to s⋅p(X)
std::size_t virtual_size() const
Fr evaluate(const Fr &z, size_t target_size) const
SharedShiftedVirtualZeroesArray< Fr > coefficients_
void multiply_chunk(const ThreadChunk &chunk, Fr scaling_factor)
Fr evaluate_mle(std::span< const Fr > evaluation_points, bool shift=false) const
evaluate multi-linear extension p(X_0,…,X_{n-1}) = \sum_i a_i*L_i(X_0,…,X_{n-1}) at u = (u_0,...
const Fr & get(size_t i, size_t virtual_padding=0) const
Retrieves the value at the specified index.
Polynomial & operator-=(PolynomialSpan< const Fr > other)
subtracts the polynomial q(X) 'other'.
Polynomial reverse() const
Returns the polynomial equal to the reverse of self.
Polynomial right_shifted(const size_t magnitude) const
Returns a Polynomial equal to the right-shift-by-magnitude of self.
Fr compute_barycentric_evaluation(const Fr &z, const EvaluationDomain< Fr > &domain)
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
void add_scaled(PolynomialSpan< const Fr > other, Fr scaling_factor) &
adds the polynomial q(X) 'other', multiplied by a scaling factor.
bool operator==(Polynomial const &rhs) const
void shrink_end_index(const size_t new_end_index)
The end_index of the polynomial is decreased without any memory de-allocation. This is a very fast wa...
Polynomial & operator+=(PolynomialSpan< const Fr > other)
adds the polynomial q(X) 'other'.
void add_scaled_chunk(const ThreadChunk &chunk, PolynomialSpan< const Fr > other, Fr scaling_factor) &
static Polynomial create_non_parallel_zero_init(size_t size, size_t virtual_size)
A factory to construct a polynomial where parallel initialization is not possible (e....
void allocate_backing_memory(size_t size, size_t virtual_size, size_t start_index)
Polynomial full() const
Copys the polynomial, but with the whole address space usable. The value of the polynomial remains th...
const std::vector< MemoryValue > data
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)
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)
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