Skip to content

Commit 1c279ea

Browse files
committed
Use rayon in inner product and update readme
Signed-off-by: lovesh <[email protected]>
1 parent 7d4a684 commit 1c279ea

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "amcl_wrapper"
3-
version = "0.3.4"
3+
version = "0.3.5"
44
authors = ["lovesh harchandani <[email protected]>"]
55
description = "Wapper over Milagro Cryptographic Library (version 3)"
66
repository = "https://github.com/lovesh/amcl_rust_wrapper"

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
## Building
1313
The wrapper has to be built by enabling any one of the mentioned curve as a feature.
14-
To build for BLS-381 curve, use (BLS381 is the default curve so not using `--no-default-features` is fine)
14+
To build for BLS-381 curve, use
1515

1616
```
1717
cargo build --no-default-features --features bls381
@@ -27,11 +27,11 @@ To run tests for secp256k1, use
2727
cargo test --no-default-features --features secp256k1
2828
```
2929

30-
To use it as dependency crate, add the name of the curve as a feature. Something like this
30+
To use it as dependency crate, use the name of the curve as a feature. eg. for BLS12-381 curve, use
3131
```
3232
[dependencies.amcl_wrapper]
33-
git = "https://github.com/lovesh/amcl_rust_wrapper"
34-
branch = "master"
33+
version = "0.3.4"
34+
default-features = false
3535
features = ["bls381"]
3636
```
3737

@@ -297,6 +297,7 @@ let diff = &poly1 - &poly2;
297297
let product = UnivarPolynomial::multiply(&poly1, &poly2);
298298
// Or use operator overloading
299299
let product = &poly1 * &poly2;
300+
// Dividing polynomials: poly1 / poly2
300301
let (quotient, rem) = UnivarPolynomial::long_division(&poly1, &poly2);
301302
```
302303

src/field_elem.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,8 @@ impl FieldElementVector {
886886
/// [a1, a2, a3, ...field elements].[b1, b2, b3, ...field elements] = (a1*b1 + a2*b2 + a3*b3) % curve_order
887887
pub fn inner_product(&self, b: &FieldElementVector) -> Result<FieldElement, ValueError> {
888888
check_vector_size_for_equality!(self, b)?;
889-
let mut accum = FieldElement::new();
890-
for i in 0..self.len() {
891-
accum += &self[i] * &b[i];
892-
}
893-
Ok(accum)
889+
let r = (0..b.len()).into_par_iter().map(|i| (&self[i] * &b[i])).reduce(|| FieldElement::new(), |a, b| a + b);
890+
Ok(r)
894891
}
895892

896893
/// Calculates Hadamard product of 2 field element vectors.
@@ -1405,7 +1402,7 @@ mod test {
14051402
assert_eq!(x, FieldElement::from_power_of_2_base(&b, 3));
14061403
}
14071404

1408-
for i in 0..100 {
1405+
for _ in 0..100 {
14091406
let x = FieldElement::random();
14101407
for base in 2..8 {
14111408
let digits = x.to_power_of_2_base(base);

src/group_elem.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use rand::{CryptoRng, RngCore};
33
use crate::errors::{SerzDeserzError, ValueError};
44
use crate::field_elem::{FieldElement, FieldElementVector};
55

6-
use crate::rayon::iter::IntoParallelRefMutIterator;
76
use rayon::prelude::*;
87
use std::slice::Iter;
98

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#![allow(non_snake_case)]
1+
#[allow(non_snake_case)]
2+
#[allow(non_upper_case_globals)]
23

34
pub extern crate amcl;
45

@@ -22,7 +23,6 @@ extern crate serde;
2223
#[macro_use]
2324
extern crate serde_derive;
2425

25-
#[macro_use]
2626
extern crate serde_json;
2727

2828
extern crate rayon;

0 commit comments

Comments
 (0)