(print_content,
arg1,
arg2,
rtol=1.e-3,
atol=1.e-8,
ignore_unknown_type=True)
| 144 | |
| 145 | |
| 146 | def 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 |
no test coverage detected
searching dependent graphs…