MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / merge_bucket

Method merge_bucket

datasets/multi_resolution_sampler.py:41–62  ·  view source on GitHub ↗
(bucket_dict: OrderedDict, min_length: int)

Source from the content-addressed store, hash-verified

39 bucket_dict[bucket_key].append(idx)
40
41 def merge_bucket(bucket_dict: OrderedDict, min_length: int):
42 all_pass = False
43 while not all_pass:
44 all_pass = True
45 keys = list(bucket_dict.keys())
46 to_pop_keys = []
47 for key_idx, (key, idx_list) in enumerate(bucket_dict.items()):
48 if len(idx_list) < min_length:
49 all_pass = False
50 if key_idx == len(bucket_dict) - 1:
51 continue
52 tgt_key = keys[key_idx + 1]
53 bucket_dict[tgt_key] = idx_list + bucket_dict[tgt_key]
54 to_pop_keys.append(key)
55 for key in to_pop_keys:
56 bucket_dict.pop(key)
57 keys = list(bucket_dict.keys())
58 if len(bucket_dict[keys[-1]]) < min_length:
59 bucket_dict[keys[-2]] = bucket_dict[
60 keys[-2]] + bucket_dict[keys[-1]]
61 bucket_dict.pop(keys[-1])
62 return bucket_dict
63
64 for bucket_key, idx_list in bucket_dict.items():
65 print(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected