Index Mathematics Conjectures nbv lettuce Widgets

chunks_sum_map!

Sum consecutive chunks of a vector element-wise, optionally mapping each chunk through a block. Loops and mapping

chunks_sum_map! vector, chunk_len[, chunk[, i]] [{ ... }]

Splits vector into consecutive chunks of chunk_len elements. Without a block it returns the element-wise sum of the chunks, a vector of length chunk_len (for a matrix stored row by row, the sum of its rows). With a block it runs the block once per chunk, with chunk bound to the chunk and the optional counter to the static chunk index, each in a fresh inner scope, and adds the block values element-wise.

Arguments

vector
Static or witness vector, its length a multiple of chunk_len.
chunk_len
Static scalar, the chunk length.
chunk
Optional, with a block. A bare variable name bound to the current chunk.
i
Optional, with a block. A bare variable name bound to the static chunk index.
{ ... }
Optional block ending in a final expression, a non-empty vector of the same length for every chunk.

Returns

The element-wise sum, an expression; a witness if any summed value is a witness.

Constraints

None; sums are linear. The block's operations add their own. Behaves the same in the static VM.

Example

(let x)
chunks_sum_map! x, 2
(let x)
chunks_sum_map! x, 2, c {
  c * c
}

Notes

Used in the standard library

ext/ext_recompose, ext/ext_sum, polynomial/mat_poly_mul_vec, slip/slip_r1cs_arg_verify