


def     _lowercase							(  __lowerCamelCase      :       int      )	-> str:





     '''simple docstring'''





     UpperCamelCase__				:	Optional[int]										=  abs(UpperCamelCase__      )
     UpperCamelCase__				:	int										=  0
     while n > 0:
          res += n % 10
          n //= 10
     return res







def     _lowercase							(  __lowerCamelCase      :       int      )	-> int:





     '''simple docstring'''





     UpperCamelCase__				:	str										=  abs(UpperCamelCase__      )
     return n if n < 10 else n % 10 + sum_of_digits(n // 10      )







def     _lowercase							(  __lowerCamelCase      :       int      )	-> Optional[int]:





     '''simple docstring'''





     return sum(int(UpperCamelCase__      ) for c in str(abs(UpperCamelCase__      )      )      )







def     _lowercase							(  )	-> int:





     '''simple docstring'''





     from collections.abc import Callable
     from timeit import timeit

     def benchmark_a_function(__lowerCamelCase      :       Callable		,__lowerCamelCase      :       int      ) -> None:
          UpperCamelCase__				:	str										=  F'{func.__name__}({value})'
          UpperCamelCase__				:	Dict										=  timeit(F'__main__.{call}'		,setup='''import __main__'''      )
          print(F'{call:56} = {func(UpperCamelCase__      )} -- {timing:.4f} seconds'      )

     for value in (262144, 1125899906842624, 1267650600228229401496703205376):
          for func in (sum_of_digits, sum_of_digits_recursion, sum_of_digits_compact):
               benchmark_a_function(UpperCamelCase__		,UpperCamelCase__      )
          print()


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   benchmark()





'''simple docstring'''


from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch






@require_torch
@require_tf
class     A ( UpperCAmelCase ):





							def    snake_case__    (   self					:				str						)				->						Any:
								__UpperCAmelCase      					=      SMALL_MODEL_IDENTIFIER
								__UpperCAmelCase      					=      '''pt'''
								__UpperCAmelCase      					=      '''tf'''





							def    snake_case__    (   self					:				int  ,		__a					:				int						)				->						Union[str, Any]:
								__UpperCAmelCase      					=      AutoModel.from_pretrained(self.test_model						)
								model_pt.save_pretrained(__a						)





							def    snake_case__    (   self					:				Any  ,		__a					:				Optional[int]						)				->						Tuple:
								__UpperCAmelCase      					=      TFAutoModel.from_pretrained(self.test_model  ,		from_pt=__a						)
								model_tf.save_pretrained(__a						)





							def    snake_case__    (   self					:				Dict						)				->						Dict:
								__UpperCAmelCase      					=      '''mock_framework'''

								# Framework provided - return whatever the user provides
								__UpperCAmelCase      					=      FeaturesManager.determine_framework(self.test_model  ,		__a						)
								self.assertEqual(__a  ,		__a						)

								# Local checkpoint and framework provided - return provided framework
								# PyTorch checkpoint
								with TemporaryDirectory() as local_pt_ckpt:
									self._setup_pt_ckpt(__a						)
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(__a  ,		__a						)
									self.assertEqual(__a  ,		__a						)

								# TensorFlow checkpoint
								with TemporaryDirectory() as local_tf_ckpt:
									self._setup_tf_ckpt(__a						)
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(__a  ,		__a						)
									self.assertEqual(__a  ,		__a						)





							def    snake_case__    (   self					:				Dict						)				->						List[str]:
								# PyTorch checkpoint
								with TemporaryDirectory() as local_pt_ckpt:
									self._setup_pt_ckpt(__a						)
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(__a						)
									self.assertEqual(__a  ,		self.framework_pt						)

								# TensorFlow checkpoint
								with TemporaryDirectory() as local_tf_ckpt:
									self._setup_tf_ckpt(__a						)
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(__a						)
									self.assertEqual(__a  ,		self.framework_tf						)

								# Invalid local checkpoint
								with TemporaryDirectory() as local_invalid_ckpt:
									with self.assertRaises(__a						):
										__UpperCAmelCase      					=      FeaturesManager.determine_framework(__a						)






							def    snake_case__    (   self					:				str						)				->						Union[str, Any]:
								__UpperCAmelCase      					=      MagicMock(return_value=__a						)
								with patch('''transformers.onnx.features.is_tf_available'''  ,		__a						):
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(self.test_model						)
									self.assertEqual(__a  ,		self.framework_pt						)

								# PyTorch not in environment -> use TensorFlow
								__UpperCAmelCase      					=      MagicMock(return_value=__a						)
								with patch('''transformers.onnx.features.is_torch_available'''  ,		__a						):
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(self.test_model						)
									self.assertEqual(__a  ,		self.framework_tf						)

								# Both in environment -> use PyTorch
								__UpperCAmelCase      					=      MagicMock(return_value=__a						)
								__UpperCAmelCase      					=      MagicMock(return_value=__a						)
								with patch('''transformers.onnx.features.is_tf_available'''  ,		__a						), patch(
								    '''transformers.onnx.features.is_torch_available'''  ,		__a						):
									__UpperCAmelCase      					=      FeaturesManager.determine_framework(self.test_model						)
									self.assertEqual(__a  ,		self.framework_pt						)

								# Both not in environment -> raise error
								__UpperCAmelCase      					=      MagicMock(return_value=__a						)
								__UpperCAmelCase      					=      MagicMock(return_value=__a						)
								with patch('''transformers.onnx.features.is_tf_available'''  ,		__a						), patch(
								    '''transformers.onnx.features.is_torch_available'''  ,		__a						):
									with self.assertRaises(__a						):
										__UpperCAmelCase      					=      FeaturesManager.determine_framework(self.test_model						)
