MCPcopy Create free account
hub / github.com/MegEngine/MegCC / compare_file_or_dir

Function compare_file_or_dir

script/test_model.py:124–163  ·  view source on GitHub ↗
(path_0, path_1, eps, output_name_2_dtype)

Source from the content-addressed store, hash-verified

122
123
124def compare_file_or_dir(path_0, path_1, eps, output_name_2_dtype):
125 compare_file_cnt = 0
126 dtype_str_2_np = {"f32": np.float32, "ui8": np.uint8,
127 "f16": np.float16, "si8": np.int8, "si32": np.int32}
128 if os.path.isdir(path_0) and os.path.isdir(path_1):
129 file_names = os.listdir(path_0)
130 for file_name in file_names:
131 output_name = None
132 for i in output_name_2_dtype.keys():
133 if re.search("^"+i+"_[0-9]+$", file_name):
134 output_name = i
135 break
136 assert output_name
137 file_path_0 = os.path.join(path_0, file_name)
138 file_path_1 = os.path.join(path_1, file_name)
139 assert os.path.exists(file_path_0), "can not find {}".format(
140 file_path_0)
141 assert os.path.exists(file_path_1), "can not find {}".format(
142 file_path_1)
143 compare_file(file_path_0, file_path_1, eps,
144 dtype_str_2_np[output_name_2_dtype[output_name]])
145 compare_file_cnt += 1
146 else:
147 assert os.path.isfile(path_0), "can not find {}".format(path_0)
148 assert os.path.isfile(path_1), "can not find {}".format(path_1)
149 output_name = None
150 for i in output_name_2_dtype.keys():
151 if re.search(i+"_[0-9]+$", file_name):
152 output_name = i
153 break
154 assert output_name
155 compare_file(path_0, path_1, eps,
156 dtype_str_2_np[output_name_2_dtype[output_name]])
157 compare_file_cnt += 1
158 if compare_file_cnt > 0:
159 print("compare pass!!")
160 return True
161 else:
162 print("no file compared!!")
163 return False
164
165
166def parse_dump_dir(user_mdl_str):

Callers 1

auto_checkFunction · 0.85

Calls 2

searchMethod · 0.80
compare_fileFunction · 0.70

Tested by

no test coverage detected