



"""simple docstring"""






import unittest

import numpy as np
import torch

from .utils_summarization import build_mask, compute_token_type_ids, process_story, truncate_or_pad






class 			__snake_case			(      unittest.TestCase):




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[Any]						):






         """simple docstring"""






         _lowerCamelCase		:							str            =					1_0




  def 		SCREAMING_SNAKE_CASE							(					self	:		Any						):






         """simple docstring"""






         _lowerCamelCase		:							str            =					[1, 2, 3, 4]
         _lowerCamelCase		:							Union[str, Any]            =					[1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
         self.assertEqual(truncate_or_pad(_lowerCAmelCase		,   self.block_size		,   0						)		,   _lowerCAmelCase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[str]						):






         """simple docstring"""






         _lowerCamelCase		:							Any            =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0]
         _lowerCamelCase		:							Dict            =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0]
         self.assertEqual(truncate_or_pad(_lowerCAmelCase		,   self.block_size		,   0						)		,   _lowerCAmelCase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[str]						):






         """simple docstring"""






         _lowerCamelCase		:							Any            =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0, 1_1, 1_2, 1_3]
         _lowerCamelCase		:							Dict            =					[1, 2, 3, 4, 5, 6, 7, 8, 9, 1_0]
         self.assertEqual(truncate_or_pad(_lowerCAmelCase		,   self.block_size		,   0						)		,   _lowerCAmelCase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Union[str, Any]						):






         """simple docstring"""






         _lowerCamelCase		:							Optional[Any]            =					'''It was the year of Our Lord one thousand seven hundred and\n        seventy-five.\n\nSpiritual revelations were conceded to England at that\n        favoured period, as at this.'''
         _lowerCamelCase     ,       _lowerCamelCase		:							Optional[int]            =					process_story(_lowerCAmelCase						)
         self.assertEqual(_lowerCAmelCase		,   []						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Dict						):






         """simple docstring"""






         _lowerCamelCase		:							str            =					''''''
         _lowerCamelCase     ,       _lowerCamelCase		:							Union[str, Any]            =					process_story(_lowerCAmelCase						)
         self.assertEqual(_lowerCAmelCase		,   []						)
         self.assertEqual(_lowerCAmelCase		,   []						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[Any]						):






         """simple docstring"""






         _lowerCamelCase		:							Union[str, Any]            =					(
             '''It was the year of Our Lord one thousand seven hundred and '''
             '''seventy-five\n\nSpiritual revelations were conceded to England '''
             '''at that favoured period, as at this.\n@highlight\n\nIt was the best of times'''
         )
         _lowerCamelCase     ,       _lowerCamelCase		:							Union[str, Any]            =					process_story(_lowerCAmelCase						)

         _lowerCamelCase		:							Optional[int]            =					[
             '''It was the year of Our Lord one thousand seven hundred and seventy-five.''',
             '''Spiritual revelations were conceded to England at that favoured period, as at this.''',
         ]
         self.assertEqual(_lowerCAmelCase		,   _lowerCAmelCase						)

         _lowerCamelCase		:							Any            =					['''It was the best of times.''']
         self.assertEqual(_lowerCAmelCase		,   _lowerCAmelCase						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Union[str, Any]						):






         """simple docstring"""






         _lowerCamelCase		:							List[str]            =					torch.tensor([1, 2, 3, 4]						)
         _lowerCamelCase		:							Tuple            =					torch.tensor([1, 1, 1, 1]						)
         np.testing.assert_array_equal(build_mask(_lowerCAmelCase		,   0						).numpy()		,   expected.numpy()						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		Union[str, Any]						):






         """simple docstring"""






         _lowerCamelCase		:							Union[str, Any]            =					torch.tensor([1, 2, 3, 4, 2_3, 2_3, 2_3]						)
         _lowerCamelCase		:							Dict            =					torch.tensor([1, 1, 1, 1, 0, 0, 0]						)
         np.testing.assert_array_equal(build_mask(_lowerCAmelCase		,   2_3						).numpy()		,   expected.numpy()						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		int						):






         """simple docstring"""






         _lowerCamelCase		:							Dict            =					torch.tensor([8, 2, 3, 4, 1, 1, 1]						)
         _lowerCamelCase		:							List[Any]            =					torch.tensor([1, 1, 1, 1, 0, 0, 0]						)
         np.testing.assert_array_equal(build_mask(_lowerCAmelCase		,   1						).numpy()		,   expected.numpy()						)




  def 		SCREAMING_SNAKE_CASE							(					self	:		List[str]						):






         """simple docstring"""






         _lowerCamelCase		:							List[str]            =					1_0_1
         _lowerCamelCase		:							List[str]            =					torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 1_0_1, 5, 6], [1, 1_0_1, 3, 4, 1_0_1, 6]]						)
         _lowerCamelCase		:							Optional[int]            =					torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]						)

         _lowerCamelCase		:							List[str]            =					compute_token_type_ids(_lowerCAmelCase		,   _lowerCAmelCase						)
         np.testing.assert_array_equal(_lowerCAmelCase		,   _lowerCAmelCase						)






import importlib.metadata
from typing import Union

from packaging.version import Version, parse

from .constants import STR_OPERATION_TO_FUNC


SCREAMING_SNAKE_CASE						:Union[str, Any]			=  parse(importlib.metadata.version('''torch'''))



def       _lowerCAmelCase    (				lowerCAmelCase_				:Union[str, Version]		,    lowerCAmelCase_				:str		,    lowerCAmelCase_				:str				)->Any:
   '''simple docstring'''






   if operation not in STR_OPERATION_TO_FUNC.keys():
      raise ValueError(F'''`operation` must be one of {list(STR_OPERATION_TO_FUNC.keys()				)}, received {operation}'''				)
   snake_case_            =       STR_OPERATION_TO_FUNC[operation]
   if isinstance(lowerCAmelCase_		,    lowerCAmelCase_				):
      snake_case_            =       parse(importlib.metadata.version(lowerCAmelCase_				)				)
   return operation(lowerCAmelCase_		,    parse(lowerCAmelCase_				)				)



def       _lowerCAmelCase    (				lowerCAmelCase_				:str		,    lowerCAmelCase_				:str				)->Any:
   '''simple docstring'''






   return compare_versions(lowerCAmelCase_		,    lowerCAmelCase_		,    lowerCAmelCase_				)




