






# Copyright 2022 The HuggingFace Team and The OpenBMB Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

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


UpperCamelCase								=		{
    "configuration_cpmant": ["CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP", "CpmAntConfig"],
    "tokenization_cpmant": ["CpmAntTokenizer"],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							UpperCamelCase								=		[
							    "CPMANT_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "CpmAntForCausalLM",
							    "CpmAntModel",
							    "CpmAntPreTrainedModel",
							]


if TYPE_CHECKING:
							from .configuration_cpmant import CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP, CpmAntConfig
							from .tokenization_cpmant import CpmAntTokenizer

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_cpmant import (
														    CPMANT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    CpmAntForCausalLM,
														    CpmAntModel,
														    CpmAntPreTrainedModel,
														)


else:
							import sys

							UpperCamelCase								=		_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   ):




			"""simple docstring"""







			def   lowerCamelCase__  (					self    :       Optional[int]						)   ->			List[str]:







								"""simple docstring"""
								A_								=    10




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







								"""simple docstring"""
								A_								=    [1, 2, 3, 4]
								A_								=    [1, 2, 3, 4, 0, 0, 0, 0, 0, 0]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       List[str]						)   ->			List[Any]:







								"""simple docstring"""
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       str						)   ->			Dict:







								"""simple docstring"""
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
								A_								=    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
								self.assertEqual(truncate_or_pad(_snake_case							, self.block_size							, 0						)							, _snake_case						)




			def   lowerCamelCase__  (					self    :       Dict						)   ->			Dict:







								"""simple docstring"""
								A_								=    "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."
								A_			,     A_								=    process_story(_snake_case						)
								self.assertEqual(_snake_case							, []						)




			def   lowerCamelCase__  (					self    :       str						)   ->			str:







								"""simple docstring"""
								A_								=    ""
								A_			,     A_								=    process_story(_snake_case						)
								self.assertEqual(_snake_case							, []						)
								self.assertEqual(_snake_case							, []						)




			def   lowerCamelCase__  (					self    :       Tuple						)   ->			Optional[Any]:







								"""simple docstring"""
								A_								=    (
								    "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_								=    process_story(_snake_case						)

								A_								=    [
								    "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(_snake_case							, _snake_case						)

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




			def   lowerCamelCase__  (					self    :       List[str]						)   ->			Optional[Any]:







								"""simple docstring"""
								A_								=    torch.tensor([1, 2, 3, 4]						)
								A_								=    torch.tensor([1, 1, 1, 1]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 0						).numpy()							, expected.numpy()						)




			def   lowerCamelCase__  (					self    :       List[Any]						)   ->			Optional[int]:







								"""simple docstring"""
								A_								=    torch.tensor([1, 2, 3, 4, 23, 23, 23]						)
								A_								=    torch.tensor([1, 1, 1, 1, 0, 0, 0]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 23						).numpy()							, expected.numpy()						)




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







								"""simple docstring"""
								A_								=    torch.tensor([8, 2, 3, 4, 1, 1, 1]						)
								A_								=    torch.tensor([1, 1, 1, 1, 0, 0, 0]						)
								np.testing.assert_array_equal(build_mask(_snake_case							, 1						).numpy()							, expected.numpy()						)






			def   lowerCamelCase__  (					self    :       int						)   ->			List[str]:







								"""simple docstring"""
								A_								=    101
								A_								=    torch.tensor([[1, 2, 3, 4, 5, 6], [1, 2, 3, 101, 5, 6], [1, 101, 3, 4, 101, 6]]						)
								A_								=    torch.tensor([[1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 1, 1]]						)

								A_								=    compute_token_type_ids(_snake_case							, _snake_case						)
								np.testing.assert_array_equal(_snake_case							, _snake_case						)




