




import argparse

from ...utils.dataclasses import (
    ComputeEnvironment,
    DistributedType,
    DynamoBackend,
    PrecisionType,
    SageMakerDistributedType,
)
from ..menu import BulletMenu


UpperCamelCase__ :   List[Any]						=							[
    'EAGER',
    'AOT_EAGER',
    'INDUCTOR',
    'NVFUSER',
    'AOT_NVFUSER',
    'AOT_CUDAGRAPHS',
    'OFI',
    'FX2TRT',
    'ONNXRT',
    'IPEX',
]





def        __UpperCAmelCase						(							lowerCamelCase_ :     Optional[int]  ,							lowerCamelCase_ :     List[Any]=None  ,							lowerCamelCase_ :     int=None  ,							lowerCamelCase_ :     Tuple=None  )       ->  Optional[Any]:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Any					  =      True
			while ask_again:
						SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      input(lowerCamelCase_  )
						try:
									if default is not None and len(lowerCamelCase_  ) == 0:
												return default
									return convert_value(lowerCamelCase_  ) if convert_value is not None else result
						except Exception:
									if error_message is not None:
												print(lowerCamelCase_  )





def        __UpperCAmelCase						(							lowerCamelCase_ :     str  ,							lowerCamelCase_ :     List[Any]=[]  ,							lowerCamelCase_ :     int=None  ,							lowerCamelCase_ :     Optional[Any]=0  )       ->  Tuple:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : List[Any]					  =      BulletMenu(lowerCamelCase_  ,							lowerCamelCase_  )
			SCREAMING_SNAKE_CASE_   : List[str]					  =      menu.run(default_choice=lowerCamelCase_  )
			return convert_value(lowerCamelCase_  ) if convert_value is not None else result





def        __UpperCAmelCase						(							lowerCamelCase_ :     int  )       ->  List[Any]:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Optional[int]					  =      int(lowerCamelCase_  )
			return ComputeEnvironment(['LOCAL_MACHINE', 'AMAZON_SAGEMAKER'][value]  )





def        __UpperCAmelCase						(							lowerCamelCase_ :     Optional[Any]  )       ->  str:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Any					  =      int(lowerCamelCase_  )
			return DistributedType(['NO', 'MULTI_CPU', 'MULTI_XPU', 'MULTI_GPU', 'MULTI_NPU', 'TPU'][value]  )





def        __UpperCAmelCase						(							lowerCamelCase_ :     Optional[int]  )       ->  Dict:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : List[str]					  =      int(lowerCamelCase_  )
			return DynamoBackend(DYNAMO_BACKENDS[value]  ).value





def        __UpperCAmelCase						(							lowerCamelCase_ :     Optional[int]  )       ->  Optional[int]:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Tuple					  =      int(lowerCamelCase_  )
			return PrecisionType(['no', 'fp16', 'bf16', 'fp8'][value]  )





def        __UpperCAmelCase						(							lowerCamelCase_ :     List[Any]  )       ->  Optional[int]:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Optional[int]					  =      int(lowerCamelCase_  )
			return SageMakerDistributedType(['NO', 'DATA_PARALLEL', 'MODEL_PARALLEL'][value]  )





def        __UpperCAmelCase						(							lowerCamelCase_ :     Optional[int]  )       ->  Union[str, Any]:







			"""simple docstring"""





			return {"yes": True, "no": False}[value.lower()]







class 				lowerCAmelCase_       (					argparse.RawDescriptionHelpFormatter							):






				def 		snake_case	(			self      ,snake_case__      ,snake_case__      ,snake_case__      ,snake_case__ ):
							SCREAMING_SNAKE_CASE_   : Tuple					  =      super()._format_usage(snake_case__      ,snake_case__      ,snake_case__      ,snake_case__ )
							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      usage.replace('<command> [<args>] '      ,'' )
							return usage







'''simple docstring'''

from __future__ import annotations

from collections import deque
class     __lowerCAmelCase		:





      '''simple docstring'''






      def __init__(self       :       str  ,		UpperCamelCase       :       list[str]					):

             '''simple docstring'''







             lowercase__      =					[]
             self.adlist.append(
                 {'''value''': '''''', '''next_states''': [], '''fail_state''': 0, '''output''': []}					)

             for keyword in keywords:
                    self.add_keyword(UpperCamelCase					)
             self.set_fail_transitions()



      def  UpperCamelCase__						(self       :       Optional[int]  ,		UpperCamelCase       :       int  ,		UpperCamelCase       :       str					):

             '''simple docstring'''







             for state in self.adlist[current_state]["next_states"]:
                    if char == self.adlist[state]["value"]:
                           return state
             return None



      def  UpperCamelCase__						(self       :       Optional[Any]  ,		UpperCamelCase       :       str					):

             '''simple docstring'''







             lowercase__      =					0
             for character in keyword:
                    lowercase__      =					self.find_next_state(UpperCamelCase  ,		UpperCamelCase					)
                    if next_state is None:
                           self.adlist.append(
                               {
                                   '''value''': character,
                                   '''next_states''': [],
                                   '''fail_state''': 0,
                                   '''output''': [],
                               }					)
                           self.adlist[current_state]["next_states"].append(len(self.adlist					) - 1					)
                           lowercase__      =					len(self.adlist					) - 1
                    else:
                           lowercase__      =					next_state
             self.adlist[current_state]["output"].append(UpperCamelCase					)



      def  UpperCamelCase__						(self       :       List[str]					):

             '''simple docstring'''







             lowercase__      =					deque()
             for node in self.adlist[0]["next_states"]:
                    q.append(UpperCamelCase					)
                    lowercase__      =					0
             while q:
                    lowercase__      =					q.popleft()
                    for child in self.adlist[r]["next_states"]:
                           q.append(UpperCamelCase					)
                           lowercase__      =					self.adlist[r]['''fail_state''']
                           while (
                               self.find_next_state(UpperCamelCase  ,		self.adlist[child]['''value''']					) is None
                               and state != 0
                           ):
                                  lowercase__      =					self.adlist[state]['''fail_state''']
                           lowercase__      =					self.find_next_state(
                               UpperCamelCase  ,		self.adlist[child]['''value''']					)
                           if self.adlist[child]["fail_state"] is None:
                                  lowercase__      =					0
                           lowercase__      =					(
                               self.adlist[child]['''output''']
                               + self.adlist[self.adlist[child]['''fail_state''']]['''output''']
                           )






      def  UpperCamelCase__						(self       :       Optional[int]  ,		UpperCamelCase       :       str					):

             '''simple docstring'''







             lowercase__      =					{}  # returns a dict with keywords and list of its occurrences
             lowercase__      =					0
             for i in range(len(UpperCamelCase					)					):
                    while (
                        self.find_next_state(UpperCamelCase  ,		string[i]					) is None
                        and current_state != 0
                    ):
                           lowercase__      =					self.adlist[current_state]['''fail_state''']
                    lowercase__      =					self.find_next_state(UpperCamelCase  ,		string[i]					)
                    if next_state is None:
                           lowercase__      =					0
                    else:
                           lowercase__      =					next_state
                           for key in self.adlist[current_state]["output"]:
                                  if key not in result:
                                         lowercase__      =					[]
                                  result[key].append(i - len(UpperCamelCase					) + 1					)
             return result


if __name__ == "__main__":
 import doctest

 doctest.testmod()




