use ark_ff::Field;
#[cfg(not(feature = "std"))]
use ark_std::vec::Vec;
#[cfg(feature = "parallel")]
use rayon::prelude::*;
pub(crate) fn flat_to_matrix_column_major<T: Copy>(flat: &[T], n: usize, m: usize) -> Vec<Vec<T>> {
assert_eq!(flat.len(), n * m, "n * m should coincide with flat.len()");
let mut res = Vec::new();
for row in 0..n {
res.push((0..m).map(|col| flat[col * n + row]).collect())
}
res
}
pub(crate) fn tensor_prime<F: Field>(values: &[F]) -> Vec<F> {
if values.is_empty() {
return vec![F::one()];
}
let tail = tensor_prime(&values[1..]);
let val = values[0];
cfg_iter!(tail)
.map(|v| *v * (F::one() - val))
.chain(cfg_iter!(tail).map(|v| *v * val))
.collect()
}