Skip to content

Instantly share code, notes, and snippets.

@titouanc
Created October 24, 2023 15:31
Show Gist options
  • Save titouanc/5f1297f39d10fd3264e79d756b90e284 to your computer and use it in GitHub Desktop.
Save titouanc/5f1297f39d10fd3264e79d756b90e284 to your computer and use it in GitHub Desktop.
def distance [D] (p1: [D]f32) (p2: [D]f32): f32 =
map2 (-) p1 p2
|> map (\x -> x*x)
|> reduce (+) 0f32
|> (** 0.5)
def nearest [D][N] (data_points: [N][D]f32) (query_point: [D]f32): f32 =
map (distance query_point) data_points
|> reduce f32.min f32.inf
def main [D][N][Q] (data_points: [N][D]f32) (query_points: [Q][D]f32): [Q]f32 =
map (nearest data_points) query_points
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment