





"""simple docstring"""





import os

import numpy
import onnx


def 					a__    (    _SCREAMING_SNAKE_CASE     ,		_SCREAMING_SNAKE_CASE			):




		"""simple docstring"""


		UpperCamelCase      =		a.name
		UpperCamelCase      =		b.name

		UpperCamelCase      =		""
		UpperCamelCase      =		""

		UpperCamelCase      =		a == b

		UpperCamelCase      =		name_a
		UpperCamelCase      =		name_b

		return res


def 					a__    (    _SCREAMING_SNAKE_CASE     ,		_SCREAMING_SNAKE_CASE     ,		_SCREAMING_SNAKE_CASE			):




		"""simple docstring"""


		for i, input_name in enumerate(node_proto.input			):
				if input_name == name:
						node_proto.input.insert(__lowerCamelCase     ,		__lowerCamelCase			)
						node_proto.input.pop(i + 1			)

		if node_proto.op_type == "If":
				_graph_replace_input_with(node_proto.attribute[0].g     ,		__lowerCamelCase     ,		__lowerCamelCase			)
				_graph_replace_input_with(node_proto.attribute[1].g     ,		__lowerCamelCase     ,		__lowerCamelCase			)
		if node_proto.op_type == "Loop":
				_graph_replace_input_with(node_proto.attribute[0].g     ,		__lowerCamelCase     ,		__lowerCamelCase			)


def 					a__    (    _SCREAMING_SNAKE_CASE     ,		_SCREAMING_SNAKE_CASE     ,		_SCREAMING_SNAKE_CASE			):




		"""simple docstring"""


		for n in graph_proto.node:
				_node_replace_input_with(__lowerCamelCase     ,		__lowerCamelCase     ,		__lowerCamelCase			)


def 					a__    (    _SCREAMING_SNAKE_CASE     ,		_SCREAMING_SNAKE_CASE     ,		_SCREAMING_SNAKE_CASE			):




		"""simple docstring"""


		UpperCamelCase      =		list(model.graph.initializer			)
		UpperCamelCase      =		list(model_without_ext.graph.initializer			)
		for i, ref_i in ind_to_replace:
				assert inits_with_data[i].name == inits[i].name
				assert inits_with_data[ref_i].name == inits[ref_i].name
				assert i > ref_i

				UpperCamelCase      =		inits[i].name
				UpperCamelCase      =		inits[ref_i].name

				model_without_ext.graph.initializer.remove(inits[i]			)

				# for n in model.graph.node:
				_graph_replace_input_with(model_without_ext.graph     ,		__lowerCamelCase     ,		__lowerCamelCase			)






def 					a__    (    _SCREAMING_SNAKE_CASE			):




		"""simple docstring"""


		UpperCamelCase      =		os.path.dirname(__lowerCamelCase			)
		UpperCamelCase      =		os.path.basename(__lowerCamelCase			)

		UpperCamelCase      =		onnx.load(os.path.join(__lowerCamelCase     ,		__lowerCamelCase			)			)

		UpperCamelCase      =		list(model.graph.initializer			)

		UpperCamelCase      =		set()
		UpperCamelCase      =		{}
		UpperCamelCase      =		[]

		UpperCamelCase      =		0

		for i in range(len(__lowerCamelCase			)			):
				if i in dup_set:
						continue

				for j in range(i + 1     ,		len(__lowerCamelCase			)			):
						if j in dup_set:
								continue
						if _is_equal_tensor_proto(inits[i]     ,		inits[j]			):
								dup_set.add(__lowerCamelCase			)
								dup_set.add(__lowerCamelCase			)

								UpperCamelCase      =		inits[j].data_type
								UpperCamelCase      =		numpy.prod(inits[j].dims			)
								if dtype == 1:
										mem_size *= 4
								elif dtype == 6:
										mem_size *= 4
								elif dtype == 7 or dtype == 11:
										mem_size *= 8
								else:
										print("unexpected data type: "     ,		__lowerCamelCase			)
								total_reduced_size += mem_size

								UpperCamelCase      =		inits[i].name
								UpperCamelCase      =		inits[j].name

								if name_i in dup_map:
										dup_map[name_i].append(__lowerCamelCase			)
								else:
										UpperCamelCase      =		[name_j]
								ind_to_replace.append((j, i)			)

		print("total reduced size: "     ,		total_reduced_size / 1_024 / 1_024 / 1_024     ,		"GB"			)

		UpperCamelCase      =		sorted(__lowerCamelCase			)
		_remove_dup_initializers_from_model(__lowerCamelCase     ,		__lowerCamelCase     ,		__lowerCamelCase			)

		UpperCamelCase      =		"optimized_" + model_file_name
		UpperCamelCase      =		os.path.join(__lowerCamelCase     ,		__lowerCamelCase			)
		onnx.save(__lowerCamelCase     ,		__lowerCamelCase			)

		return new_model








"""simple docstring"""





def 	__a     (		__lowerCamelCase = 3,		__lowerCamelCase = 7,		__lowerCamelCase = 100_0000  ):
   UpperCAmelCase_					:					Dict			     =    0
   UpperCAmelCase_					:					List[Any]			     =    1

   for current_denominator in range(1,		limit + 1  ):
      UpperCAmelCase_					:					Dict			     =    current_denominator * numerator // denominator
      if current_denominator % denominator == 0:
         current_numerator -= 1
      if current_numerator * max_denominator > current_denominator * max_numerator:
         UpperCAmelCase_					:					List[Any]			     =    current_numerator
         UpperCAmelCase_					:					Optional[int]			     =    current_denominator
   return max_numerator


if __name__ == "__main__":
    print(solution(numerator=3, denominator=7, limit=1_000_000))


