Created
October 24, 2023 15:31
-
-
Save titouanc/5f1297f39d10fd3264e79d756b90e284 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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