Skip to content

Commit

Permalink
Merge pull request #1357 from akoshelev/sz-additive-share
Browse files Browse the repository at this point in the history
Add compile time function to compute the size of AdditiveShare
  • Loading branch information
akoshelev authored Oct 18, 2024
2 parents 5183c9f + e2d82c7 commit 297b693
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ impl<V: SharedValue + Vectorizable<N>, const N: usize> AdditiveShare<V, N> {
<V as Vectorizable<N>>::Array::ZERO_ARRAY,
<V as Vectorizable<N>>::Array::ZERO_ARRAY,
);

/// Returns the size this instance would occupy on the wire or disk.
/// In other words, it does not include padding/alignment.
#[must_use]
pub const fn size() -> usize {
2 * <<V as Vectorizable<N>>::Array as Serializable>::Size::USIZE
}
}

impl<V: SharedValue> AdditiveShare<V> {
Expand Down Expand Up @@ -636,6 +643,14 @@ mod tests {
mult_by_constant_test_case((0, 0, 0), 2, 0);
}

#[test]
fn test_size() {
const FP31_SZ: usize = AdditiveShare::<Fp31>::size();
const VEC_FP32: usize = AdditiveShare::<Fp32BitPrime, 32>::size();
assert_eq!(2, FP31_SZ);
assert_eq!(256, VEC_FP32);
}

impl<V: SharedValue, const N: usize> Arbitrary for AdditiveShare<V, N>
where
V: Vectorizable<N, Array = StdArray<V, N>>,
Expand Down

0 comments on commit 297b693

Please sign in to comment.