numba_levenshtein.py 822 B

1234567891011121314151617
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model can generate a numba implementation of the Levenshtein distance algorithm."
  3. TAGS = ['code', 'python', 'performance']
  4. question = """
  5. Write me a numba implementation of levensthin distance, taking two numpy int arrays. Call it levenshtein. Run it in nopython mode. Character swaps are cost 2.
  6. """
  7. test_case, answer = make_python_test([("levenshtein(np.array([3, 5, 2, 4, 8, 7]), np.array([3, 4, 2, 4, 8, 7, 9]))", "3")])
  8. TestProgramNumbaLev = question >> LLMRun() >> ExtractCode(keep_main=False) >> (((SubstringEvaluator("from numba") | SubstringEvaluator("import numba")) & (SubstringEvaluator("nopython") | SubstringEvaluator("njit"))) & PythonRun(test_case) >> SubstringEvaluator(answer))
  9. if __name__ == "__main__":
  10. print(run_test(TestProgramNumbaLev))