mirror of
https://github.com/cberner/raptorq.git
synced 2024-06-30 18:51:43 +00:00
Remove From and Into for Octet
This commit is contained in:
parent
5fe8ac022d
commit
e9dec4b6c8
@ -14,7 +14,7 @@ use raptorq::Symbol;
|
|||||||
fn criterion_benchmark(c: &mut Criterion) {
|
fn criterion_benchmark(c: &mut Criterion) {
|
||||||
Octet::static_init();
|
Octet::static_init();
|
||||||
|
|
||||||
let octet1 = Octet::from(rand::thread_rng().gen_range(1, 255));
|
let octet1 = Octet::new(rand::thread_rng().gen_range(1, 255));
|
||||||
let symbol_size = 512;
|
let symbol_size = 512;
|
||||||
let mut data1: Vec<u8> = vec![0; symbol_size];
|
let mut data1: Vec<u8> = vec![0; symbol_size];
|
||||||
let mut data2: Vec<u8> = vec![0; symbol_size];
|
let mut data2: Vec<u8> = vec![0; symbol_size];
|
||||||
|
@ -34,7 +34,7 @@ fn generate_mt(H: usize, Kprime: usize, S: usize) -> OctetMatrix {
|
|||||||
for j in 0..=(Kprime + S - 2) {
|
for j in 0..=(Kprime + S - 2) {
|
||||||
if i == rand((j + 1) as u32, 6, H as u32) as usize ||
|
if i == rand((j + 1) as u32, 6, H as u32) as usize ||
|
||||||
i == ((rand((j + 1) as u32, 6, H as u32) + rand((j + 1) as u32, 7, (H - 1) as u32) + 1) % (H as u32)) as usize {
|
i == ((rand((j + 1) as u32, 6, H as u32) + rand((j + 1) as u32, 7, (H - 1) as u32) + 1) % (H as u32)) as usize {
|
||||||
matrix.set(i, j, 1.into());
|
matrix.set(i, j, Octet::one());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
matrix.set(i, Kprime + S - 1, Octet::alpha(i as u8));
|
matrix.set(i, Kprime + S - 1, Octet::alpha(i as u8));
|
||||||
@ -100,25 +100,25 @@ pub fn generate_constraint_matrix<T:Iterator<Item=u32>>(source_block_symbols: u3
|
|||||||
let a = 1 + i / S;
|
let a = 1 + i / S;
|
||||||
|
|
||||||
let b = i % S;
|
let b = i % S;
|
||||||
matrix.set(b, i, 1.into());
|
matrix.set(b, i, Octet::one());
|
||||||
|
|
||||||
let b = (b + a) % S;
|
let b = (b + a) % S;
|
||||||
matrix.set(b, i, 1.into());
|
matrix.set(b, i, Octet::one());
|
||||||
|
|
||||||
let b = (b + a) % S;
|
let b = (b + a) % S;
|
||||||
matrix.set(b, i, 1.into());
|
matrix.set(b, i, Octet::one());
|
||||||
}
|
}
|
||||||
|
|
||||||
// I_S
|
// I_S
|
||||||
for i in 0..S {
|
for i in 0..S {
|
||||||
matrix.set(i as usize, i + B as usize, 1.into());
|
matrix.set(i as usize, i + B as usize, Octet::one());
|
||||||
}
|
}
|
||||||
|
|
||||||
// G_LDPC,2
|
// G_LDPC,2
|
||||||
// See section 5.3.3.3
|
// See section 5.3.3.3
|
||||||
for i in 0..S {
|
for i in 0..S {
|
||||||
matrix.set(i, (i % P) + W, 1.into());
|
matrix.set(i, (i % P) + W, Octet::one());
|
||||||
matrix.set(i, ((i + 1) % P) + W, 1.into());
|
matrix.set(i, ((i + 1) % P) + W, Octet::one());
|
||||||
}
|
}
|
||||||
|
|
||||||
// G_HDPC
|
// G_HDPC
|
||||||
@ -131,7 +131,7 @@ pub fn generate_constraint_matrix<T:Iterator<Item=u32>>(source_block_symbols: u3
|
|||||||
|
|
||||||
// I_H
|
// I_H
|
||||||
for i in 0..H {
|
for i in 0..H {
|
||||||
matrix.set(i + S as usize, i + (Kprime + S) as usize, 1.into());
|
matrix.set(i + S as usize, i + (Kprime + S) as usize, Octet::one());
|
||||||
}
|
}
|
||||||
|
|
||||||
// G_ENC
|
// G_ENC
|
||||||
@ -141,7 +141,7 @@ pub fn generate_constraint_matrix<T:Iterator<Item=u32>>(source_block_symbols: u3
|
|||||||
let tuple = intermediate_tuple(Kprime as u32, i);
|
let tuple = intermediate_tuple(Kprime as u32, i);
|
||||||
|
|
||||||
for j in enc_indices(Kprime as u32, tuple) {
|
for j in enc_indices(Kprime as u32, tuple) {
|
||||||
matrix.set(row as usize + S + H, j, 1.into());
|
matrix.set(row as usize + S + H, j, Octet::one());
|
||||||
}
|
}
|
||||||
row += 1;
|
row += 1;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ impl OctetMatrix {
|
|||||||
pub fn new(height: usize, width: usize) -> OctetMatrix {
|
pub fn new(height: usize, width: usize) -> OctetMatrix {
|
||||||
let mut elements: Vec<Vec<Octet>> = vec![];
|
let mut elements: Vec<Vec<Octet>> = vec![];
|
||||||
for _ in 0..height {
|
for _ in 0..height {
|
||||||
elements.push(vec![0.into(); width]);
|
elements.push(vec![Octet::zero(); width]);
|
||||||
}
|
}
|
||||||
OctetMatrix {
|
OctetMatrix {
|
||||||
height,
|
height,
|
||||||
@ -74,9 +74,9 @@ impl OctetMatrix {
|
|||||||
let mut intermediate = self.elements.clone();
|
let mut intermediate = self.elements.clone();
|
||||||
for i in 0..self.height {
|
for i in 0..self.height {
|
||||||
for _ in 0..self.width {
|
for _ in 0..self.width {
|
||||||
intermediate[i].push(0.into());
|
intermediate[i].push(Octet::zero());
|
||||||
}
|
}
|
||||||
intermediate[i][self.width + i] = 1.into();
|
intermediate[i][self.width + i] = Octet::one();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to row echelon form
|
// Convert to row echelon form
|
||||||
@ -95,8 +95,8 @@ impl OctetMatrix {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Scale leading coefficient to 1
|
// Scale leading coefficient to 1
|
||||||
if intermediate[i][i] != 1.into() {
|
if intermediate[i][i] != Octet::one() {
|
||||||
let element_inverse = Octet::from(1) / intermediate[i][i].clone();
|
let element_inverse = Octet::one() / intermediate[i][i].clone();
|
||||||
for j in i..(2*self.width) {
|
for j in i..(2*self.width) {
|
||||||
intermediate[i][j] = intermediate[i][j].clone() * element_inverse.clone();
|
intermediate[i][j] = intermediate[i][j].clone() * element_inverse.clone();
|
||||||
}
|
}
|
||||||
|
18
src/octet.rs
18
src/octet.rs
@ -152,20 +152,6 @@ impl Octet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<u8> for Octet {
|
|
||||||
fn from(value: u8) -> Octet {
|
|
||||||
Octet {
|
|
||||||
value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Into<u8> for Octet {
|
|
||||||
fn into(self) -> u8 {
|
|
||||||
self.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Add for Octet {
|
impl Add for Octet {
|
||||||
type Output = Octet;
|
type Output = Octet;
|
||||||
|
|
||||||
@ -340,8 +326,8 @@ mod tests {
|
|||||||
let mut fma_result = Octet::zero();
|
let mut fma_result = Octet::zero();
|
||||||
for i in 0..255 {
|
for i in 0..255 {
|
||||||
for j in 0..255 {
|
for j in 0..255 {
|
||||||
result += Octet::from(i) * Octet::from(j);
|
result += Octet::new(i) * Octet::new(j);
|
||||||
fma_result.fma(&Octet::from(i), &Octet::from(j));
|
fma_result.fma(&Octet::new(i), &Octet::new(j));
|
||||||
assert_eq!(result, fma_result);
|
assert_eq!(result, fma_result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user