forked from SWE-bench/SWE-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
45 lines (36 loc) · 1.19 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
def get_instances(instance_path: str) -> list:
"""
Get task instances from given path
Args:
instance_path (str): Path to task instances
Returns:
task_instances (list): List of task instances
"""
if any([instance_path.endswith(x) for x in [".jsonl", ".jsonl.all"]]):
task_instances = list()
with open(instance_path) as f:
for line in f.readlines():
task_instances.append(json.loads(line))
return task_instances
with open(instance_path) as f:
task_instances = json.load(f)
return task_instances
def split_instances(input_list: list, n: int) -> list:
"""
Split a list into n approximately equal length sublists
Args:
input_list (list): List to split
n (int): Number of sublists to split into
Returns:
result (list): List of sublists
"""
avg_length = len(input_list) // n
remainder = len(input_list) % n
result, start = [], 0
for i in range(n):
length = avg_length + 1 if i < remainder else avg_length
sublist = input_list[start : start + length]
result.append(sublist)
start += length
return result