
import os

import numpy
import onnx






def 		_UpperCAmelCase   (	UpperCamelCase:     int			,							UpperCamelCase:     Tuple  ):






	"""simple docstring"""


	__lowerCAmelCase         =							a.name
	__lowerCAmelCase         =							b.name

	__lowerCAmelCase         =							""
	__lowerCAmelCase         =							""

	__lowerCAmelCase         =							a == b

	__lowerCAmelCase         =							name_a
	__lowerCAmelCase         =							name_b

	return res






def 		_UpperCAmelCase   (	UpperCamelCase:     Optional[Any]			,							UpperCamelCase:     Optional[Any]			,							UpperCamelCase:     Union[str, Any]  ):






	"""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 		_UpperCAmelCase   (	UpperCamelCase:     Union[str, Any]			,							UpperCamelCase:     Tuple			,							UpperCamelCase:     Optional[Any]  ):






	"""simple docstring"""


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






def 		_UpperCAmelCase   (	UpperCamelCase:     List[str]			,							UpperCamelCase:     str			,							UpperCamelCase:     int  ):






	"""simple docstring"""


	__lowerCAmelCase         =							list(model.graph.initializer  )
	__lowerCAmelCase         =							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

		__lowerCAmelCase         =							inits[i].name
		__lowerCAmelCase         =							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 		_UpperCAmelCase   (	UpperCamelCase:     Any  ):






	"""simple docstring"""


	__lowerCAmelCase         =							os.path.dirname(_lowerCAmelCase  )
	__lowerCAmelCase         =							os.path.basename(_lowerCAmelCase  )

	__lowerCAmelCase         =							onnx.load(os.path.join(_lowerCAmelCase			,							_lowerCAmelCase  )  )

	__lowerCAmelCase         =							list(model.graph.initializer  )

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

	__lowerCAmelCase         =							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  )

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

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

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

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

	__lowerCAmelCase         =							sorted(_lowerCAmelCase  )
	_remove_dup_initializers_from_model(_lowerCAmelCase			,							_lowerCAmelCase			,							_lowerCAmelCase  )

	__lowerCAmelCase         =							"optimized_" + model_file_name
	__lowerCAmelCase         =							os.path.join(_lowerCAmelCase			,							_lowerCAmelCase  )
	onnx.save(_lowerCAmelCase			,							_lowerCAmelCase  )

	return new_model



from __future__ import annotations

UpperCamelCase_   	=	[True] * 1_0_0_0_0_0_1
UpperCamelCase_   	=	2
while i * i <= 1_0_0_0_0_0_0:
					if seive[i]:
										for j in range(i * i, 1_0_0_0_0_0_1, i):
															UpperCamelCase_   	=	False
					i += 1






def 		_UpperCAmelCase   (	UpperCamelCase:     int  ):






	"""simple docstring"""


	return seive[n]






def 		_UpperCAmelCase   (	UpperCamelCase:     int  ):






	"""simple docstring"""


	return any(digit in "02468" for digit in str(UpperCamelCase  )  )






def 		_UpperCAmelCase   (	UpperCamelCase:     int = 1_0_0_0_0_0_0  ):






	"""simple docstring"""


	__lowerCAmelCase         =							[2]  # result already includes the number 2.
	for num in range(3			,							limit + 1			,							2  ):
		if is_prime(UpperCamelCase  ) and not contains_an_even_digit(UpperCamelCase  ):
			__lowerCAmelCase         =							str(UpperCamelCase  )
			__lowerCAmelCase         =							[int(str_num[j:] + str_num[:j]  ) for j in range(len(UpperCamelCase  )  )]
			if all(is_prime(UpperCamelCase  ) for i in list_nums  ):
				result.append(UpperCamelCase  )
	return result






def 		_UpperCAmelCase   (	):






	"""simple docstring"""


	return len(find_circular_primes()  )


if __name__ == "__main__":
					print(f'''{len(find_circular_primes()) = }''')






