small API changes to encoding
@@ -53,7 +53,7 @@ want.iter_mut()
.for_each(|x| *x = source.next_u64n(16, 15) as i64); // m - m.encode_i64_vec(log_base2k, log_scale, &want, 4); + m.encode_vec_i64(log_base2k, log_scale, &want, 4); m.normalize(log_base2k, &mut carry); // buf_big <- m - buf_big@@ -78,7 +78,7 @@ module.vec_znx_big_normalize(log_base2k, &mut res, &buf_big, &mut carry);
// have = m * 2^{log_scale} + e let mut have: Vec<i64> = vec![i64::default(); n]; - res.decode_i64_vec(log_base2k, res.limbs() * log_base2k, &mut have); + res.decode_vec_i64(log_base2k, res.limbs() * log_base2k, &mut have); let scale: f64 = (1 << (res.limbs() * log_base2k - log_scale)) as f64; izip!(want.iter(), have.iter())
@@ -26,7 +26,7 @@ let mut a_values: Vec<i64> = vec![i64::default(); n];
a_values[1] = (1 << log_base2k) + 1; let mut a: VecZnx = module.new_vec_znx(limbs); - a.encode_i64_vec(log_base2k, log_k, &a_values, 32); + a.encode_vec_i64(log_base2k, log_k, &a_values, 32); a.normalize(log_base2k, &mut buf); (0..a.limbs()).for_each(|i| println!("{}: {:?}", i, a.at(i)));@@ -50,7 +50,7 @@ let mut res: VecZnx = module.new_vec_znx(cols);
module.vec_znx_big_normalize(log_base2k, &mut res, &c_big, &mut buf); let mut values_res: Vec<i64> = vec![i64::default(); n]; - res.decode_i64_vec(log_base2k, log_k, &mut values_res); + res.decode_vec_i64(log_base2k, log_k, &mut values_res); (0..res.limbs()).for_each(|i| println!("{}: {:?}", i, res.at(i)));
@@ -12,7 +12,7 @@ /// * `log_base2k`: base two logarithm decomposition of the receiver.
/// * `log_k`: base two logarithm of the scaling of the data. /// * `data`: data to encode on the receiver. /// * `log_max`: base two logarithm of the infinity norm of the input data. - fn encode_i64_vec(&mut self, log_base2k: usize, log_k: usize, data: &[i64], log_max: usize); + fn encode_vec_i64(&mut self, log_base2k: usize, log_k: usize, data: &[i64], log_max: usize); /// decode a vector of i64 from the receiver. ///@@ -21,7 +21,7 @@ ///
/// * `log_base2k`: base two logarithm decomposition of the receiver. /// * `log_k`: base two logarithm of the scaling of the data. /// * `data`: data to decode from the receiver. - fn decode_i64_vec(&self, log_base2k: usize, log_k: usize, data: &mut [i64]); + fn decode_vec_i64(&self, log_base2k: usize, log_k: usize, data: &mut [i64]); /// encodes a single i64 on the receiver at the given index. ///@@ -32,7 +32,7 @@ /// * `log_k`: base two logarithm of the scaling of the data.
/// * `i`: index of the coefficient on which to encode the data. /// * `data`: data to encode on the receiver. /// * `log_max`: base two logarithm of the infinity norm of the input data. - fn encode_i64_coeff( + fn encode_coeff_i64( &mut self, log_base2k: usize, log_k: usize,@@ -49,11 +49,11 @@ /// * `log_base2k`: base two logarithm decomposition of the receiver.
/// * `log_k`: base two logarithm of the scaling of the data. /// * `i`: index of the coefficient to decode. /// * `data`: data to decode from the receiver. - fn decode_i64_coeff(&self, log_base2k: usize, log_k: usize, i: usize) -> i64; + fn decode_coeff_i64(&self, log_base2k: usize, log_k: usize, i: usize) -> i64; } impl Encoding for VecZnx { - fn encode_i64_vec(&mut self, log_base2k: usize, log_k: usize, data: &[i64], log_max: usize) { + fn encode_vec_i64(&mut self, log_base2k: usize, log_k: usize, data: &[i64], log_max: usize) { let limbs: usize = (log_k + log_base2k - 1) / log_base2k; assert!(limbs <= self.limbs(), "invalid argument log_k: (log_k + self.log_base2k - 1)/self.log_base2k={} > self.limbs()={}", limbs, self.limbs());@@ -99,7 +99,7 @@ })
} } - fn decode_i64_vec(&self, log_base2k: usize, log_k: usize, data: &mut [i64]) { + fn decode_vec_i64(&self, log_base2k: usize, log_k: usize, data: &mut [i64]) { let limbs: usize = (log_k + log_base2k - 1) / log_base2k; assert!( data.len() >= self.n,@@ -123,7 +123,7 @@ }
}) } - fn encode_i64_coeff( + fn encode_coeff_i64( &mut self, log_base2k: usize, log_k: usize,@@ -168,7 +168,7 @@ })
} } - fn decode_i64_coeff(&self, log_base2k: usize, log_k: usize, i: usize) -> i64 { + fn decode_coeff_i64(&self, log_base2k: usize, log_k: usize, i: usize) -> i64 { let limbs: usize = (log_k + log_base2k - 1) / log_base2k; assert!(i < self.n()); let mut res: i64 = self.data[i];@@ -203,9 +203,9 @@ let mut have: Vec<i64> = vec![i64::default(); n];
have.iter_mut() .enumerate() .for_each(|(i, x)| *x = (i as i64) - (n as i64) / 2); - a.encode_i64_vec(log_base2k, log_k, &have, 10); + a.encode_vec_i64(log_base2k, log_k, &have, 10); let mut want = vec![i64::default(); n]; - a.decode_i64_vec(log_base2k, log_k, &mut want); + a.decode_vec_i64(log_base2k, log_k, &mut want); izip!(want, have).for_each(|(a, b)| assert_eq!(a, b)); }@@ -223,14 +223,11 @@ *x = source
.next_u64n(u64::MAX, u64::MAX) .wrapping_sub(u64::MAX / 2 + 1) as i64; }); - a.encode_i64_vec(log_base2k, log_k, &have, 63); + a.encode_vec_i64(log_base2k, log_k, &have, 63); //(0..a.limbs()).for_each(|i| println!("i:{} -> {:?}", i, a.at(i))); let mut want = vec![i64::default(); n]; //(0..a.limbs()).for_each(|i| println!("i:{} -> {:?}", i, a.at(i))); - a.decode_i64_vec(log_base2k, log_k, &mut want); + a.decode_vec_i64(log_base2k, log_k, &mut want); izip!(want, have).for_each(|(a, b)| assert_eq!(a, b, "{} != {}", a, b)); } - - #[test] - fn test_normalize() {} }
@@ -120,7 +120,7 @@ /// *x = source
/// .next_u64n(u64::MAX, u64::MAX) /// .wrapping_sub(u64::MAX / 2 + 1) as i64; /// }); - /// a.encode_i64_vec(log_base2k, log_k, &have, 63); + /// a.encode_vec_i64(log_base2k, log_k, &have, 63); /// a.normalize(log_base2k, &mut carry); /// /// // Ensures normalized values are in the range +/- 2^{log_base2k-1}@@ -131,7 +131,7 @@ /// .for_each(|x| assert!(x.abs() <= base_half, "|x|={} > 2^(k-1)={}", x, base_half));
/// /// // Ensures reconstructed normalized values are equal to non-normalized values. /// let mut want = vec![i64::default(); n]; - /// a.decode_i64_vec(log_base2k, log_k, &mut want); + /// a.decode_vec_i64(log_base2k, log_k, &mut want); /// izip!(want, have).for_each(|(a, b)| assert_eq!(a, b, "{} != {}", a, b)); /// ``` pub fn normalize(&mut self, log_base2k: usize, carry: &mut [u8]) {