



'''simple docstring'''




from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCamelCase							:str				    =					{'''configuration_focalnet''': ['''FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''FocalNetConfig''']}


try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase							:List[Any]				    =					[
						    '''FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''FocalNetForImageClassification''',
						    '''FocalNetForMaskedImageModeling''',
						    '''FocalNetBackbone''',
						    '''FocalNetModel''',
						    '''FocalNetPreTrainedModel''',
						]

if TYPE_CHECKING:
						from .configuration_focalnet import FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP, FocalNetConfig

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_focalnet import (
												    FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST,
												    FocalNetBackbone,
												    FocalNetForImageClassification,
												    FocalNetForMaskedImageModeling,
												    FocalNetModel,
												    FocalNetPreTrainedModel,
												)

else:
						import sys

						lowerCamelCase							:int				    =					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




'''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 	_lowerCAmelCase							(			unittest.TestCase ):


	def     _a	(self							):
				A_	:						Optional[Any]	=     10


	def     _a	(self							):
				A_	:						Dict	=     [1, 2, 3, 4]
				A_	:						List[Any]	=     [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
				self.assertEqual(truncate_or_pad(lowercase       ,      self.block_size       ,      0							)       ,      lowercase							)


	def     _a	(self							):
				A_	:						List[Any]	=     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				A_	:						Tuple	=     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				self.assertEqual(truncate_or_pad(lowercase       ,      self.block_size       ,      0							)       ,      lowercase							)


	def     _a	(self							):
				A_	:						Optional[Any]	=     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
				A_	:						Any	=     [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
				self.assertEqual(truncate_or_pad(lowercase       ,      self.block_size       ,      0							)       ,      lowercase							)


	def     _a	(self							):
				A_	:						List[str]	=     """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."""
				A_,    A_	:						Dict	=     process_story(lowercase							)
				self.assertEqual(lowercase       ,      []							)


	def     _a	(self							):
				A_	:						Optional[int]	=     """"""
				A_,    A_	:						List[str]	=     process_story(lowercase							)
				self.assertEqual(lowercase       ,      []							)
				self.assertEqual(lowercase       ,      []							)


	def     _a	(self							):
				A_	:						Optional[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"""
				)
				A_,    A_	:						int	=     process_story(lowercase							)

				A_	:						Optional[Any]	=     [
				    """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(lowercase       ,      lowercase							)

				A_	:						Dict	=     ["""It was the best of times."""]
				self.assertEqual(lowercase       ,      lowercase							)


	def     _a	(self							):
				A_	:						Optional[int]	=     torch.tensor([1, 2, 3, 4]							)
				A_	:						Dict	=     torch.tensor([1, 1, 1, 1]							)
				np.testing.assert_array_equal(build_mask(lowercase       ,      0							).numpy()       ,      expected.numpy()							)


	def     _a	(self							):
				A_	:						str	=     torch.tensor([1, 2, 3, 4, 23, 23, 23]							)
				A_	:						str	=     torch.tensor([1, 1, 1, 1, 0, 0, 0]							)
				np.testing.assert_array_equal(build_mask(lowercase       ,      23							).numpy()       ,      expected.numpy()							)


	def     _a	(self							):
				A_	:						Any	=     torch.tensor([8, 2, 3, 4, 1, 1, 1]							)
				A_	:						List[str]	=     torch.tensor([1, 1, 1, 1, 0, 0, 0]							)
				np.testing.assert_array_equal(build_mask(lowercase       ,      1							).numpy()       ,      expected.numpy()							)


	def     _a	(self							):
				A_	:						List[Any]	=     101
				A_	:						List[Any]	=     torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]							)
				A_	:						List[str]	=     torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]							)

				A_	:						Dict	=     compute_token_type_ids(lowercase       ,      lowercase							)
				np.testing.assert_array_equal(lowercase       ,      lowercase							)