


"""simple docstring"""


import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
_snake_case          =							sys.version_info >= (3, 10)



def   snake_case      (				_a:     Dict=None		,   _a:     Any=None							)->		Optional[int]:
      '''simple docstring'''


      return field(default_factory=lambda: default		,   metadata=SCREAMING_SNAKE_CASE__							)



@dataclass
class   _a      :
    a_    :				int
    a_    :				float
    a_    :				str
    a_    :				bool





@dataclass
class   _a      :
    a_    :				int             =    42
    a_    :				str             =    field(default='toto'		,		metadata={'help': 'help message'} )





@dataclass
class   _a      :
    a_    :				bool             =    False
    a_    :				bool             =    True
    a_    :				Optional[bool]             =    None





class   _a      (      _UpperCAmelCase ):
    a_    :				int             =    """titi"""
    a_    :				str             =    """toto"""





class   _a      (      _UpperCAmelCase ):
    a_    :				int             =    """titi"""
    a_    :				Dict             =    """toto"""
    a_    :				Tuple             =    42





@dataclass
class   _a      :
    a_    :				BasicEnum             =    "toto"
    def      _UpperCamelCase       ( self							:					int				):
          lowerCamelCase__           =		BasicEnum(self.foo				)





@dataclass
class   _a      :
    a_    :				MixedTypeEnum             =    "toto"
    def      _UpperCamelCase       ( self							:					int				):
          lowerCamelCase__           =		MixedTypeEnum(self.foo				)





@dataclass
class   _a      :
    a_    :				Optional[int]             =    None
    a_    :				Optional[float]             =    field(default=_UpperCAmelCase		,		metadata={'help': 'help message'} )
    a_    :				Optional[str]             =    None
    a_    :				Optional[List[str]]             =    list_field(default=[] )
    a_    :				Optional[List[int]]             =    list_field(default=[] )





@dataclass
class   _a      :
    a_    :				List[int]             =    list_field(default=[] )
    a_    :				List[int]             =    list_field(default=[1, 2, 3] )
    a_    :				List[str]             =    list_field(default=['Hallo', 'Bonjour', 'Hello'] )
    a_    :				List[float]             =    list_field(default=[0.1, 0.2, 0.3] )





@dataclass
class   _a      :
    a_    :				List[int]             =    field()
    a_    :				str             =    field()
    a_    :				BasicEnum             =    field()
    def      _UpperCamelCase       ( self							:					Optional[Any]				):
          lowerCamelCase__           =		BasicEnum(self.required_enum				)





@dataclass
class   _a      :
    a_    :				int
    a_    :				"BasicEnum"             =    field()
    a_    :				"Optional[bool]"             =    None
    a_    :				"str"             =    field(default='toto'		,		metadata={'help': 'help message'} )
    a_    :				"List[str]"             =    list_field(default=['Hallo', 'Bonjour', 'Hello'] )


if is_python_no_less_than_3_10:



   @dataclass
   class   _a      :
       a_    :				bool             =    False
       a_    :				bool             =    True
       a_    :				bool | None             =    None





   @dataclass
   class   _a      :
       a_    :				int | None             =    None
       a_    :				float | None             =    field(default=_UpperCAmelCase		,		metadata={'help': 'help message'} )
       a_    :				str | None             =    None
       a_    :				list[str] | None             =    list_field(default=[] )
       a_    :				list[int] | None             =    list_field(default=[] )






class   _a      (      unittest.TestCase ):
    def      _UpperCamelCase       ( self							:					List[str]							,					SCREAMING_SNAKE_CASE__							:					Optional[int]							,					SCREAMING_SNAKE_CASE__							:					int				):
          self.assertEqual(len(a._actions				)							,					len(b._actions				)				)
          for x, y in zip(a._actions							,					b._actions				):
                lowerCamelCase__           =		{k: v for k, v in vars(lowercase__				).items() if k != """container"""}
                lowerCamelCase__           =		{k: v for k, v in vars(lowercase__				).items() if k != """container"""}

                # Choices with mixed type have custom function as "type"
                # So we need to compare results directly for equality
                if xx.get('choices'							,					lowercase__				) and yy.get('choices'							,					lowercase__				):
                      for expected_choice in yy["choices"] + xx["choices"]:
                            self.assertEqual(xx['type'](lowercase__				)							,					yy['type'](lowercase__				)				)
                      del xx["type"], yy["type"]

                self.assertEqual(lowercase__							,					lowercase__				)
    def      _UpperCamelCase       ( self							:					int				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		argparse.ArgumentParser()
          expected.add_argument('--foo'							,					type=lowercase__							,					required=lowercase__				)
          expected.add_argument('--bar'							,					type=lowercase__							,					required=lowercase__				)
          expected.add_argument('--baz'							,					type=lowercase__							,					required=lowercase__				)
          expected.add_argument('--flag'							,					type=lowercase__							,					default=lowercase__							,					const=lowercase__							,					nargs='?'				)
          self.argparsersEqual(lowercase__							,					lowercase__				)

          lowerCamelCase__           =		["""--foo""", """1""", """--baz""", """quux""", """--bar""", """0.5"""]
          (lowerCamelCase__			)           =		parser.parse_args_into_dataclasses(lowercase__							,					look_for_args_file=lowercase__				)
          self.assertFalse(example.flag				)
    def      _UpperCamelCase       ( self							:					Tuple				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		argparse.ArgumentParser()
          expected.add_argument('--foo'							,					default=42							,					type=lowercase__				)
          expected.add_argument('--baz'							,					default='toto'							,					type=lowercase__							,					help='help message'				)
          self.argparsersEqual(lowercase__							,					lowercase__				)
    def      _UpperCamelCase       ( self							:					Any				):
          lowerCamelCase__           =		argparse.ArgumentParser()
          expected.add_argument('--foo'							,					type=lowercase__							,					default=lowercase__							,					const=lowercase__							,					nargs='?'				)
          expected.add_argument('--baz'							,					type=lowercase__							,					default=lowercase__							,					const=lowercase__							,					nargs='?'				)
          # A boolean no_* argument always has to come after its "default: True" regular counter-part
          # and its default must be set to False
          expected.add_argument('--no_baz'							,					action='store_false'							,					default=lowercase__							,					dest='baz'				)
          expected.add_argument('--opt'							,					type=lowercase__							,					default=lowercase__				)

          lowerCamelCase__           =		[WithDefaultBoolExample]
          if is_python_no_less_than_3_10:
                dataclass_types.append(lowercase__				)

          for dataclass_type in dataclass_types:
                lowerCamelCase__           =		HfArgumentParser(lowercase__				)
                self.argparsersEqual(lowercase__							,					lowercase__				)

                lowerCamelCase__           =		parser.parse_args([]				)
                self.assertEqual(lowercase__							,					Namespace(foo=lowercase__							,					baz=lowercase__							,					opt=lowercase__				)				)

                lowerCamelCase__           =		parser.parse_args(['--foo', '--no_baz']				)
                self.assertEqual(lowercase__							,					Namespace(foo=lowercase__							,					baz=lowercase__							,					opt=lowercase__				)				)

                lowerCamelCase__           =		parser.parse_args(['--foo', '--baz']				)
                self.assertEqual(lowercase__							,					Namespace(foo=lowercase__							,					baz=lowercase__							,					opt=lowercase__				)				)

                lowerCamelCase__           =		parser.parse_args(['--foo', 'True', '--baz', 'True', '--opt', 'True']				)
                self.assertEqual(lowercase__							,					Namespace(foo=lowercase__							,					baz=lowercase__							,					opt=lowercase__				)				)

                lowerCamelCase__           =		parser.parse_args(['--foo', 'False', '--baz', 'False', '--opt', 'False']				)
                self.assertEqual(lowercase__							,					Namespace(foo=lowercase__							,					baz=lowercase__							,					opt=lowercase__				)				)
    def      _UpperCamelCase       ( self							:					int				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		argparse.ArgumentParser()
          expected.add_argument(
              '--foo'							,					default='toto'							,					choices=['titi', 'toto', 42]							,					type=make_choice_type_function(['titi', 'toto', 42]				)							,					)
          self.argparsersEqual(lowercase__							,					lowercase__				)

          lowerCamelCase__           =		parser.parse_args([]				)
          self.assertEqual(args.foo							,					'toto'				)
          lowerCamelCase__           =		parser.parse_args_into_dataclasses([]				)[0]
          self.assertEqual(enum_ex.foo							,					MixedTypeEnum.toto				)

          lowerCamelCase__           =		parser.parse_args(['--foo', 'titi']				)
          self.assertEqual(args.foo							,					'titi'				)
          lowerCamelCase__           =		parser.parse_args_into_dataclasses(['--foo', 'titi']				)[0]
          self.assertEqual(enum_ex.foo							,					MixedTypeEnum.titi				)

          lowerCamelCase__           =		parser.parse_args(['--foo', '42']				)
          self.assertEqual(args.foo							,					42				)
          lowerCamelCase__           =		parser.parse_args_into_dataclasses(['--foo', '42']				)[0]
          self.assertEqual(enum_ex.foo							,					MixedTypeEnum.fourtytwo				)
    def      _UpperCamelCase       ( self							:					Any				):



          @dataclass
          class   _a      :
              a_    :				Literal["titi", "toto", 42]             =    "toto"





          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		argparse.ArgumentParser()
          expected.add_argument(
              '--foo'							,					default='toto'							,					choices=('titi', 'toto', 42)							,					type=make_choice_type_function(['titi', 'toto', 42]				)							,					)
          self.argparsersEqual(lowercase__							,					lowercase__				)

          lowerCamelCase__           =		parser.parse_args([]				)
          self.assertEqual(args.foo							,					'toto'				)

          lowerCamelCase__           =		parser.parse_args(['--foo', 'titi']				)
          self.assertEqual(args.foo							,					'titi'				)

          lowerCamelCase__           =		parser.parse_args(['--foo', '42']				)
          self.assertEqual(args.foo							,					42				)
    def      _UpperCamelCase       ( self							:					Optional[int]				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		argparse.ArgumentParser()
          expected.add_argument('--foo_int'							,					nargs='+'							,					default=[]							,					type=lowercase__				)
          expected.add_argument('--bar_int'							,					nargs='+'							,					default=[1, 2, 3]							,					type=lowercase__				)
          expected.add_argument('--foo_str'							,					nargs='+'							,					default=['Hallo', 'Bonjour', 'Hello']							,					type=lowercase__				)
          expected.add_argument('--foo_float'							,					nargs='+'							,					default=[0.1, 0.2, 0.3]							,					type=lowercase__				)

          self.argparsersEqual(lowercase__							,					lowercase__				)

          lowerCamelCase__           =		parser.parse_args([]				)
          self.assertEqual(
              lowercase__							,					Namespace(foo_int=[]							,					bar_int=[1, 2, 3]							,					foo_str=['Hallo', 'Bonjour', 'Hello']							,					foo_float=[0.1, 0.2, 0.3]				)							,					)

          lowerCamelCase__           =		parser.parse_args('--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'.split()				)
          self.assertEqual(lowercase__							,					Namespace(foo_int=[1]							,					bar_int=[2, 3]							,					foo_str=['a', 'b', 'c']							,					foo_float=[0.1, 0.7]				)				)
    def      _UpperCamelCase       ( self							:					Optional[int]				):
          lowerCamelCase__           =		argparse.ArgumentParser()
          expected.add_argument('--foo'							,					default=lowercase__							,					type=lowercase__				)
          expected.add_argument('--bar'							,					default=lowercase__							,					type=lowercase__							,					help='help message'				)
          expected.add_argument('--baz'							,					default=lowercase__							,					type=lowercase__				)
          expected.add_argument('--ces'							,					nargs='+'							,					default=[]							,					type=lowercase__				)
          expected.add_argument('--des'							,					nargs='+'							,					default=[]							,					type=lowercase__				)

          lowerCamelCase__           =		[OptionalExample]
          if is_python_no_less_than_3_10:
                dataclass_types.append(lowercase__				)

          for dataclass_type in dataclass_types:
                lowerCamelCase__           =		HfArgumentParser(lowercase__				)

                self.argparsersEqual(lowercase__							,					lowercase__				)

                lowerCamelCase__           =		parser.parse_args([]				)
                self.assertEqual(lowercase__							,					Namespace(foo=lowercase__							,					bar=lowercase__							,					baz=lowercase__							,					ces=[]							,					des=[]				)				)

                lowerCamelCase__           =		parser.parse_args('--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'.split()				)
                self.assertEqual(lowercase__							,					Namespace(foo=12							,					bar=3.14							,					baz='42'							,					ces=['a', 'b', 'c']							,					des=[1, 2, 3]				)				)
    def      _UpperCamelCase       ( self							:					List[str]				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		argparse.ArgumentParser()
          expected.add_argument('--required_list'							,					nargs='+'							,					type=lowercase__							,					required=lowercase__				)
          expected.add_argument('--required_str'							,					type=lowercase__							,					required=lowercase__				)
          expected.add_argument(
              '--required_enum'							,					type=make_choice_type_function(['titi', 'toto']				)							,					choices=['titi', 'toto']							,					required=lowercase__							,					)
          self.argparsersEqual(lowercase__							,					lowercase__				)
    def      _UpperCamelCase       ( self							:					List[str]				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		argparse.ArgumentParser()
          expected.add_argument('--foo'							,					type=lowercase__							,					required=lowercase__				)
          expected.add_argument(
              '--required_enum'							,					type=make_choice_type_function(['titi', 'toto']				)							,					choices=['titi', 'toto']							,					required=lowercase__							,					)
          expected.add_argument('--opt'							,					type=lowercase__							,					default=lowercase__				)
          expected.add_argument('--baz'							,					default='toto'							,					type=lowercase__							,					help='help message'				)
          expected.add_argument('--foo_str'							,					nargs='+'							,					default=['Hallo', 'Bonjour', 'Hello']							,					type=lowercase__				)
          self.argparsersEqual(lowercase__							,					lowercase__				)
    def      _UpperCamelCase       ( self							:					Optional[Any]				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		{
              """foo""": 12,
              """bar""": 3.14,
              """baz""": """42""",
              """flag""": True,
          }

          lowerCamelCase__           =		parser.parse_dict(lowercase__				)[0]
          lowerCamelCase__           =		BasicExample(**lowercase__				)
          self.assertEqual(lowercase__							,					lowercase__				)
    def      _UpperCamelCase       ( self							:					List[Any]				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		{
              """foo""": 12,
              """bar""": 3.14,
              """baz""": """42""",
              """flag""": True,
              """extra""": 42,
          }

          self.assertRaises(lowercase__							,					parser.parse_dict							,					lowercase__							,					allow_extra_keys=lowercase__				)
    def      _UpperCamelCase       ( self							:					str				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		{
              """foo""": 12,
              """bar""": 3.14,
              """baz""": """42""",
              """flag""": True,
          }
          with tempfile.TemporaryDirectory() as tmp_dir:
                lowerCamelCase__           =		os.path.join(lowercase__							,					'temp_json'				)
                os.mkdir(lowercase__				)
                with open(temp_local_path + '.json'							,					'w+'				) as f:
                      json.dump(lowercase__							,					lowercase__				)
                lowerCamelCase__           =		parser.parse_yaml_file(Path(temp_local_path + '.json'				)				)[0]

          lowerCamelCase__           =		BasicExample(**lowercase__				)
          self.assertEqual(lowercase__							,					lowercase__				)
    def      _UpperCamelCase       ( self							:					Optional[Any]				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)

          lowerCamelCase__           =		{
              """foo""": 12,
              """bar""": 3.14,
              """baz""": """42""",
              """flag""": True,
          }
          with tempfile.TemporaryDirectory() as tmp_dir:
                lowerCamelCase__           =		os.path.join(lowercase__							,					'temp_yaml'				)
                os.mkdir(lowercase__				)
                with open(temp_local_path + '.yaml'							,					'w+'				) as f:
                      yaml.dump(lowercase__							,					lowercase__				)
                lowerCamelCase__           =		parser.parse_yaml_file(Path(temp_local_path + '.yaml'				)				)[0]
          lowerCamelCase__           =		BasicExample(**lowercase__				)
          self.assertEqual(lowercase__							,					lowercase__				)


    def      _UpperCamelCase       ( self							:					List[Any]				):
          lowerCamelCase__           =		HfArgumentParser(lowercase__				)
          self.assertIsNotNone(lowercase__				)







"""simple docstring"""


from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
   if not (is_transformers_available() and is_torch_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from ...utils.dummy_torch_and_transformers_objects import ShapEPipeline
else:
   from .camera import create_pan_cameras
   from .pipeline_shap_e import ShapEPipeline
   from .pipeline_shap_e_img2img import ShapEImgaImgPipeline
   from .renderer import (
       BoundingBoxVolume,
       ImportanceRaySampler,
       MLPNeRFModelOutput,
       MLPNeRSTFModel,
       ShapEParamsProjModel,
       ShapERenderer,
       StratifiedRaySampler,
       VoidNeRFModel,
   )



