fix: Fix error in calling of monic function
This commit is contained in:
parent
1b45c192b3
commit
1290adcd9b
2 changed files with 18 additions and 13 deletions
|
|
@ -82,11 +82,11 @@ pub fn gfpoly_sort(args: &Value) -> Result<Vec<Polynomial>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gfpoly_make_monic(args: &Value) -> Result<Polynomial> {
|
pub fn gfpoly_make_monic(args: &Value) -> Result<Polynomial> {
|
||||||
let mut poly_a = Polynomial::from_c_array(&args["A"].clone());
|
let poly_a = Polynomial::from_c_array(&args["A"].clone());
|
||||||
|
|
||||||
poly_a.monic();
|
let result = poly_a.monic();
|
||||||
|
|
||||||
Ok(poly_a)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn gfpoly_sqrt(args: &Value) -> Result<Polynomial> {
|
pub fn gfpoly_sqrt(args: &Value) -> Result<Polynomial> {
|
||||||
|
|
|
||||||
|
|
@ -256,7 +256,7 @@ impl Polynomial {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn monic(&mut self) {
|
pub fn monic(mut self) -> Self {
|
||||||
let divident = self.polynomial.last().unwrap().clone();
|
let divident = self.polynomial.last().unwrap().clone();
|
||||||
|
|
||||||
for fieldelement in &mut self.polynomial.iter_mut() {
|
for fieldelement in &mut self.polynomial.iter_mut() {
|
||||||
|
|
@ -274,6 +274,11 @@ impl Polynomial {
|
||||||
{
|
{
|
||||||
self.polynomial.pop();
|
self.polynomial.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.is_empty() {
|
||||||
|
self = Polynomial::new(vec![FieldElement::new(vec![0; 16])]);
|
||||||
|
}
|
||||||
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sqrt(self) -> Self {
|
pub fn sqrt(self) -> Self {
|
||||||
|
|
@ -1129,22 +1134,22 @@ mod tests {
|
||||||
"1Ial5rAJGOucIdUe3zh5bw==",
|
"1Ial5rAJGOucIdUe3zh5bw==",
|
||||||
"gAAAAAAAAAAAAAAAAAAAAA=="
|
"gAAAAAAAAAAAAAAAAAAAAA=="
|
||||||
]);
|
]);
|
||||||
let mut element1: Polynomial = Polynomial::from_c_array(&json1);
|
let element1: Polynomial = Polynomial::from_c_array(&json1);
|
||||||
|
|
||||||
element1.monic();
|
let result = element1.monic();
|
||||||
|
|
||||||
assert_eq!(json!(element1.to_c_array()), expected);
|
assert_eq!(json!(result.to_c_array()), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_poly_monic_poly_zero() {
|
fn test_poly_monic_poly_zero() {
|
||||||
let json1 = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]);
|
let json1 = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]);
|
||||||
let expected = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]);
|
let expected = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]);
|
||||||
let mut element1: Polynomial = Polynomial::from_c_array(&json1);
|
let element1: Polynomial = Polynomial::from_c_array(&json1);
|
||||||
|
|
||||||
element1.monic();
|
let result = element1.monic();
|
||||||
|
|
||||||
assert_eq!(json!(element1.to_c_array()), expected);
|
assert_eq!(json!(result.to_c_array()), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -1156,11 +1161,11 @@ mod tests {
|
||||||
"AAAAAAAAAAAAAAAAAAAAAA=="
|
"AAAAAAAAAAAAAAAAAAAAAA=="
|
||||||
]);
|
]);
|
||||||
let expected = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]);
|
let expected = json!(["AAAAAAAAAAAAAAAAAAAAAA=="]);
|
||||||
let mut element1: Polynomial = Polynomial::from_c_array(&json1);
|
let element1: Polynomial = Polynomial::from_c_array(&json1);
|
||||||
|
|
||||||
element1.monic();
|
let result = element1.monic();
|
||||||
|
|
||||||
assert_eq!(json!(element1.to_c_array()), expected);
|
assert_eq!(json!(result.to_c_array()), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue