






'''simple docstring'''






import json
import os
import pickle
import subprocess
from hashlib import mda
from pathlib import Path
from tempfile import gettempdir
from textwrap import dedent
from types import CodeType, FunctionType
from unittest import TestCase
from unittest.mock import patch

import pytest
from multiprocess import Pool
from packaging import version

import datasets
from datasets.fingerprint import Hasher, fingerprint_transform
from datasets.table import InMemoryTable

from .utils import (
    require_regex,
    require_spacy,
    require_spacy_model,
    require_tiktoken,
    require_torch,
    require_transformers,
)




class a_     :







   def __init__(self       , __a)      ->   Union[str, Any]:
      """simple docstring"""






      __snake_case					:   Optional[int]  				=			foo







   def __call__(self)      ->   Optional[Any]:
      """simple docstring"""






      return self.foo




class a_     (     datasets.Dataset				):







   @fingerprint_transform(inplace=__a)
   def      SCREAMING_SNAKE_CASE__       (self       , __a       , *__a       , **__a)      ->   int:
      """simple docstring"""






      return DatasetChild(self.data       , fingerprint=__a)







   @fingerprint_transform(inplace=__a)
   def      SCREAMING_SNAKE_CASE__       (self       , __a       , *__a       , **__a)      ->   Dict:
      """simple docstring"""






      return DatasetChild(self.data       , fingerprint=__a)




class a_     :







   def __init__(self       , __a)      ->   Dict:
      """simple docstring"""






      __snake_case					:   int  				=			callable







   def __call__(self       , *__a       , **__a)      ->   List[str]:
      """simple docstring"""






      if self.callable is not None:
         return self.callable(*__a       , **__a)







   def __getstate__(self)      ->   Optional[int]:
      """simple docstring"""






      raise pickle.PicklingError()




class a_     (     UpperCamelCase_				):







   @require_transformers
   @pytest.mark.integration
   def      SCREAMING_SNAKE_CASE__       (self)      ->   Any:
      """simple docstring"""






      from transformers import AutoTokenizer

      def encode(__a):
         return tokenizer(__a)

      # TODO: add hash consistency tests across sessions
      __snake_case					:   Optional[int]  				=			AutoTokenizer.from_pretrained('bert-base-uncased')
      __snake_case					:   str  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   Any  				=			mda(datasets.utils.py_utils.dumps(lambda __a: tokenizer(__a))).hexdigest()
      __snake_case					:   Any  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   List[Any]  				=			AutoTokenizer.from_pretrained('bert-base-cased')
      __snake_case					:   List[Any]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   Dict  				=			mda(datasets.utils.py_utils.dumps(lambda __a: tokenizer(__a))).hexdigest()
      __snake_case					:   Dict  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   str  				=			AutoTokenizer.from_pretrained('bert-base-uncased')
      __snake_case					:   int  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   Union[str, Any]  				=			mda(datasets.utils.py_utils.dumps(lambda __a: tokenizer(__a))).hexdigest()
      __snake_case					:   Dict  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)







   @require_transformers
   @pytest.mark.integration
   def      SCREAMING_SNAKE_CASE__       (self)      ->   List[str]:
      """simple docstring"""






      from transformers import AutoTokenizer

      __snake_case					:   Tuple  				=			AutoTokenizer.from_pretrained('gpt2')
      __snake_case					:   Dict  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      tokenizer('Hello world !')  # call once to change the tokenizer's cache
      __snake_case					:   Union[str, Any]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      self.assertEqual(__a       , __a)







   @require_regex
   def      SCREAMING_SNAKE_CASE__       (self)      ->   Tuple:
      """simple docstring"""






      import regex

      __snake_case					:   Union[str, Any]  				=			regex.Regex('foo')
      __snake_case					:   int  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   Optional[Any]  				=			regex.Regex('bar')
      __snake_case					:   Tuple  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   int  				=			regex.Regex('foo')
      __snake_case					:   Any  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)




class a_     (     UpperCamelCase_				):







   def      SCREAMING_SNAKE_CASE__       (self)      ->   Union[str, Any]:
      """simple docstring"""






      def func():
         return foo

      __snake_case					:   int  				=			[0]
      __snake_case					:   Any  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   Dict  				=			[1]
      __snake_case					:   Dict  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   Tuple  				=			[0]
      __snake_case					:   Union[str, Any]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)







   def      SCREAMING_SNAKE_CASE__       (self)      ->   str:
      """simple docstring"""






      def func():
         pass

      __snake_case					:   Tuple  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()

      def func():
         pass

      __snake_case					:   Tuple  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      self.assertEqual(__a       , __a)







   def      SCREAMING_SNAKE_CASE__       (self)      ->   int:
      """simple docstring"""






      __snake_case					:   Union[str, Any]  				=			mda(datasets.utils.py_utils.dumps(Foo([0]))).hexdigest()
      __snake_case					:   Optional[Any]  				=			mda(datasets.utils.py_utils.dumps(Foo([1]))).hexdigest()
      __snake_case					:   Optional[Any]  				=			mda(datasets.utils.py_utils.dumps(Foo([0]))).hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)







   def      SCREAMING_SNAKE_CASE__       (self)      ->   int:
      """simple docstring"""






      __snake_case					:   Any  				=			mda(datasets.utils.py_utils.dumps(Foo([0]).__call__)).hexdigest()
      __snake_case					:   Union[str, Any]  				=			mda(datasets.utils.py_utils.dumps(Foo([1]).__call__)).hexdigest()
      __snake_case					:   Any  				=			mda(datasets.utils.py_utils.dumps(Foo([0]).__call__)).hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)







   def      SCREAMING_SNAKE_CASE__       (self)      ->   int:
      """simple docstring"""






      __snake_case					:   int  				=			(
          'co_argcount',
          'co_kwonlyargcount',
          'co_nlocals',
          'co_stacksize',
          'co_flags',
          'co_code',
          'co_consts',
          'co_names',
          'co_varnames',
          'co_filename',
          'co_name',
          'co_firstlineno',
          'co_lnotab',
          'co_freevars',
          'co_cellvars',
      )

      def _create_code_pyaa(*__a):
         if hasattr(args[-3]       , 'encode'):
            __snake_case					:   Union[str, Any]  				=			list(__a)
            __snake_case					:   Dict  				=			args[-3].encode()  # co_lnotab
            __snake_case					:   str  				=			args[-1_0].encode()  # co_code
         if hasattr(__a       , 'co_posonlyargcount'):
            if len(__a) == 1_6:
               return CodeType(*__a)
            elif len(__a) == 1_5:
               return CodeType(args[0]       , 0       , *args[1:])
            return CodeType(args[0]       , 0       , 0       , *args[1:])
         elif hasattr(__a       , 'co_kwonlyargcount'):
            if len(__a) == 1_6:
               return CodeType(args[0]       , *args[2:])
            elif len(__a) == 1_5:
               return CodeType(*__a)
            return CodeType(args[0]       , 0       , *args[1:])
         if len(__a) == 1_6:
            return CodeType(args[0]       , *args[3:])
         elif len(__a) == 1_5:
            return CodeType(args[0]       , *args[2:])
         return CodeType(*__a)

      def create_ipython_func(__a       , __a):
         def func():
            return returned_obj

         __snake_case					:   Any  				=			func.__code__
         # Use _create_code from dill in order to make it work for different python versions
         if datasets.config.PY_VERSION < version.parse('3.8'):
            __snake_case					:   Dict  				=			_create_code_pyaa(
                *[getattr(__a       , __a) if k != 'co_filename' else co_filename for k in code_args_pyaa])
         else:
            __snake_case					:   str  				=			code.replace(co_filename=__a)
         return FunctionType(__a       , func.__globals__       , func.__name__       , func.__defaults__       , func.__closure__)

      __snake_case				,__snake_case					:   List[str]  				=			'<ipython-input-2-e0383a102aae>', [0]
      __snake_case					:   Optional[int]  				=			mda(datasets.utils.py_utils.dumps(create_ipython_func(__a       , __a))).hexdigest()
      __snake_case				,__snake_case					:   str  				=			'<ipython-input-2-e0383a102aae>', [1]
      __snake_case					:   Optional[int]  				=			mda(datasets.utils.py_utils.dumps(create_ipython_func(__a       , __a))).hexdigest()
      __snake_case				,__snake_case					:   List[str]  				=			'<ipython-input-5-713f6613acf3>', [0]
      __snake_case					:   Dict  				=			mda(datasets.utils.py_utils.dumps(create_ipython_func(__a       , __a))).hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)

      __snake_case				,__snake_case					:   str  				=			os.path.join(gettempdir()       , 'ipykernel_12345'       , '321456789.py'), [0]
      __snake_case					:   List[Any]  				=			mda(datasets.utils.py_utils.dumps(create_ipython_func(__a       , __a))).hexdigest()
      __snake_case				,__snake_case					:   Any  				=			os.path.join(gettempdir()       , 'ipykernel_12345'       , '321456789.py'), [1]
      __snake_case					:   Tuple  				=			mda(datasets.utils.py_utils.dumps(create_ipython_func(__a       , __a))).hexdigest()
      __snake_case				,__snake_case					:   Any  				=			os.path.join(gettempdir()       , 'ipykernel_12345'       , '654123987.py'), [0]
      __snake_case					:   Tuple  				=			mda(datasets.utils.py_utils.dumps(create_ipython_func(__a       , __a))).hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)







   def      SCREAMING_SNAKE_CASE__       (self)      ->   List[str]:
      """simple docstring"""






      __snake_case				,__snake_case					:   str  				=			[0], [1]

      def func():
         return foo, bar

      __snake_case					:   Union[str, Any]  				=			'__main__'

      def globalvars_mocka_side_effect(__a       , *__a       , **__a):
         return {"foo": foo, "bar": bar}

      def globalvars_mocka_side_effect(__a       , *__a       , **__a):
         return {"bar": bar, "foo": foo}

      with patch('dill.detect.globalvars'       , side_effect=__a) as globalvars_mocka:
         __snake_case					:   Union[str, Any]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
         self.assertGreater(globalvars_mocka.call_count       , 0)
      with patch('dill.detect.globalvars'       , side_effect=__a) as globalvars_mocka:
         __snake_case					:   Dict  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
         self.assertGreater(globalvars_mocka.call_count       , 0)
      self.assertEqual(__a       , __a)




class a_     (     UpperCamelCase_				):







   def      SCREAMING_SNAKE_CASE__       (self)      ->   str:
      """simple docstring"""






      __snake_case					:   Any  				=			Hasher.hash('hello')
      __snake_case					:   Tuple  				=			Hasher.hash('hello')
      __snake_case					:   Dict  				=			Hasher.hash('there')
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)







   def      SCREAMING_SNAKE_CASE__       (self)      ->   Tuple:
      """simple docstring"""






      __snake_case					:   Any  				=			Hasher.hash(Foo('hello'))
      __snake_case					:   Optional[int]  				=			Hasher.hash(Foo('hello'))
      __snake_case					:   Dict  				=			Hasher.hash(Foo('there'))
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)







   def      SCREAMING_SNAKE_CASE__       (self)      ->   Optional[int]:
      """simple docstring"""






      __snake_case					:   Optional[int]  				=			Hasher()
      for x in ["hello", Foo('hello')]:
         hasher.update(__a)
      __snake_case					:   Dict  				=			hasher.hexdigest()
      __snake_case					:   Optional[int]  				=			Hasher()
      for x in ["hello", Foo('hello')]:
         hasher.update(__a)
      __snake_case					:   Any  				=			hasher.hexdigest()
      __snake_case					:   List[Any]  				=			Hasher()
      for x in ["there", Foo('there')]:
         hasher.update(__a)
      __snake_case					:   Any  				=			hasher.hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)







   def      SCREAMING_SNAKE_CASE__       (self)      ->   Tuple:
      """simple docstring"""






      with self.assertRaises(pickle.PicklingError):
         Hasher.hash(UnpicklableCallable(Foo('hello')))







   def      SCREAMING_SNAKE_CASE__       (self)      ->   Any:
      """simple docstring"""






      __snake_case					:   List[str]  				=			'abc'
      __snake_case					:   str  				=			[string, string]  # two strings have the same ids
      __snake_case					:   Dict  				=			[string, string]
      __snake_case					:   Optional[Any]  				=			json.loads(F"""[\"{string}\", \"{string}\"]""")  # two strings have different ids
      self.assertIs(obja[0]       , __a)
      self.assertIs(obja[0]       , obja[1])
      self.assertIs(obja[0]       , __a)
      self.assertIs(obja[0]       , obja[1])
      self.assertIsNot(obja[0]       , __a)
      self.assertIsNot(obja[0]       , obja[1])
      __snake_case					:   Dict  				=			Hasher.hash(__a)
      __snake_case					:   List[str]  				=			Hasher.hash(__a)
      __snake_case					:   Optional[int]  				=			Hasher.hash(__a)
      self.assertEqual(__a       , __a)
      self.assertEqual(__a       , __a)







   @require_tiktoken
   def      SCREAMING_SNAKE_CASE__       (self)      ->   Union[str, Any]:
      """simple docstring"""






      import tiktoken

      __snake_case					:   Tuple  				=			tiktoken.get_encoding('gpt2')
      __snake_case					:   Any  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   int  				=			tiktoken.get_encoding('r50k_base')
      __snake_case					:   Union[str, Any]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   List[Any]  				=			tiktoken.get_encoding('gpt2')
      __snake_case					:   Optional[int]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)







   @require_torch
   def      SCREAMING_SNAKE_CASE__       (self)      ->   int:
      """simple docstring"""






      import torch

      __snake_case					:   List[str]  				=			torch.tensor([1.0])
      __snake_case					:   Optional[int]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   Optional[Any]  				=			torch.tensor([2.0])
      __snake_case					:   Union[str, Any]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   str  				=			torch.tensor([1.0])
      __snake_case					:   Union[str, Any]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)







   @require_spacy
   @require_spacy_model('en_core_web_sm')
   @require_spacy_model('fr_core_news_sm')
   @pytest.mark.integration
   def      SCREAMING_SNAKE_CASE__       (self)      ->   int:
      """simple docstring"""






      import spacy

      __snake_case					:   Any  				=			spacy.load('en_core_web_sm')
      __snake_case					:   Optional[Any]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   Optional[Any]  				=			spacy.load('fr_core_news_sm')
      __snake_case					:   Any  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      __snake_case					:   List[Any]  				=			spacy.load('en_core_web_sm')
      __snake_case					:   Optional[int]  				=			mda(datasets.utils.py_utils.dumps(__a)).hexdigest()
      self.assertEqual(__a       , __a)
      self.assertNotEqual(__a       , __a)




@pytest.mark.integration
def 							_SCREAMING_SNAKE_CASE	(					A	:							Path	)     ->			Union[str, Any]:







   """simple docstring"""
   __snake_case					:   str  				=			tmp_path / 'dir1'
   __snake_case					:   List[str]  				=			tmp_path / 'dir2'
   dira.mkdir()
   dira.mkdir()
   __snake_case					:   List[Any]  				=			'script.py'
   __snake_case					:   List[str]  				=			dedent(
       '\n    from datasets.fingerprint import Hasher\n    def foo():\n        pass\n    print(Hasher.hash(foo))\n    '	)
   __snake_case					:   List[Any]  				=			dira / script_filename
   __snake_case					:   Optional[Any]  				=			dira / script_filename
   with script_patha.open('w'	) as f:
      f.write(A	)
   with script_patha.open('w'	) as f:
      f.write(A	)
   __snake_case					:   str  				=			subprocess.check_output(['python', str(A	)]	)
   __snake_case					:   Any  				=			subprocess.check_output(['python', str(A	)]	)
   assert fingerprinta == fingerprinta




def 							_SCREAMING_SNAKE_CASE	(					)     ->			Union[str, Any]:







   """simple docstring"""
   __snake_case					:   str  				=			{'a': [0, 1, 2]}
   __snake_case					:   Any  				=			DatasetChild(InMemoryTable.from_pydict(A	)	)
   __snake_case					:   Any  				=			dataset.funca()._fingerprint
   assert expected_fingerprint == dataset.funca()._fingerprint
   assert expected_fingerprint != dataset.funca()._fingerprint

   with Pool(2	) as p:
      assert expected_fingerprint == p.apply_async(dataset.funca	).get()._fingerprint
      assert expected_fingerprint != p.apply_async(dataset.funca	).get()._fingerprint




def 							_SCREAMING_SNAKE_CASE	(					)     ->			Tuple:







   """simple docstring"""
   __snake_case					:   Optional[Any]  				=			{'a': [0, 1, 2]}




   class a_     (     datasets.Dataset				):







      @fingerprint_transform(inplace=__a)
      def      SCREAMING_SNAKE_CASE__       (self       , __a)      ->   Optional[Any]:
         """simple docstring"""






         return DummyDatasetChild(self.data       , fingerprint=__a)


   __snake_case					:   str  				=			DummyDatasetChild(InMemoryTable.from_pydict(A	)	).func()




   class a_     (     datasets.Dataset				):







      @fingerprint_transform(inplace=__a       , version='1.0.0')
      def      SCREAMING_SNAKE_CASE__       (self       , __a)      ->   Any:
         """simple docstring"""






         return DummyDatasetChild(self.data       , fingerprint=__a)


   __snake_case					:   Optional[int]  				=			DummyDatasetChild(InMemoryTable.from_pydict(A	)	).func()




   class a_     (     datasets.Dataset				):







      @fingerprint_transform(inplace=__a       , version='2.0.0')
      def      SCREAMING_SNAKE_CASE__       (self       , __a)      ->   List[str]:
         """simple docstring"""






         return DummyDatasetChild(self.data       , fingerprint=__a)


   __snake_case					:   str  				=			DummyDatasetChild(InMemoryTable.from_pydict(A	)	).func()

   assert len({fingeprint_no_version, fingeprint_a, fingeprint_a}	) == 3





def 							_SCREAMING_SNAKE_CASE	(					)     ->			List[str]:







   """simple docstring"""
   # AttributeError: module 'dill._dill' has no attribute 'stack'
   __snake_case					:   Optional[int]  				=			Hasher()
   hasher.update(lambda A	: x	)







'''simple docstring'''






def 							_SCREAMING_SNAKE_CASE	(					)     ->			int:







   """simple docstring"""

   for a in range(3_00	):
      for b in range(a + 1	,		4_00	):
         for c in range(b + 1	,		5_00	):
            if (a + b + c) == 10_00 and (a**2) + (b**2) == (c**2):
               return a * b * c

   return -1




def 							_SCREAMING_SNAKE_CASE	(					)     ->			int:







   """simple docstring"""

   for a in range(3_00	):
      for b in range(4_00	):
         __snake_case					:   Optional[Any]  				=			10_00 - a - b
         if a < b < c and (a**2) + (b**2) == (c**2):
            return a * b * c

   return -1




def 							_SCREAMING_SNAKE_CASE	(					)     ->			None:







   """simple docstring"""
   import timeit

   print(
       timeit.timeit('solution()'	,		setup='from __main__ import solution'	,		number=10_00	)	)
   print(
       timeit.timeit(
           'solution_fast()'	,		setup='from __main__ import solution_fast'	,		number=10_00	)	)


if __name__ == "__main__":
      print(f'''{solution() = }''')