From 34c26087b5afdedd4b37564ecf2b9cecadbd7b8d Mon Sep 17 00:00:00 2001 From: Ohad Agadi Date: Mon, 23 Dec 2024 13:08:31 +0200 Subject: [PATCH] uninitialized trace --- crates/air_utils/src/trace/component_trace.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/crates/air_utils/src/trace/component_trace.rs b/crates/air_utils/src/trace/component_trace.rs index 8a3c10f36..ceb5c0f2e 100644 --- a/crates/air_utils/src/trace/component_trace.rs +++ b/crates/air_utils/src/trace/component_trace.rs @@ -13,6 +13,7 @@ use super::row_iterator::{ParRowIterMut, RowIterMut}; /// Stored as an array of `N` columns, each column is a vector of [`PackedM31`] values. /// Exposes an iterator over mutable references to the rows of the matrix. /// +/// /// # Example: /// /// ```text @@ -54,17 +55,29 @@ pub struct ComponentTrace { } impl ComponentTrace { + /// Creates a new `ComponentTrace` with all values initialized to zero. + /// The number of rows in each column is `2^log_size`, padded to a multiple of [`N_LANES`]. pub fn zeroed(log_size: u32) -> Self { + let log_size = std::cmp::max(log_size, LOG_N_LANES); let n_simd_elems = 1 << (log_size - LOG_N_LANES); let data = [(); N].map(|_| vec![PackedM31::zeroed(); n_simd_elems]); Self { data, log_size } } + /// Creates a new `ComponentTrace` with all values uninitialized. /// # Safety /// The caller must ensure that the column is populated before being used. + /// The number of rows in each column is `2^log_size`, padded to a multiple of [`N_LANES`]. #[allow(clippy::uninit_vec)] - pub unsafe fn uninitialized(_log_size: u32) -> Self { - todo!() + pub unsafe fn uninitialized(log_size: u32) -> Self { + let log_size = std::cmp::max(log_size, LOG_N_LANES); + let n_simd_elems = 1 << (log_size - LOG_N_LANES); + let data = [(); N].map(|_| { + let mut vec = Vec::with_capacity(n_simd_elems); + vec.set_len(n_simd_elems); + vec + }); + Self { data, log_size } } pub fn log_size(&self) -> u32 {