strided_trick.py 698 B

1234567891011121314151617
  1. from evaluator import *
  2. DESCRIPTION = "Test if the model knows how to use the strided trick with numpy."
  3. TAGS = ['code', 'python', 'performance']
  4. question = """
  5. Write a function strides() that given an array of tokens T as numpy array, using strided trick, returns [T[0:50], T[10:60], T[20: 70] ... ]
  6. """
  7. test_case, answer = make_python_test([("strides(np.arange(100)).shape", "(6, 50)"),
  8. ("strides(np.arange(100)).sum()", "14850")])
  9. TestProgramStrided = question >> LLMRun() >> ExtractCode() >> ((PythonRun(test_case) >> (SubstringEvaluator(answer))) & SubstringEvaluator("as_strided"))
  10. if __name__ == "__main__":
  11. print(run_test(TestProgramStrided))