



'''simple docstring'''





from transformers import (
    DPRContextEncoderTokenizer,
    DPRContextEncoderTokenizerFast,
    DPRQuestionEncoderTokenizer,
    DPRQuestionEncoderTokenizerFast,
    DPRReaderOutput,
    DPRReaderTokenizer,
    DPRReaderTokenizerFast,
)
from transformers.testing_utils import require_tokenizers, slow
from transformers.tokenization_utils_base import BatchEncoding

from ..bert.test_tokenization_bert import BertTokenizationTest






@require_tokenizers
class  lowerCamelCase_   (    SCREAMING_SNAKE_CASE_					):
  """simple docstring"""




  a_							 =DPRContextEncoderTokenizer
  a_							 =DPRContextEncoderTokenizerFast
  a_							 =True






@require_tokenizers
class  lowerCamelCase_   (    SCREAMING_SNAKE_CASE_					):
  """simple docstring"""




  a_							 =DPRQuestionEncoderTokenizer
  a_							 =DPRQuestionEncoderTokenizerFast
  a_							 =True






@require_tokenizers
class  lowerCamelCase_   (    SCREAMING_SNAKE_CASE_					):
  """simple docstring"""




  a_							 =DPRReaderTokenizer
  a_							 =DPRReaderTokenizerFast
  a_							 =True




  @slow
  def 						_lowercase					(			self				:     int       ) -> Dict:
    __lowerCamelCase	:	List[Any]   	=			self.tokenizer_class.from_pretrained('bert-base-uncased'       )

    __lowerCamelCase	:	List[str]   	=			tokenizer.encode('question sequence'      ,     add_special_tokens=_a       )
    __lowerCamelCase	:	Tuple   	=			tokenizer.encode('title sequence'      ,     add_special_tokens=_a       )
    __lowerCamelCase	:	List[str]   	=			tokenizer.encode('text sequence ' * 4      ,     add_special_tokens=_a       )
    __lowerCamelCase	:	List[Any]   	=			[[101] + text_a + [102] + text_a + [102] + text_a]
    __lowerCamelCase	:	Optional[Any]   	=			BatchEncoding({'input_ids': input_ids}       )

    __lowerCamelCase	:	Any   	=			[[0] * len(input_ids[0]       )]
    __lowerCamelCase	:	List[Any]   	=			[[0] * len(input_ids[0]       )]
    __lowerCamelCase	:	Dict   	=			[0]
    __lowerCamelCase	:	Dict   	=			DPRReaderOutput(_a      ,     _a      ,     _a       )

    __lowerCamelCase	,__lowerCamelCase	:	Optional[Any]   	=			8, 9
    __lowerCamelCase	:	Union[str, Any]   	=			10
    __lowerCamelCase	:	List[str]   	=			10
    __lowerCamelCase	:	Optional[int]   	=			tokenizer.decode_best_spans(_a      ,     _a       )
    self.assertEqual(predicted_spans[0].start_index      ,     _a       )
    self.assertEqual(predicted_spans[0].end_index      ,     _a       )
    self.assertEqual(predicted_spans[0].doc_id      ,     0       )




  @slow
  def 						_lowercase					(			self				:     List[Any]       ) -> str:
    __lowerCamelCase	:	Optional[Any]   	=			self.tokenizer_class.from_pretrained('bert-base-uncased'       )

    __lowerCamelCase	:	List[str]   	=			tokenizer.encode('question sequence'      ,     add_special_tokens=_a       )
    __lowerCamelCase	:	Optional[Any]   	=			tokenizer.encode('title sequence'      ,     add_special_tokens=_a       )
    __lowerCamelCase	:	Tuple   	=			tokenizer.encode('text sequence'      ,     add_special_tokens=_a       )
    __lowerCamelCase	:	str   	=			[101] + text_a + [102] + text_a + [102] + text_a
    __lowerCamelCase	:	List[str]   	=			tokenizer(questions=['question sequence']      ,     titles=['title sequence']      ,     texts=['text sequence']       )
    self.assertIn('input_ids'      ,     _a       )
    self.assertIn('attention_mask'      ,     _a       )
    self.assertListEqual(encoded_input['input_ids'][0]      ,     _a       )











'''simple docstring'''





import math
from timeit import timeit

def 	a_					(							_lowerCAmelCase	)				->				int:
  __lowerCamelCase	:	int   	=			0
  __lowerCamelCase	:	Optional[int]   	=			abs(_lowerCAmelCase	)
  while True:
    __lowerCamelCase	:	List[str]   	=			n // 10
    digits += 1
    if n == 0:
      break
  return digits

def 	a_					(							_lowerCAmelCase	)				->				int:
  return 1 if n == 0 else math.floor(math.log(abs(_lowerCAmelCase	)	,10	) + 1	)

def 	a_					(							_lowerCAmelCase	)				->				int:
  return len(str(abs(_lowerCAmelCase	)	)	)

def 	a_					(							)				->				None:
  from collections.abc import Callable

  def benchmark_a_function(_lowerCAmelCase	,_lowerCAmelCase	) -> None:
    __lowerCamelCase	:	Any   	=			F'{func.__name__}({value})'
    __lowerCamelCase	:	int   	=			timeit(F'__main__.{call}'	,setup='import __main__'	)
    print(F'{call}: {func(_lowerCAmelCase	)} -- {timing} seconds'	)

  for value in (262144, 1125899906842624, 1267650600228229401496703205376):
    for func in (num_digits, num_digits_fast, num_digits_faster):
      benchmark_a_function(_lowerCAmelCase	,_lowerCAmelCase	)
    print()


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   benchmark()






