Functionalize nearest neighbor computation.