






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
_a        =			sys.version_info >= (3, 10)


def 				snake_case__							(							UpperCAmelCase							:  Tuple=None    ,			UpperCAmelCase							:  int=None       ):
    return field(default_factory=lambda: default    ,			metadata=UpperCAmelCase       )







@dataclass
class 	_UpperCAmelCase  :




      """simple docstring"""



      A          =    42
      A          =    42
      A          =    42
      A          =    42







@dataclass
class 	_UpperCAmelCase  :




      """simple docstring"""



      A          =    42
      A          =    field(default='''toto'''				,							metadata={'''help''': '''help message'''}		)







@dataclass
class 	_UpperCAmelCase  :




      """simple docstring"""



      A          =    False
      A          =    True
      A          =    None







class 	_UpperCAmelCase  (  _A		):




      """simple docstring"""



      A          =    '''titi'''
      A          =    '''toto'''







class 	_UpperCAmelCase  (  _A		):




      """simple docstring"""



      A          =    '''titi'''
      A          =    '''toto'''
      A          =    42







@dataclass
class 	_UpperCAmelCase  :




      """simple docstring"""



      A          =    '''toto'''
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[Any]      							=				BasicEnum(self.foo		)







@dataclass
class 	_UpperCAmelCase  :




      """simple docstring"""



      A          =    '''toto'''
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :str      							=				MixedTypeEnum(self.foo		)







@dataclass
class 	_UpperCAmelCase  :




      """simple docstring"""



      A          =    None
      A          =    field(default=_A				,							metadata={'''help''': '''help message'''}		)
      A          =    None
      A          =    list_field(default=[]		)
      A          =    list_field(default=[]		)







@dataclass
class 	_UpperCAmelCase  :




      """simple docstring"""



      A          =    list_field(default=[]		)
      A          =    list_field(default=[1, 2, 3]		)
      A          =    list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']		)
      A          =    list_field(default=[0.1, 0.2, 0.3]		)







@dataclass
class 	_UpperCAmelCase  :




      """simple docstring"""



      A          =    field()
      A          =    field()
      A          =    field()
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Any      							=				BasicEnum(self.required_enum		)







@dataclass
class 	_UpperCAmelCase  :




      """simple docstring"""



      A          =    42
      A          =    field()
      A          =    None
      A          =    field(default='''toto'''				,							metadata={'''help''': '''help message'''}		)
      A          =    list_field(default=['''Hallo''', '''Bonjour''', '''Hello''']		)


if is_python_no_less_than_3_10:







 @dataclass
 class 	_UpperCAmelCase  :




       """simple docstring"""



       A          =    False
       A          =    True
       A          =    None







 @dataclass
 class 	_UpperCAmelCase  :




       """simple docstring"""



       A          =    None
       A          =    field(default=_A				,							metadata={'''help''': '''help message'''}		)
       A          =    None
       A          =    list_field(default=[]		)
       A          =    list_field(default=[]		)







class 	_UpperCAmelCase  (  unittest.TestCase		):




      """simple docstring"""



      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase		):



          '''simple docstring'''
          self.assertEqual(len(a._actions		)    ,	len(b._actions		)		)
          for x, y in zip(a._actions    ,	b._actions		):
              lowerCAmelCase__   :Optional[int]      							=				{k: v for k, v in vars(_lowerCAmelCase		).items() if k != "container"}
              lowerCAmelCase__   :int      							=				{k: v for k, v in vars(_lowerCAmelCase		).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"    ,	_lowerCAmelCase		) and yy.get("choices"    ,	_lowerCAmelCase		):
                  for expected_choice in yy["choices"] + xx["choices"]:
                      self.assertEqual(xx["type"](_lowerCAmelCase		)    ,	yy["type"](_lowerCAmelCase		)		)
                  del xx["type"], yy["type"]

              self.assertEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Tuple      							=				HfArgumentParser(_lowerCAmelCase		)

          lowerCAmelCase__   :Dict      							=				argparse.ArgumentParser()
          expected.add_argument("--foo"    ,	type=_lowerCAmelCase    ,	required=_lowerCAmelCase		)
          expected.add_argument("--bar"    ,	type=_lowerCAmelCase    ,	required=_lowerCAmelCase		)
          expected.add_argument("--baz"    ,	type=_lowerCAmelCase    ,	required=_lowerCAmelCase		)
          expected.add_argument("--flag"    ,	type=_lowerCAmelCase    ,	default=_lowerCAmelCase    ,	const=_lowerCAmelCase    ,	nargs="?"		)
          self.argparsersEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)

          lowerCAmelCase__   :Optional[Any]      							=				["--foo", "1", "--baz", "quux", "--bar", "0.5"]
          (lowerCAmelCase__)   :Any      							=				parser.parse_args_into_dataclasses(_lowerCAmelCase    ,	look_for_args_file=_lowerCAmelCase		)
          self.assertFalse(example.flag		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[Any]      							=				HfArgumentParser(_lowerCAmelCase		)

          lowerCAmelCase__   :Dict      							=				argparse.ArgumentParser()
          expected.add_argument("--foo"    ,	default=42    ,	type=_lowerCAmelCase		)
          expected.add_argument("--baz"    ,	default="toto"    ,	type=_lowerCAmelCase    ,	help="help message"		)
          self.argparsersEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[Any]      							=				argparse.ArgumentParser()
          expected.add_argument("--foo"    ,	type=_lowerCAmelCase    ,	default=_lowerCAmelCase    ,	const=_lowerCAmelCase    ,	nargs="?"		)
          expected.add_argument("--baz"    ,	type=_lowerCAmelCase    ,	default=_lowerCAmelCase    ,	const=_lowerCAmelCase    ,	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=_lowerCAmelCase    ,	dest="baz"		)
          expected.add_argument("--opt"    ,	type=_lowerCAmelCase    ,	default=_lowerCAmelCase		)

          lowerCAmelCase__   :Optional[Any]      							=				[WithDefaultBoolExample]
          if is_python_no_less_than_3_10:
              dataclass_types.append(_lowerCAmelCase		)

          for dataclass_type in dataclass_types:
              lowerCAmelCase__   :List[str]      							=				HfArgumentParser(_lowerCAmelCase		)
              self.argparsersEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)

              lowerCAmelCase__   :int      							=				parser.parse_args([]		)
              self.assertEqual(_lowerCAmelCase    ,	Namespace(foo=_lowerCAmelCase    ,	baz=_lowerCAmelCase    ,	opt=_lowerCAmelCase		)		)

              lowerCAmelCase__   :int      							=				parser.parse_args(["--foo", "--no_baz"]		)
              self.assertEqual(_lowerCAmelCase    ,	Namespace(foo=_lowerCAmelCase    ,	baz=_lowerCAmelCase    ,	opt=_lowerCAmelCase		)		)

              lowerCAmelCase__   :Dict      							=				parser.parse_args(["--foo", "--baz"]		)
              self.assertEqual(_lowerCAmelCase    ,	Namespace(foo=_lowerCAmelCase    ,	baz=_lowerCAmelCase    ,	opt=_lowerCAmelCase		)		)

              lowerCAmelCase__   :Optional[int]      							=				parser.parse_args(["--foo", "True", "--baz", "True", "--opt", "True"]		)
              self.assertEqual(_lowerCAmelCase    ,	Namespace(foo=_lowerCAmelCase    ,	baz=_lowerCAmelCase    ,	opt=_lowerCAmelCase		)		)

              lowerCAmelCase__   :Optional[int]      							=				parser.parse_args(["--foo", "False", "--baz", "False", "--opt", "False"]		)
              self.assertEqual(_lowerCAmelCase    ,	Namespace(foo=_lowerCAmelCase    ,	baz=_lowerCAmelCase    ,	opt=_lowerCAmelCase		)		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Any      							=				HfArgumentParser(_lowerCAmelCase		)

          lowerCAmelCase__   :Any      							=				argparse.ArgumentParser()
          expected.add_argument(
              "--foo"    ,	default="toto"    ,	choices=["titi", "toto", 42]    ,	type=make_choice_type_function(["titi", "toto", 42]		)    ,	)
          self.argparsersEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)

          lowerCAmelCase__   :Dict      							=				parser.parse_args([]		)
          self.assertEqual(args.foo    ,	"toto"		)
          lowerCAmelCase__   :Optional[int]      							=				parser.parse_args_into_dataclasses([]		)[0]
          self.assertEqual(enum_ex.foo    ,	MixedTypeEnum.toto		)

          lowerCAmelCase__   :Tuple      							=				parser.parse_args(["--foo", "titi"]		)
          self.assertEqual(args.foo    ,	"titi"		)
          lowerCAmelCase__   :Union[str, Any]      							=				parser.parse_args_into_dataclasses(["--foo", "titi"]		)[0]
          self.assertEqual(enum_ex.foo    ,	MixedTypeEnum.titi		)

          lowerCAmelCase__   :List[str]      							=				parser.parse_args(["--foo", "42"]		)
          self.assertEqual(args.foo    ,	42		)
          lowerCAmelCase__   :Optional[Any]      							=				parser.parse_args_into_dataclasses(["--foo", "42"]		)[0]
          self.assertEqual(enum_ex.foo    ,	MixedTypeEnum.fourtytwo		)
      def 			snake_case_      (   self		):



          '''simple docstring'''







          @dataclass
          class 	_UpperCAmelCase  :




                """simple docstring"""



                A          =    '''toto'''





          lowerCAmelCase__   :Union[str, Any]      							=				HfArgumentParser(_lowerCAmelCase		)

          lowerCAmelCase__   :Dict      							=				argparse.ArgumentParser()
          expected.add_argument(
              "--foo"    ,	default="toto"    ,	choices=("titi", "toto", 42)    ,	type=make_choice_type_function(["titi", "toto", 42]		)    ,	)
          self.argparsersEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)

          lowerCAmelCase__   :Any      							=				parser.parse_args([]		)
          self.assertEqual(args.foo    ,	"toto"		)

          lowerCAmelCase__   :int      							=				parser.parse_args(["--foo", "titi"]		)
          self.assertEqual(args.foo    ,	"titi"		)

          lowerCAmelCase__   :Tuple      							=				parser.parse_args(["--foo", "42"]		)
          self.assertEqual(args.foo    ,	42		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :List[Any]      							=				HfArgumentParser(_lowerCAmelCase		)

          lowerCAmelCase__   :Optional[Any]      							=				argparse.ArgumentParser()
          expected.add_argument("--foo_int"    ,	nargs="+"    ,	default=[]    ,	type=_lowerCAmelCase		)
          expected.add_argument("--bar_int"    ,	nargs="+"    ,	default=[1, 2, 3]    ,	type=_lowerCAmelCase		)
          expected.add_argument("--foo_str"    ,	nargs="+"    ,	default=["Hallo", "Bonjour", "Hello"]    ,	type=_lowerCAmelCase		)
          expected.add_argument("--foo_float"    ,	nargs="+"    ,	default=[0.1, 0.2, 0.3]    ,	type=_lowerCAmelCase		)

          self.argparsersEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)

          lowerCAmelCase__   :Any      							=				parser.parse_args([]		)
          self.assertEqual(
              _lowerCAmelCase    ,	Namespace(foo_int=[]    ,	bar_int=[1, 2, 3]    ,	foo_str=["Hallo", "Bonjour", "Hello"]    ,	foo_float=[0.1, 0.2, 0.3]		)    ,	)

          lowerCAmelCase__   :Dict      							=				parser.parse_args("--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7".split()		)
          self.assertEqual(_lowerCAmelCase    ,	Namespace(foo_int=[1]    ,	bar_int=[2, 3]    ,	foo_str=["a", "b", "c"]    ,	foo_float=[0.1, 0.7]		)		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Any      							=				argparse.ArgumentParser()
          expected.add_argument("--foo"    ,	default=_lowerCAmelCase    ,	type=_lowerCAmelCase		)
          expected.add_argument("--bar"    ,	default=_lowerCAmelCase    ,	type=_lowerCAmelCase    ,	help="help message"		)
          expected.add_argument("--baz"    ,	default=_lowerCAmelCase    ,	type=_lowerCAmelCase		)
          expected.add_argument("--ces"    ,	nargs="+"    ,	default=[]    ,	type=_lowerCAmelCase		)
          expected.add_argument("--des"    ,	nargs="+"    ,	default=[]    ,	type=_lowerCAmelCase		)

          lowerCAmelCase__   :Tuple      							=				[OptionalExample]
          if is_python_no_less_than_3_10:
              dataclass_types.append(_lowerCAmelCase		)

          for dataclass_type in dataclass_types:
              lowerCAmelCase__   :str      							=				HfArgumentParser(_lowerCAmelCase		)

              self.argparsersEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)

              lowerCAmelCase__   :List[Any]      							=				parser.parse_args([]		)
              self.assertEqual(_lowerCAmelCase    ,	Namespace(foo=_lowerCAmelCase    ,	bar=_lowerCAmelCase    ,	baz=_lowerCAmelCase    ,	ces=[]    ,	des=[]		)		)

              lowerCAmelCase__   :List[Any]      							=				parser.parse_args("--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3".split()		)
              self.assertEqual(_lowerCAmelCase    ,	Namespace(foo=12    ,	bar=3.14    ,	baz="42"    ,	ces=["a", "b", "c"]    ,	des=[1, 2, 3]		)		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[int]      							=				HfArgumentParser(_lowerCAmelCase		)

          lowerCAmelCase__   :Optional[int]      							=				argparse.ArgumentParser()
          expected.add_argument("--required_list"    ,	nargs="+"    ,	type=_lowerCAmelCase    ,	required=_lowerCAmelCase		)
          expected.add_argument("--required_str"    ,	type=_lowerCAmelCase    ,	required=_lowerCAmelCase		)
          expected.add_argument(
              "--required_enum"    ,	type=make_choice_type_function(["titi", "toto"]		)    ,	choices=["titi", "toto"]    ,	required=_lowerCAmelCase    ,	)
          self.argparsersEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Optional[Any]      							=				HfArgumentParser(_lowerCAmelCase		)

          lowerCAmelCase__   :List[Any]      							=				argparse.ArgumentParser()
          expected.add_argument("--foo"    ,	type=_lowerCAmelCase    ,	required=_lowerCAmelCase		)
          expected.add_argument(
              "--required_enum"    ,	type=make_choice_type_function(["titi", "toto"]		)    ,	choices=["titi", "toto"]    ,	required=_lowerCAmelCase    ,	)
          expected.add_argument("--opt"    ,	type=_lowerCAmelCase    ,	default=_lowerCAmelCase		)
          expected.add_argument("--baz"    ,	default="toto"    ,	type=_lowerCAmelCase    ,	help="help message"		)
          expected.add_argument("--foo_str"    ,	nargs="+"    ,	default=["Hallo", "Bonjour", "Hello"]    ,	type=_lowerCAmelCase		)
          self.argparsersEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :List[str]      							=				HfArgumentParser(_lowerCAmelCase		)

          lowerCAmelCase__   :List[str]      							=				{
              "foo": 12,
              "bar": 3.14,
              "baz": "42",
              "flag": True,
          }

          lowerCAmelCase__   :Tuple      							=				parser.parse_dict(_lowerCAmelCase		)[0]
          lowerCAmelCase__   :List[Any]      							=				BasicExample(**_lowerCAmelCase		)
          self.assertEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :str      							=				HfArgumentParser(_lowerCAmelCase		)

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

          self.assertRaises(_lowerCAmelCase    ,	parser.parse_dict    ,	_lowerCAmelCase    ,	allow_extra_keys=_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :str      							=				HfArgumentParser(_lowerCAmelCase		)

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

          lowerCAmelCase__   :Union[str, Any]      							=				BasicExample(**_lowerCAmelCase		)
          self.assertEqual(_lowerCAmelCase    ,	_lowerCAmelCase		)
      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :Dict      							=				HfArgumentParser(_lowerCAmelCase		)

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



      def 			snake_case_      (   self		):



          '''simple docstring'''
          lowerCAmelCase__   :List[str]      							=				HfArgumentParser(_lowerCAmelCase		)
          self.assertIsNotNone(_lowerCAmelCase		)











from __future__ import annotations

import numpy as np


def 				snake_case__							(							UpperCAmelCase							:  np.ndarray       ):
    lowerCAmelCase__							,lowerCAmelCase__   :List[str]      							=				np.shape(UpperCAmelCase       )
    if rows != columns:
        lowerCAmelCase__   :Tuple      							=				(
            "'table' has to be of square shaped array but got a "
            F'''{rows}x{columns} array:\n{table}'''
        )
        raise ValueError(UpperCAmelCase       )

    lowerCAmelCase__   :Optional[Any]      							=				np.zeros((rows, columns)       )
    lowerCAmelCase__   :Tuple      							=				np.zeros((rows, columns)       )
    for i in range(UpperCAmelCase       ):
        for j in range(UpperCAmelCase       ):
            lowerCAmelCase__   :Any      							=				sum(lower[i][k] * upper[k][j] for k in range(UpperCAmelCase       )       )
            if upper[j][j] == 0:
                raise ArithmeticError("No LU decomposition exists"       )
            lowerCAmelCase__   :Any      							=				(table[i][j] - total) / upper[j][j]
        lowerCAmelCase__   :Tuple      							=				1
        for j in range(UpperCAmelCase    ,			UpperCAmelCase       ):
            lowerCAmelCase__   :Optional[Any]      							=				sum(lower[i][k] * upper[k][j] for k in range(UpperCAmelCase       )       )
            lowerCAmelCase__   :Dict      							=				table[i][j] - total
    return lower, upper


if __name__ == "__main__":
 import doctest

 doctest.testmod()



