MCPcopy Create free account
hub / github.com/docknetwork/crypto / add_vecs

Function add_vecs

utils/src/ff.rs:37–47  ·  view source on GitHub ↗

Add two vectors of scalars

(a: &[F], b: &[F])

Source from the content-addressed store, hash-verified

35
36/// Add two vectors of scalars
37pub fn add_vecs<F: Field>(a: &[F], b: &[F]) -> Vec<F> {
38 let (a_len, b_len) = (a.len(), b.len());
39 let res_len = ark_std::cmp::max(a_len, b_len);
40 cfg_into_iter!(0..res_len)
41 .map(|i| {
42 let a_i = a.get(i).cloned().unwrap_or(F::zero());
43 let b_i = b.get(i).cloned().unwrap_or(F::zero());
44 a_i + b_i
45 })
46 .collect()
47}
48
49/// Weighted inner product of 2 vectors `a` and `b` with weight `w`. Calculated as `\sum_{i=0}(a_i * b_i * w^{i+1})`
50pub fn weighted_inner_product<F: Field>(a: &[F], b: &[F], w: &F) -> F {

Callers 4

round_3Method · 0.85
g_vec_pub_offsetsMethod · 0.85
alpha_r_q_inv_powFunction · 0.85

Calls 3

mapMethod · 0.80
getMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected