MCPcopy Create free account
hub / github.com/zai-org/CodeGeeX / LMDBDataset

Class LMDBDataset

codegeex/mindspore/src/sat_dataset.py:18–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16
17
18class LMDBDataset(Dataset):
19 def __init__(self, path, process_fn=None):
20 import lmdb
21
22 self.path = path
23 self.env = lmdb.open(
24 path,
25 max_readers=32,
26 readonly=True,
27 lock=False,
28 readahead=False,
29 meminit=False,
30 )
31 self.process_fn = process_fn
32 if not self.env:
33 raise IOError("Cannot open lmdb dataset", path)
34
35 with self.env.begin(write=False) as txn:
36 self.length = int(txn.get("length".encode("utf-8")).decode("utf-8"))
37
38 def __len__(self):
39 return self.length
40
41 def __getitem__(self, idx):
42 # print(f"Get {self.path}: {idx}")
43 with self.env.begin(write=False) as txn:
44 key = str(idx).encode("utf-8")
45 # row = pickle.loads(txn.get(key))
46 try:
47 row = pickle.loads(txn.get(key))
48 except TypeError:
49 raise IndexError("Index out of range")
50 if self.process_fn:
51 return self.process_fn(row)
52 else:
53 return row
54
55
56class PadDataset(Dataset):

Callers 4

run_predictFunction · 0.90
get_code_data_trainFunction · 0.85
get_code_data_evalFunction · 0.85
get_code_dataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected