




'''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    lowerCAmelCase   ( self	)   ->	Optional[Any]:



            '''simple docstring'''




            __snake_case            =	{
                '''task_specific_params''': {
                    '''summarization''': {'''length_penalty''': 1.0, '''max_length''': 128, '''min_length''': 12, '''num_beams''': 4},
                    '''summarization_cnn''': {'''length_penalty''': 2.0, '''max_length''': 142, '''min_length''': 56, '''num_beams''': 4},
                    '''summarization_xsum''': {'''length_penalty''': 1.0, '''max_length''': 62, '''min_length''': 11, '''num_beams''': 6},
                }
            }
            __snake_case            =	{
                '''task_specific_params.summarization.length_penalty''': 1.0,
                '''task_specific_params.summarization.max_length''': 128,
                '''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''': 142,
                '''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(__SCREAMING_SNAKE_CASE	)     ,	__SCREAMING_SNAKE_CASE	)


       def    lowerCAmelCase   ( self	)   ->	Dict:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            self.assertTrue(np.allclose(transpose(__SCREAMING_SNAKE_CASE	)     ,	x.transpose()	)	)

            __snake_case            =	np.random.randn(3     ,	4     ,	5	)
            self.assertTrue(np.allclose(transpose(__SCREAMING_SNAKE_CASE     ,	axes=(1, 2, 0)	)     ,	x.transpose((1, 2, 0)	)	)	)


       @require_torch
       def    lowerCAmelCase   ( self	)   ->	Union[str, Any]:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            __snake_case            =	torch.tensor(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(transpose(__SCREAMING_SNAKE_CASE	)     ,	transpose(__SCREAMING_SNAKE_CASE	).numpy()	)	)

            __snake_case            =	np.random.randn(3     ,	4     ,	5	)
            __snake_case            =	torch.tensor(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(transpose(__SCREAMING_SNAKE_CASE     ,	axes=(1, 2, 0)	)     ,	transpose(__SCREAMING_SNAKE_CASE     ,	axes=(1, 2, 0)	).numpy()	)	)


       @require_tf
       def    lowerCAmelCase   ( self	)   ->	Union[str, Any]:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            __snake_case            =	tf.constant(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(transpose(__SCREAMING_SNAKE_CASE	)     ,	transpose(__SCREAMING_SNAKE_CASE	).numpy()	)	)

            __snake_case            =	np.random.randn(3     ,	4     ,	5	)
            __snake_case            =	tf.constant(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(transpose(__SCREAMING_SNAKE_CASE     ,	axes=(1, 2, 0)	)     ,	transpose(__SCREAMING_SNAKE_CASE     ,	axes=(1, 2, 0)	).numpy()	)	)


       @require_flax
       def    lowerCAmelCase   ( self	)   ->	List[str]:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            __snake_case            =	jnp.array(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(transpose(__SCREAMING_SNAKE_CASE	)     ,	np.asarray(transpose(__SCREAMING_SNAKE_CASE	)	)	)	)

            __snake_case            =	np.random.randn(3     ,	4     ,	5	)
            __snake_case            =	jnp.array(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(transpose(__SCREAMING_SNAKE_CASE     ,	axes=(1, 2, 0)	)     ,	np.asarray(transpose(__SCREAMING_SNAKE_CASE     ,	axes=(1, 2, 0)	)	)	)	)


       def    lowerCAmelCase   ( self	)   ->	str:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            self.assertTrue(np.allclose(reshape(__SCREAMING_SNAKE_CASE     ,	(4, 3)	)     ,	np.reshape(__SCREAMING_SNAKE_CASE     ,	(4, 3)	)	)	)

            __snake_case            =	np.random.randn(3     ,	4     ,	5	)
            self.assertTrue(np.allclose(reshape(__SCREAMING_SNAKE_CASE     ,	(12, 5)	)     ,	np.reshape(__SCREAMING_SNAKE_CASE     ,	(12, 5)	)	)	)


       @require_torch
       def    lowerCAmelCase   ( self	)   ->	Union[str, Any]:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            __snake_case            =	torch.tensor(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(reshape(__SCREAMING_SNAKE_CASE     ,	(4, 3)	)     ,	reshape(__SCREAMING_SNAKE_CASE     ,	(4, 3)	).numpy()	)	)

            __snake_case            =	np.random.randn(3     ,	4     ,	5	)
            __snake_case            =	torch.tensor(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(reshape(__SCREAMING_SNAKE_CASE     ,	(12, 5)	)     ,	reshape(__SCREAMING_SNAKE_CASE     ,	(12, 5)	).numpy()	)	)


       @require_tf
       def    lowerCAmelCase   ( self	)   ->	Optional[int]:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            __snake_case            =	tf.constant(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(reshape(__SCREAMING_SNAKE_CASE     ,	(4, 3)	)     ,	reshape(__SCREAMING_SNAKE_CASE     ,	(4, 3)	).numpy()	)	)

            __snake_case            =	np.random.randn(3     ,	4     ,	5	)
            __snake_case            =	tf.constant(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(reshape(__SCREAMING_SNAKE_CASE     ,	(12, 5)	)     ,	reshape(__SCREAMING_SNAKE_CASE     ,	(12, 5)	).numpy()	)	)


       @require_flax
       def    lowerCAmelCase   ( self	)   ->	List[str]:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            __snake_case            =	jnp.array(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(reshape(__SCREAMING_SNAKE_CASE     ,	(4, 3)	)     ,	np.asarray(reshape(__SCREAMING_SNAKE_CASE     ,	(4, 3)	)	)	)	)

            __snake_case            =	np.random.randn(3     ,	4     ,	5	)
            __snake_case            =	jnp.array(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(reshape(__SCREAMING_SNAKE_CASE     ,	(12, 5)	)     ,	np.asarray(reshape(__SCREAMING_SNAKE_CASE     ,	(12, 5)	)	)	)	)


       def    lowerCAmelCase   ( self	)   ->	List[str]:



            '''simple docstring'''




            __snake_case            =	np.random.randn(1     ,	3     ,	4	)
            self.assertTrue(np.allclose(squeeze(__SCREAMING_SNAKE_CASE	)     ,	np.squeeze(__SCREAMING_SNAKE_CASE	)	)	)

            __snake_case            =	np.random.randn(1     ,	4     ,	1     ,	5	)
            self.assertTrue(np.allclose(squeeze(__SCREAMING_SNAKE_CASE     ,	axis=2	)     ,	np.squeeze(__SCREAMING_SNAKE_CASE     ,	axis=2	)	)	)


       @require_torch
       def    lowerCAmelCase   ( self	)   ->	List[str]:



            '''simple docstring'''




            __snake_case            =	np.random.randn(1     ,	3     ,	4	)
            __snake_case            =	torch.tensor(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(squeeze(__SCREAMING_SNAKE_CASE	)     ,	squeeze(__SCREAMING_SNAKE_CASE	).numpy()	)	)

            __snake_case            =	np.random.randn(1     ,	4     ,	1     ,	5	)
            __snake_case            =	torch.tensor(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(squeeze(__SCREAMING_SNAKE_CASE     ,	axis=2	)     ,	squeeze(__SCREAMING_SNAKE_CASE     ,	axis=2	).numpy()	)	)


       @require_tf
       def    lowerCAmelCase   ( self	)   ->	Any:



            '''simple docstring'''




            __snake_case            =	np.random.randn(1     ,	3     ,	4	)
            __snake_case            =	tf.constant(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(squeeze(__SCREAMING_SNAKE_CASE	)     ,	squeeze(__SCREAMING_SNAKE_CASE	).numpy()	)	)

            __snake_case            =	np.random.randn(1     ,	4     ,	1     ,	5	)
            __snake_case            =	tf.constant(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(squeeze(__SCREAMING_SNAKE_CASE     ,	axis=2	)     ,	squeeze(__SCREAMING_SNAKE_CASE     ,	axis=2	).numpy()	)	)


       @require_flax
       def    lowerCAmelCase   ( self	)   ->	List[str]:



            '''simple docstring'''




            __snake_case            =	np.random.randn(1     ,	3     ,	4	)
            __snake_case            =	jnp.array(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(squeeze(__SCREAMING_SNAKE_CASE	)     ,	np.asarray(squeeze(__SCREAMING_SNAKE_CASE	)	)	)	)

            __snake_case            =	np.random.randn(1     ,	4     ,	1     ,	5	)
            __snake_case            =	jnp.array(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(squeeze(__SCREAMING_SNAKE_CASE     ,	axis=2	)     ,	np.asarray(squeeze(__SCREAMING_SNAKE_CASE     ,	axis=2	)	)	)	)


       def    lowerCAmelCase   ( self	)   ->	Any:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            self.assertTrue(np.allclose(expand_dims(__SCREAMING_SNAKE_CASE     ,	axis=1	)     ,	np.expand_dims(__SCREAMING_SNAKE_CASE     ,	axis=1	)	)	)


       @require_torch
       def    lowerCAmelCase   ( self	)   ->	int:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            __snake_case            =	torch.tensor(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(expand_dims(__SCREAMING_SNAKE_CASE     ,	axis=1	)     ,	expand_dims(__SCREAMING_SNAKE_CASE     ,	axis=1	).numpy()	)	)


       @require_tf
       def    lowerCAmelCase   ( self	)   ->	int:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            __snake_case            =	tf.constant(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(expand_dims(__SCREAMING_SNAKE_CASE     ,	axis=1	)     ,	expand_dims(__SCREAMING_SNAKE_CASE     ,	axis=1	).numpy()	)	)




       @require_flax
       def    lowerCAmelCase   ( self	)   ->	List[str]:



            '''simple docstring'''




            __snake_case            =	np.random.randn(3     ,	4	)
            __snake_case            =	jnp.array(__SCREAMING_SNAKE_CASE	)
            self.assertTrue(np.allclose(expand_dims(__SCREAMING_SNAKE_CASE     ,	axis=1	)     ,	np.asarray(expand_dims(__SCREAMING_SNAKE_CASE     ,	axis=1	)	)	)	)












def lowerCamelCase__  (     _lowercase					,		_lowercase ):

     '''simple docstring'''


     while a != 0:
          UpperCAmelCase_,       UpperCAmelCase_     :				Optional[int]  =     b % a, a
     return b







def lowerCamelCase__  (     _lowercase					,		_lowercase ):

     '''simple docstring'''


     if gcd(_lowercase					,		_lowercase ) != 1:
          UpperCAmelCase_     :				int  =     f'''mod inverse of {a!r} and {m!r} does not exist'''
          raise ValueError(_lowercase )
     UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_     :				Union[str, Any]  =     1, 0, a
     UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_     :				Dict  =     0, 1, m
     while va != 0:
          UpperCAmelCase_     :				List[Any]  =     ua // va
          UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_,       UpperCAmelCase_     :				Any  =     (ua - q * va), (ua - q * va), (ua - q * va), va, va, va
     return ua % m