



'''simple docstring'''



import unittest

import numpy as np

from transformers.testing_utils import require_flax, require_tf, require_torch
from transformers.utils import (
    expand_dims,
    flatten_dict,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    reshape,
    squeeze,
    transpose,
)


if is_flax_available():
							import jax.numpy as jnp

if is_tf_available():
							import tensorflow as tf

if is_torch_available():
							import torch
class 	lowerCamelCase_							(					unittest.TestCase			):







						def 					__lowercase    (  self   :      Optional[int]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Any     					=			{
													    '''task_specific_params''': {
													        '''summarization''': {'''length_penalty''': 1.0, '''max_length''': 1_28, '''min_length''': 12, '''num_beams''': 4},
													        '''summarization_cnn''': {'''length_penalty''': 2.0, '''max_length''': 1_42, '''min_length''': 56, '''num_beams''': 4},
													        '''summarization_xsum''': {'''length_penalty''': 1.0, '''max_length''': 62, '''min_length''': 11, '''num_beams''': 6},
													    }
													}
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			{
													    '''task_specific_params.summarization.length_penalty''': 1.0,
													    '''task_specific_params.summarization.max_length''': 1_28,
													    '''task_specific_params.summarization.min_length''': 12,
													    '''task_specific_params.summarization.num_beams''': 4,
													    '''task_specific_params.summarization_cnn.length_penalty''': 2.0,
													    '''task_specific_params.summarization_cnn.max_length''': 1_42,
													    '''task_specific_params.summarization_cnn.min_length''': 56,
													    '''task_specific_params.summarization_cnn.num_beams''': 4,
													    '''task_specific_params.summarization_xsum.length_penalty''': 1.0,
													    '''task_specific_params.summarization_xsum.max_length''': 62,
													    '''task_specific_params.summarization_xsum.min_length''': 11,
													    '''task_specific_params.summarization_xsum.num_beams''': 6,
													}

													self.assertEqual(flatten_dict(lowerCAmelCase__				)				,    lowerCAmelCase__				)







						def 					__lowercase    (  self   :      Optional[int]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      str     					=			np.random.randn(3				,    4				)
													self.assertTrue(np.allclose(transpose(lowerCAmelCase__				)				,    x.transpose()				)				)

													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			np.random.randn(3				,    4				,    5				)
													self.assertTrue(np.allclose(transpose(lowerCAmelCase__				,    axes=(1, 2, 0)				)				,    x.transpose((1, 2, 0)				)				)				)







						@require_torch
						def 					__lowercase    (  self   :      Dict				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			np.random.randn(3				,    4				)
													SCREAMING_SNAKE_CASE					:      Dict     					=			torch.tensor(lowerCAmelCase__				)
													self.assertTrue(np.allclose(transpose(lowerCAmelCase__				)				,    transpose(lowerCAmelCase__				).numpy()				)				)

													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			np.random.randn(3				,    4				,    5				)
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			torch.tensor(lowerCAmelCase__				)
													self.assertTrue(np.allclose(transpose(lowerCAmelCase__				,    axes=(1, 2, 0)				)				,    transpose(lowerCAmelCase__				,    axes=(1, 2, 0)				).numpy()				)				)







						@require_tf
						def 					__lowercase    (  self   :      Any				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			np.random.randn(3				,    4				)
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			tf.constant(lowerCAmelCase__				)
													self.assertTrue(np.allclose(transpose(lowerCAmelCase__				)				,    transpose(lowerCAmelCase__				).numpy()				)				)

													SCREAMING_SNAKE_CASE					:      List[Any]     					=			np.random.randn(3				,    4				,    5				)
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			tf.constant(lowerCAmelCase__				)
													self.assertTrue(np.allclose(transpose(lowerCAmelCase__				,    axes=(1, 2, 0)				)				,    transpose(lowerCAmelCase__				,    axes=(1, 2, 0)				).numpy()				)				)







						@require_flax
						def 					__lowercase    (  self   :      Optional[int]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			np.random.randn(3				,    4				)
													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			jnp.array(lowerCAmelCase__				)
													self.assertTrue(np.allclose(transpose(lowerCAmelCase__				)				,    np.asarray(transpose(lowerCAmelCase__				)				)				)				)

													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			np.random.randn(3				,    4				,    5				)
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			jnp.array(lowerCAmelCase__				)
													self.assertTrue(np.allclose(transpose(lowerCAmelCase__				,    axes=(1, 2, 0)				)				,    np.asarray(transpose(lowerCAmelCase__				,    axes=(1, 2, 0)				)				)				)				)







						def 					__lowercase    (  self   :      Dict				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      int     					=			np.random.randn(3				,    4				)
													self.assertTrue(np.allclose(reshape(lowerCAmelCase__				,    (4, 3)				)				,    np.reshape(lowerCAmelCase__				,    (4, 3)				)				)				)

													SCREAMING_SNAKE_CASE					:      List[str]     					=			np.random.randn(3				,    4				,    5				)
													self.assertTrue(np.allclose(reshape(lowerCAmelCase__				,    (12, 5)				)				,    np.reshape(lowerCAmelCase__				,    (12, 5)				)				)				)







						@require_torch
						def 					__lowercase    (  self   :      List[Any]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      str     					=			np.random.randn(3				,    4				)
													SCREAMING_SNAKE_CASE					:      Any     					=			torch.tensor(lowerCAmelCase__				)
													self.assertTrue(np.allclose(reshape(lowerCAmelCase__				,    (4, 3)				)				,    reshape(lowerCAmelCase__				,    (4, 3)				).numpy()				)				)

													SCREAMING_SNAKE_CASE					:      Any     					=			np.random.randn(3				,    4				,    5				)
													SCREAMING_SNAKE_CASE					:      Any     					=			torch.tensor(lowerCAmelCase__				)
													self.assertTrue(np.allclose(reshape(lowerCAmelCase__				,    (12, 5)				)				,    reshape(lowerCAmelCase__				,    (12, 5)				).numpy()				)				)







						@require_tf
						def 					__lowercase    (  self   :      Optional[int]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Tuple     					=			np.random.randn(3				,    4				)
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			tf.constant(lowerCAmelCase__				)
													self.assertTrue(np.allclose(reshape(lowerCAmelCase__				,    (4, 3)				)				,    reshape(lowerCAmelCase__				,    (4, 3)				).numpy()				)				)

													SCREAMING_SNAKE_CASE					:      Tuple     					=			np.random.randn(3				,    4				,    5				)
													SCREAMING_SNAKE_CASE					:      Dict     					=			tf.constant(lowerCAmelCase__				)
													self.assertTrue(np.allclose(reshape(lowerCAmelCase__				,    (12, 5)				)				,    reshape(lowerCAmelCase__				,    (12, 5)				).numpy()				)				)







						@require_flax
						def 					__lowercase    (  self   :      List[Any]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			np.random.randn(3				,    4				)
													SCREAMING_SNAKE_CASE					:      Dict     					=			jnp.array(lowerCAmelCase__				)
													self.assertTrue(np.allclose(reshape(lowerCAmelCase__				,    (4, 3)				)				,    np.asarray(reshape(lowerCAmelCase__				,    (4, 3)				)				)				)				)

													SCREAMING_SNAKE_CASE					:      Tuple     					=			np.random.randn(3				,    4				,    5				)
													SCREAMING_SNAKE_CASE					:      Any     					=			jnp.array(lowerCAmelCase__				)
													self.assertTrue(np.allclose(reshape(lowerCAmelCase__				,    (12, 5)				)				,    np.asarray(reshape(lowerCAmelCase__				,    (12, 5)				)				)				)				)







						def 					__lowercase    (  self   :      List[str]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			np.random.randn(1				,    3				,    4				)
													self.assertTrue(np.allclose(squeeze(lowerCAmelCase__				)				,    np.squeeze(lowerCAmelCase__				)				)				)

													SCREAMING_SNAKE_CASE					:      Tuple     					=			np.random.randn(1				,    4				,    1				,    5				)
													self.assertTrue(np.allclose(squeeze(lowerCAmelCase__				,    axis=2				)				,    np.squeeze(lowerCAmelCase__				,    axis=2				)				)				)







						@require_torch
						def 					__lowercase    (  self   :      List[str]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			np.random.randn(1				,    3				,    4				)
													SCREAMING_SNAKE_CASE					:      int     					=			torch.tensor(lowerCAmelCase__				)
													self.assertTrue(np.allclose(squeeze(lowerCAmelCase__				)				,    squeeze(lowerCAmelCase__				).numpy()				)				)

													SCREAMING_SNAKE_CASE					:      List[str]     					=			np.random.randn(1				,    4				,    1				,    5				)
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			torch.tensor(lowerCAmelCase__				)
													self.assertTrue(np.allclose(squeeze(lowerCAmelCase__				,    axis=2				)				,    squeeze(lowerCAmelCase__				,    axis=2				).numpy()				)				)







						@require_tf
						def 					__lowercase    (  self   :      Tuple				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			np.random.randn(1				,    3				,    4				)
													SCREAMING_SNAKE_CASE					:      str     					=			tf.constant(lowerCAmelCase__				)
													self.assertTrue(np.allclose(squeeze(lowerCAmelCase__				)				,    squeeze(lowerCAmelCase__				).numpy()				)				)

													SCREAMING_SNAKE_CASE					:      List[str]     					=			np.random.randn(1				,    4				,    1				,    5				)
													SCREAMING_SNAKE_CASE					:      Union[str, Any]     					=			tf.constant(lowerCAmelCase__				)
													self.assertTrue(np.allclose(squeeze(lowerCAmelCase__				,    axis=2				)				,    squeeze(lowerCAmelCase__				,    axis=2				).numpy()				)				)







						@require_flax
						def 					__lowercase    (  self   :      int				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Any     					=			np.random.randn(1				,    3				,    4				)
													SCREAMING_SNAKE_CASE					:      str     					=			jnp.array(lowerCAmelCase__				)
													self.assertTrue(np.allclose(squeeze(lowerCAmelCase__				)				,    np.asarray(squeeze(lowerCAmelCase__				)				)				)				)

													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			np.random.randn(1				,    4				,    1				,    5				)
													SCREAMING_SNAKE_CASE					:      List[Any]     					=			jnp.array(lowerCAmelCase__				)
													self.assertTrue(np.allclose(squeeze(lowerCAmelCase__				,    axis=2				)				,    np.asarray(squeeze(lowerCAmelCase__				,    axis=2				)				)				)				)







						def 					__lowercase    (  self   :      int				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Dict     					=			np.random.randn(3				,    4				)
													self.assertTrue(np.allclose(expand_dims(lowerCAmelCase__				,    axis=1				)				,    np.expand_dims(lowerCAmelCase__				,    axis=1				)				)				)







						@require_torch
						def 					__lowercase    (  self   :      Any				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Tuple     					=			np.random.randn(3				,    4				)
													SCREAMING_SNAKE_CASE					:      Optional[Any]     					=			torch.tensor(lowerCAmelCase__				)
													self.assertTrue(np.allclose(expand_dims(lowerCAmelCase__				,    axis=1				)				,    expand_dims(lowerCAmelCase__				,    axis=1				).numpy()				)				)







						@require_tf
						def 					__lowercase    (  self   :      List[Any]				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      str     					=			np.random.randn(3				,    4				)
													SCREAMING_SNAKE_CASE					:      Dict     					=			tf.constant(lowerCAmelCase__				)
													self.assertTrue(np.allclose(expand_dims(lowerCAmelCase__				,    axis=1				)				,    expand_dims(lowerCAmelCase__				,    axis=1				).numpy()				)				)







						@require_flax
						def 					__lowercase    (  self   :      Any				):

													"""simple docstring"""
													SCREAMING_SNAKE_CASE					:      Optional[int]     					=			np.random.randn(3				,    4				)
													SCREAMING_SNAKE_CASE					:      List[str]     					=			jnp.array(lowerCAmelCase__				)
													self.assertTrue(np.allclose(expand_dims(lowerCAmelCase__				,    axis=1				)				,    np.asarray(expand_dims(lowerCAmelCase__				,    axis=1				)				)				)				)









'''simple docstring'''



import os


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_doctest_list.py
lowerCAmelCase_     :       Optional[Any]								=						'.'


if __name__ == "__main__":
							lowerCAmelCase_     :       Optional[Any]								=						os.path.join(REPO_PATH, 'utils/documentation_tests.txt')
							lowerCAmelCase_     :       Dict								=						[]
							lowerCAmelCase_     :       Any								=						[]
							with open(doctest_file_path) as fp:
														for line in fp:
																					lowerCAmelCase_     :       List[str]								=						line.strip()
																					lowerCAmelCase_     :       Optional[Any]								=						os.path.join(REPO_PATH, line)
																					if not (os.path.isfile(path) or os.path.isdir(path)):
																												non_existent_paths.append(line)
																					all_paths.append(path)
							if len(non_existent_paths) > 0:
														lowerCAmelCase_     :       Dict								=						'\n'.join(non_existent_paths)
														raise ValueError(f'`utils/documentation_tests.txt` contains non-existent paths:\n{non_existent_paths}')
							if all_paths != sorted(all_paths):
														raise ValueError('Files in `utils/documentation_tests.txt` are not in alphabetical order.')




