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());
45 static_cast<void*
>(backing_clone->raw_data() + left_expansion + array.
size()), 0,
sizeof(
Fr) * right_expansion);
73 allocate_backing_memory(size, virtual_size, start_index);
76 size_t range_per_thread = size / num_threads;
77 size_t leftovers = size - (range_per_thread * num_threads);
80 size_t offset = j * range_per_thread;
81 size_t range = (j == num_threads - 1) ? range_per_thread + leftovers : range_per_thread;
84 memset(
static_cast<void*
>(coefficients_.data() +
offset), 0,
sizeof(
Fr) * range);
98 allocate_backing_memory(size, virtual_size, start_index);
101template <
typename Fr>
110 coefficients_ = _clone(other.coefficients_, target_size - other.size());
114template <
typename Fr>
118 :
Polynomial(interpolation_points.size(), virtual_size)
128 allocate_backing_memory(coefficients.size(), virtual_size, 0);
130 memcpy(
static_cast<void*
>(
data()),
static_cast<const void*
>(coefficients.data()),
sizeof(
Fr) * coefficients.size());
138 if (
this == &other) {
156 return is_empty() && rhs.
is_empty();
163 for (
size_t i = std::min(coefficients_.start_, rhs.
coefficients_.start_);
178 size_t range_per_thread = other.
size() / num_threads;
179 size_t leftovers = other.
size() - (range_per_thread * num_threads);
182 size_t end = (j == num_threads - 1) ?
offset + range_per_thread + leftovers :
offset + range_per_thread;
183 for (
size_t i =
offset; i < end; ++i) {
192 ASSERT(size() == virtual_size());
198 ASSERT(size() == virtual_size());
210 const size_t m = evaluation_points.
size();
220 size_t n_l = 1 << (n - 1);
226 Fr u_l = evaluation_points[m - 1];
228 for (
size_t i = 0; i < n_l; i++) {
230 intermediate.
at(i) = get(i) + u_l * (get(i + n_l) - get(i));
233 for (
size_t l = 1; l < m; ++l) {
234 n_l = 1 << (n - l - 1);
235 u_l = evaluation_points[m - l - 1];
236 for (
size_t i = 0; i < n_l; ++i) {
237 intermediate.
at(i) = intermediate[i] + u_l * (intermediate[i + n_l] - intermediate[i]);
243 for (
size_t idx = 0; idx < n_l; ++idx) {
244 result.at(idx) = intermediate[idx];
250template <
typename Fr>
252 requires polynomial_arithmetic::SupportsFFT<
Fr>
257template <
typename Fr>
259 requires polynomial_arithmetic::SupportsFFT<
Fr>
269 const size_t range_per_thread = other.
size() / num_threads;
270 const size_t leftovers = other.
size() - (range_per_thread * num_threads);
273 const size_t end = (j == num_threads - 1) ?
offset + range_per_thread + leftovers :
offset + range_per_thread;
274 for (
size_t i =
offset; i < end; ++i) {
284 const size_t range_per_thread = size() / num_threads;
285 const size_t leftovers = size() - (range_per_thread * num_threads);
287 const size_t offset = j * range_per_thread;
288 const size_t end = (j == num_threads - 1) ?
offset + range_per_thread + leftovers :
offset + range_per_thread;
289 for (
size_t i =
offset; i < end; ++i) {
290 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 const size_t range_per_thread = other.
size() / num_threads;
341 const size_t leftovers = other.
size() - (range_per_thread * num_threads);
344 const size_t end = (j == num_threads - 1) ?
offset + range_per_thread + leftovers :
offset + range_per_thread;
345 for (
size_t i =
offset; i < end; ++i) {
346 at(i) += scaling_factor * other[i];
364 BB_ASSERT_LTE((coefficients_.end_ + magnitude), virtual_size());
374 const size_t end_index = this->end_index();
375 const size_t start_index = this->start_index();
376 const size_t poly_size = this->size();
378 for (
size_t idx = end_index; idx > start_index; --idx) {
379 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,...)
static std::shared_ptr< BackingMemory< Fr > > allocate(size_t size)
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
std::size_t virtual_size() const
SharedShiftedVirtualZeroesArray< Fr > coefficients_
const Fr & get(size_t i, size_t virtual_padding=0) const
Retrieves the value at the specified index.
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
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.