Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Orion related additional test #180

Merged
merged 8 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
matrix:
include:
- os: macos-latest
- os: ubuntu-latest
# - os: ubuntu-latest

steps:
- name: Checkout code
Expand Down
36 changes: 36 additions & 0 deletions poly_commit/src/orion/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,39 @@ where
alphabet == codeword[index]
})
}

#[cfg(test)]
mod tests {
use arith::{Field, SimdField};
use ark_std::test_rng;
use gf2::{GF2x8, GF2};
use gf2_128::{GF2_128x8, GF2_128};
use itertools::izip;

use super::SubsetSumLUTs;

#[test]
fn test_lut_simd_inner_prod_consistency() {
let mut rng = test_rng();

let weights: Vec<_> = (0..8).map(|_| GF2_128::random_unsafe(&mut rng)).collect();
let bases: Vec<_> = (0..8).map(|_| GF2::random_unsafe(&mut rng)).collect();

let simd_weights = GF2_128x8::pack(&weights);
let simd_bases = GF2x8::pack(&bases);

let expected_simd_inner_prod: GF2_128 = (simd_weights * simd_bases).unpack().iter().sum();

let expected_vanilla_inner_prod: GF2_128 =
izip!(&weights, &bases).map(|(w, b)| *w * *b).sum();

assert_eq!(expected_simd_inner_prod, expected_vanilla_inner_prod);

let mut table = SubsetSumLUTs::new(8, 1);
table.build(&weights);

let actual_lut_inner_prod = table.lookup_and_sum(&vec![simd_bases]);

assert_eq!(expected_simd_inner_prod, actual_lut_inner_prod)
}
}
Loading