Index Mathematics Conjectures nbv lettuce Widgets

chunks_flat_map!

Map a block over consecutive chunks of a vector and concatenate the results. Loops and mapping

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

Splits vector into consecutive chunks of chunk_len elements and 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. The block values are concatenated in order. Useful for operating on matrices stored row by row or on batches of fixed-size items.

Arguments

vector
Static or witness vector.
chunk_len
Static scalar, the chunk length. If it does not divide the length the last chunk is shorter.
chunk
Optional. A bare variable name bound to the current chunk; without it the block cannot see the chunk.
i
Optional. A bare variable name bound to the static chunk index.
{ ... }
Required block ending in a final expression, a non-empty vector.

Returns

The concatenation of the block values, an expression; static if every block value is static, a witness if every block value is a witness.

Constraints

None of its own. Behaves the same in the static VM.

Example

(let x)
chunks_flat_map! x, 2, c {
  concat! c[1], c[0] * c[1]
}

Notes

Used in the standard library

ext/ext_vec_mul, mat_vec_mul, mersenne61/poseidon/poseidon_mersenne61_state, milli/poseidon/poseidon_milli_state, oraccle/oraccle_sample_ternary_vec, oraccle/oraccle_squeeze, polynomial/intt_negacyclic_vec, polynomial/mat_poly_mul_vec, polynomial/ntt_negacyclic_mat, polynomial/ntt_negacyclic_vec, polynomial/vec_poly_scalar_mul