openvm_stark_backend/
utils.rsuse p3_field::Field;
use tracing::instrument;
use crate::prover::USE_DEBUG_BUILDER;
#[instrument(name = "batch_multiplicative_inverse", level = "info", skip_all)]
pub fn batch_multiplicative_inverse_allowing_zero<F: Field>(values: Vec<F>) -> Vec<F> {
let mut nonzero_values = Vec::with_capacity(values.len());
let mut indices = Vec::with_capacity(values.len());
for (i, value) in values.iter().cloned().enumerate() {
if value.is_zero() {
continue;
}
nonzero_values.push(value);
indices.push(i);
}
let inverse_nonzero_values = p3_field::batch_multiplicative_inverse(&nonzero_values);
let mut result = values.clone();
for (i, index) in indices.into_iter().enumerate() {
result[index] = inverse_nonzero_values[i];
}
result
}
pub fn disable_debug_builder() {
USE_DEBUG_BUILDER.with(|debug| {
*debug.lock().unwrap() = false;
});
}
#[macro_export]
#[cfg(feature = "parallel")]
macro_rules! parizip {
( $first:expr $( , $rest:expr )* $(,)* ) => {
{
use rayon::iter::*;
(( $first $( , $rest)* )).into_par_iter()
}
};
}
#[macro_export]
#[cfg(not(feature = "parallel"))]
macro_rules! parizip {
( $first:expr $( , $rest:expr )* $(,)* ) => {
itertools::izip!( $first $( , $rest)* )
};
}