Skip to content

Commit

Permalink
release v2.0.0 (#41)
Browse files Browse the repository at this point in the history
* release v2.0.0

* move test_utils to rs tester

we don't want to release them to crates.io, even
under the mock feature

* resolve cyclic dep by duplicating some test helpers

* apply suggestion

* fix
  • Loading branch information
alindima authored Jan 25, 2024
1 parent e6e641e commit df906e1
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 57 deletions.
6 changes: 3 additions & 3 deletions reed-solomon-benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ publish = false
reed-solomon-erasure = { version = "6.0.0", features = [
"simd-accel",
], optional = true }
reed-solomon-novelpoly = { package = "reed-solomon-novelpoly", path = "../reed-solomon-novelpoly" }
reed-solomon-tester = { package = "reed-solomon-tester", path = "../reed-solomon-tester" }
reed-solomon-novelpoly = { path = "../reed-solomon-novelpoly" }
reed-solomon-tester = { path = "../reed-solomon-tester" }

color-eyre = "0.6"

Expand All @@ -31,4 +31,4 @@ default = []
novelpoly-cxx = ["reed-solomon-novelpoly/with-alt-cxx-impl"]
naive = ["reed-solomon-erasure"]
upperbounds = ["naive"]
avx = ["reed-solomon-novelpoly/avx"]
avx = ["reed-solomon-novelpoly/avx", "reed-solomon-tester/avx"]
4 changes: 1 addition & 3 deletions reed-solomon-novelpoly-fuzzit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ hongg = "=0.5.61"
#hongg = { path = "../../hongg-rs/hongg", package = "hongg", version = "0.5.61" }
arbitrary = { version = "1", features = ["derive"] }
rstester = { path = "../reed-solomon-tester", package = "reed-solomon-tester" }
novelpoly = { path = "../reed-solomon-novelpoly", package = "reed-solomon-novelpoly", features = [
"mock",
] }
novelpoly = { path = "../reed-solomon-novelpoly", package = "reed-solomon-novelpoly"}
rand_chacha = "0.3.0"
rand = "0.8.3"

Expand Down
6 changes: 3 additions & 3 deletions reed-solomon-novelpoly-fuzzit/src/afft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ fn run() {
fuzz!(|params: AfftParams| {
let AfftParams { k, shift, f: _ } = params;

let mut data_plain = test_utils::gen_plain::<SmallRng>(k);
let mut data_faster8 = test_utils::gen_faster8_from_plain(&data_plain);
let mut data_plain = rstester::gen_plain::<SmallRng>(k);
let mut data_faster8 = rstester::gen_faster8_from_plain(&data_plain);

// k := size , so we need to have shift as steps of k
unsafe { &AFFT }.afft(&mut data_plain, k, shift);
unsafe { &AFFT }.afft_faster8(&mut data_faster8[..], k, shift);

test_utils::assert_plain_eq_faster8(data_plain, data_faster8);
rstester::assert_plain_eq_faster8(data_plain, data_faster8);
});
}
}
6 changes: 3 additions & 3 deletions reed-solomon-novelpoly-fuzzit/src/inverse_afft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ fn run() {
fuzz!(|params: InverseAfftParams| {
let InverseAfftParams { k, shift, f: _ } = params;

let mut data_plain = test_utils::gen_plain::<SmallRng>(k);
let mut data_faster8 = test_utils::gen_faster8_from_plain(&data_plain);
let mut data_plain = rstester::gen_plain::<SmallRng>(k);
let mut data_faster8 = rstester::gen_faster8_from_plain(&data_plain);

// k := size , so we need to have shift as steps of k
unsafe { &AFFT }.inverse_afft(&mut data_plain, k, shift);
unsafe { &AFFT }.inverse_afft_faster8(&mut data_faster8, k, shift);

test_utils::assert_plain_eq_faster8(data_plain, data_faster8);
rstester::assert_plain_eq_faster8(data_plain, data_faster8);
});
}
}
6 changes: 1 addition & 5 deletions reed-solomon-novelpoly/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "reed-solomon-novelpoly"
version = "1.0.2"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
repository = "https://github.com/paritytech/reed-solomon-novelpoly"
edition = "2021"
Expand All @@ -26,9 +26,6 @@ derive_more = { version = "0.99.0", default-features = false, features = [
"add_assign",
"add",
] }
# mock only
reed-solomon-tester = { path = "../reed-solomon-tester", optional = true }
rand = { version = "0.8.3", features = ["alloc", "small_rng"], optional = true }

[dev-dependencies]
itertools = "0.12"
Expand All @@ -40,7 +37,6 @@ quickcheck = { version = "1.0.3", default-features = false }
[features]
default = []
with-alt-cxx-impl = ["cc", "bindgen"]
mock = ["rand", "reed-solomon-tester"]
# enable the small field, experimental support
f256 = []
avx = []
65 changes: 25 additions & 40 deletions reed-solomon-novelpoly/src/field/inc_afft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,49 +473,38 @@ impl AdditiveFFT {
}
}

#[cfg(any(feature = "mock", test))]
pub mod test_utils {
use super::*;
use rand::{Rng, SeedableRng};

pub fn gen_plain<R: Rng + SeedableRng<Seed = [u8; 32]>>(size: usize) -> Vec<Additive> {
let rng = <R as SeedableRng>::from_seed(reed_solomon_tester::SMALL_RNG_SEED);
let dist = rand::distributions::Uniform::new_inclusive(Elt::MIN, Elt::MAX);

Vec::from_iter(rng.sample_iter::<Elt, _>(dist).take(size).map(Additive))
}

#[cfg(test)]
mod afft_tests {
#[cfg(all(target_feature = "avx", feature = "avx"))]
pub fn gen_faster8_from_plain(data: impl AsRef<[Additive]>) -> Vec<Additive> {
let data = data.as_ref();
data.to_vec()
}
mod simd {
use super::super::*;
use reed_solomon_tester::SMALL_RNG_SEED;
use rand::{SeedableRng, Rng, rngs::SmallRng};

#[cfg(all(target_feature = "avx", feature = "avx"))]
pub fn gen_faster8<R: Rng + SeedableRng<Seed = [u8; 32]>>(size: usize) -> Vec<Additive> {
let data = gen_plain::<R>(size);
gen_faster8_from_plain(data)
}
pub fn gen_plain<R: Rng + SeedableRng<Seed = [u8; 32]>>(size: usize) -> Vec<Additive> {
let rng = <R as SeedableRng>::from_seed(SMALL_RNG_SEED);
let dist = rand::distributions::Uniform::new_inclusive(Elt::MIN, Elt::MAX);

#[cfg(all(target_feature = "avx", feature = "avx"))]
pub fn assert_plain_eq_faster8(plain: impl AsRef<[Additive]>, faster8: impl AsRef<[Additive]>) {
let plain = plain.as_ref();
let faster8 = faster8.as_ref();
Vec::from_iter(rng.sample_iter::<Elt, _>(dist).take(size).map(Additive))
}

assert!(plain.eq(faster8));
}
}
pub fn gen_faster8_from_plain(data: impl AsRef<[Additive]>) -> Vec<Additive> {
let data = data.as_ref();
data.to_vec()
}

#[cfg(test)]
mod afft_tests {
pub fn gen_faster8<R: Rng + SeedableRng<Seed = [u8; 32]>>(size: usize) -> Vec<Additive> {
let data = gen_plain::<R>(size);
gen_faster8_from_plain(data)
}

#[cfg(all(target_feature = "avx", feature = "avx"))]
mod simd {
use super::super::*;
use super::super::test_utils::*;
use rand::rngs::SmallRng;
pub fn assert_plain_eq_faster8(plain: impl AsRef<[Additive]>, faster8: impl AsRef<[Additive]>) {
let plain = plain.as_ref();
let faster8 = faster8.as_ref();

assert!(plain.eq(faster8));
}

#[cfg(all(target_feature = "avx", feature = "avx"))]
#[test]
fn afft_output_plain_eq_faster8_size_16() {
let index = 0;
Expand All @@ -536,7 +525,6 @@ mod afft_tests {
assert_plain_eq_faster8(data_plain, data_faster8);
}

#[cfg(all(target_feature = "avx", feature = "avx"))]
#[test]
fn afft_output_plain_eq_faster8_size_32() {
let index = 0;
Expand All @@ -557,7 +545,6 @@ mod afft_tests {
assert_plain_eq_faster8(data_plain, data_faster8);
}

#[cfg(all(target_feature = "avx", feature = "avx"))]
#[test]
fn afft_output_plain_eq_faster8_impulse_data() {
let index = 0;
Expand All @@ -583,7 +570,6 @@ mod afft_tests {
assert_plain_eq_faster8(data_plain, data_faster8);
}

#[cfg(all(target_feature = "avx", feature = "avx"))]
#[test]
fn inverse_afft_output_plain_eq_faster8_size_8() {
let index = 0;
Expand All @@ -606,7 +592,6 @@ mod afft_tests {
assert_plain_eq_faster8(data_plain, data_faster8);
}

#[cfg(all(target_feature = "avx", feature = "avx"))]
#[test]
fn inverse_afft_output_plain_eq_faster8_size_32() {
let index = 0;
Expand Down
5 changes: 5 additions & 0 deletions reed-solomon-tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ rand = { version = "0.8", features = ["alloc", "small_rng"] }
fs-err = "2"

[dependencies]
reed-solomon-novelpoly = { path = "../reed-solomon-novelpoly" }

rand = { version = "0.8", features = ["alloc", "small_rng"] }
itertools = "0.12"
assert_matches = "1"

[features]
avx = []
28 changes: 28 additions & 0 deletions reed-solomon-tester/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use rand::seq::index::IndexVec;
use std::error;
use std::iter;
use std::result;
use reed_solomon_novelpoly::f2e16::{Additive, Elt};

pub static SMALL_RNG_SEED: [u8; 32] = [
0, 6, 0xFA, 0, 0x37, 3, 19, 89, 32, 32, 0x37, 0x77, 77, 0b11, 112, 52, 12, 40, 82, 34, 0, 0, 0, 1, 4, 4, 1, 4, 99,
Expand Down Expand Up @@ -165,3 +166,30 @@ where
assert_recovery(payload, &recovered_payload[..], dropped_indices, target_n, target_k);
Ok(())
}

pub fn gen_plain<R: Rng + SeedableRng<Seed = [u8; 32]>>(size: usize) -> Vec<Additive> {
let rng = <R as SeedableRng>::from_seed(SMALL_RNG_SEED);
let dist = rand::distributions::Uniform::new_inclusive(Elt::MIN, Elt::MAX);

Vec::from_iter(rng.sample_iter::<Elt, _>(dist).take(size).map(Additive))
}

#[cfg(all(target_feature = "avx", feature = "avx"))]
pub fn gen_faster8_from_plain(data: impl AsRef<[Additive]>) -> Vec<Additive> {
let data = data.as_ref();
data.to_vec()
}

#[cfg(all(target_feature = "avx", feature = "avx"))]
pub fn gen_faster8<R: Rng + SeedableRng<Seed = [u8; 32]>>(size: usize) -> Vec<Additive> {
let data = gen_plain::<R>(size);
gen_faster8_from_plain(data)
}

#[cfg(all(target_feature = "avx", feature = "avx"))]
pub fn assert_plain_eq_faster8(plain: impl AsRef<[Additive]>, faster8: impl AsRef<[Additive]>) {
let plain = plain.as_ref();
let faster8 = faster8.as_ref();

assert!(plain.eq(faster8));
}

0 comments on commit df906e1

Please sign in to comment.