





"""simple docstring"""





# Copyright 2021 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse

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


__A											=		[
    """EAGER""",
    """AOT_EAGER""",
    """INDUCTOR""",
    """NVFUSER""",
    """AOT_NVFUSER""",
    """AOT_CUDAGRAPHS""",
    """OFI""",
    """FX2TRT""",
    """ONNXRT""",
    """IPEX""",
]
def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE=None     ,   _SCREAMING_SNAKE_CASE=None     ,   _SCREAMING_SNAKE_CASE=None			)					->int:





  """simple docstring"""


  lowerCAmelCase__			:int											=							True
  while ask_again:
    lowerCAmelCase__			:Optional[Any]											=							input(_SCREAMING_SNAKE_CASE			)
    try:
      if default is not None and len(_SCREAMING_SNAKE_CASE			) == 0:
        return default
      return convert_value(_SCREAMING_SNAKE_CASE			) if convert_value is not None else result
    except Exception:
      if error_message is not None:
        print(_SCREAMING_SNAKE_CASE			)
def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE=[]     ,   _SCREAMING_SNAKE_CASE=None     ,   _SCREAMING_SNAKE_CASE=0			)					->Any:





  """simple docstring"""


  lowerCAmelCase__			:List[str]											=							BulletMenu(_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE			)
  lowerCAmelCase__			:Optional[Any]											=							menu.run(default_choice=_SCREAMING_SNAKE_CASE			)
  return convert_value(_SCREAMING_SNAKE_CASE			) if convert_value is not None else result
def  __A   (_SCREAMING_SNAKE_CASE			)					->Dict:





  """simple docstring"""


  lowerCAmelCase__			:int											=							int(_SCREAMING_SNAKE_CASE			)
  return ComputeEnvironment(['LOCAL_MACHINE', 'AMAZON_SAGEMAKER'][value]			)
def  __A   (_SCREAMING_SNAKE_CASE			)					->Tuple:





  """simple docstring"""


  lowerCAmelCase__			:List[str]											=							int(_SCREAMING_SNAKE_CASE			)
  return DistributedType(['NO', 'MULTI_CPU', 'MULTI_XPU', 'MULTI_GPU', 'MULTI_NPU', 'TPU'][value]			)
def  __A   (_SCREAMING_SNAKE_CASE			)					->List[Any]:





  """simple docstring"""


  lowerCAmelCase__			:List[Any]											=							int(_SCREAMING_SNAKE_CASE			)
  return DynamoBackend(DYNAMO_BACKENDS[value]			).value
def  __A   (_SCREAMING_SNAKE_CASE			)					->Optional[int]:





  """simple docstring"""


  lowerCAmelCase__			:Dict											=							int(_SCREAMING_SNAKE_CASE			)
  return PrecisionType(['no', 'fp16', 'bf16', 'fp8'][value]			)
def  __A   (_SCREAMING_SNAKE_CASE			)					->List[Any]:





  """simple docstring"""


  lowerCAmelCase__			:Union[str, Any]											=							int(_SCREAMING_SNAKE_CASE			)
  return SageMakerDistributedType(['NO', 'DATA_PARALLEL', 'MODEL_PARALLEL'][value]			)
def  __A   (_SCREAMING_SNAKE_CASE			)					->Dict:





  """simple docstring"""


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






class 					_lowerCAmelCase   (     argparse.RawDescriptionHelpFormatter       ):
       """simple docstring"""




       def      snake_case						(    self    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase      ):



         '''simple docstring'''

         lowerCAmelCase__			:Tuple											=							super()._format_usage(__UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase    , __UpperCAmelCase      )
         lowerCAmelCase__			:Dict											=							usage.replace('<command> [<args>] '    , ''      )
         return usage







"""simple docstring"""





def  __A   (_SCREAMING_SNAKE_CASE     ,   _SCREAMING_SNAKE_CASE			)					->float:





  """simple docstring"""


  if discount_rate < 0:
    raise ValueError('Discount rate cannot be negative'			)
  if not cash_flows:
    raise ValueError('Cash flows list cannot be empty'			)
  lowerCAmelCase__			:Union[str, Any]											=							sum(
      cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_SCREAMING_SNAKE_CASE			)			)
  return round(_SCREAMING_SNAKE_CASE     ,   ndigits=2			)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
