MCPcopy Create free account
hub / github.com/modelscope/modelscope / compare_arguments_nested

Function compare_arguments_nested

modelscope/utils/test_utils.py:146–227  ·  view source on GitHub ↗
(print_content,
                             arg1,
                             arg2,
                             rtol=1.e-3,
                             atol=1.e-8,
                             ignore_unknown_type=True)

Source from the content-addressed store, hash-verified

144
145
146def compare_arguments_nested(print_content,
147 arg1,
148 arg2,
149 rtol=1.e-3,
150 atol=1.e-8,
151 ignore_unknown_type=True):
152 type1 = type(arg1)
153 type2 = type(arg2)
154 if type1.__name__ != type2.__name__:
155 if print_content is not None:
156 print(
157 f'{print_content}, type not equal:{type1.__name__} and {type2.__name__}'
158 )
159 return False
160
161 if arg1 is None:
162 return True
163 elif isinstance(arg1, (int, str, bool, np.bool_, np.integer, np.str_)):
164 if arg1 != arg2:
165 if print_content is not None:
166 print(f'{print_content}, arg1:{arg1}, arg2:{arg2}')
167 return False
168 return True
169 elif isinstance(arg1, (float, np.floating)):
170 if not np.isclose(arg1, arg2, rtol=rtol, atol=atol, equal_nan=True):
171 if print_content is not None:
172 print(f'{print_content}, arg1:{arg1}, arg2:{arg2}')
173 return False
174 return True
175 elif isinstance(arg1, (tuple, list)):
176 if len(arg1) != len(arg2):
177 if print_content is not None:
178 print(
179 f'{print_content}, length is not equal:{len(arg1)}, {len(arg2)}'
180 )
181 return False
182 if not all([
183 compare_arguments_nested(
184 None, sub_arg1, sub_arg2, rtol=rtol, atol=atol)
185 for sub_arg1, sub_arg2 in zip(arg1, arg2)
186 ]):
187 if print_content is not None:
188 print(f'{print_content}')
189 return False
190 return True
191 elif isinstance(arg1, Mapping):
192 keys1 = arg1.keys()
193 keys2 = arg2.keys()
194 if len(keys1) != len(keys2):
195 if print_content is not None:
196 print(
197 f'{print_content}, key length is not equal:{len(keys1)}, {len(keys2)}'
198 )
199 return False
200 if len(set(keys1) - set(keys2)) > 0:
201 if print_content is not None:
202 print(f'{print_content}, key diff:{set(keys1) - set(keys2)}')
203 return False

Callers 12

_validate_modelMethod · 0.90
export_saved_modelMethod · 0.90
compare_io_and_printFunction · 0.85
_validate_onnx_modelMethod · 0.85
_validate_onnx_modelMethod · 0.85
compare_fnMethod · 0.85
test_save_pretrainedMethod · 0.85
_validate_onnx_modelMethod · 0.85

Calls 3

printFunction · 0.85
keysMethod · 0.45
whereMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…