Skip to content

Instantly share code, notes, and snippets.

@athas
Created October 27, 2020 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athas/28843a088ce60c6ca7bcf6a3c8f95a26 to your computer and use it in GitHub Desktop.
Save athas/28843a088ce60c6ca7bcf6a3c8f95a26 to your computer and use it in GitHub Desktop.
-- Summarises an n-element input in k bins, with each of the k bins
-- containing the maximum of the input in that span.
let main [n] (k: i64) (samples: [n]i32) =
let bin_size = f32.i64 n / f32.i64 k
let index i = i64.f32 (f32.i64 i / bin_size)
in reduce_by_index (replicate k 0) i32.max i32.highest
(map index (iota n)) samples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment