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





   """simple docstring"""




   def   lowerCAmelCase						(	self					:  Optional[Any]							):



    """simple docstring"""



    _UpperCamelCase:     Tuple							= {
        '''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},
        }
    }
    _UpperCamelCase:     str							= {
        '''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(_lowercase							)		,  _lowercase							)



   def   lowerCAmelCase						(	self					:  Tuple							):



    """simple docstring"""



    _UpperCamelCase:     List[Any]							= np.random.randn(3		,  4							)
    self.assertTrue(np.allclose(transpose(_lowercase							)		,  x.transpose()							)							)

    _UpperCamelCase:     Union[str, Any]							= np.random.randn(3		,  4		,  5							)
    self.assertTrue(np.allclose(transpose(_lowercase		,  axes=(1, 2, 0)							)		,  x.transpose((1, 2, 0)							)							)							)



   @require_torch
   def   lowerCAmelCase						(	self					:  Any							):



    """simple docstring"""



    _UpperCamelCase:     Union[str, Any]							= np.random.randn(3		,  4							)
    _UpperCamelCase:     str							= torch.tensor(_lowercase							)
    self.assertTrue(np.allclose(transpose(_lowercase							)		,  transpose(_lowercase							).numpy()							)							)

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



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



    """simple docstring"""



    _UpperCamelCase:     int							= np.random.randn(3		,  4							)
    _UpperCamelCase:     int							= tf.constant(_lowercase							)
    self.assertTrue(np.allclose(transpose(_lowercase							)		,  transpose(_lowercase							).numpy()							)							)

    _UpperCamelCase:     Tuple							= np.random.randn(3		,  4		,  5							)
    _UpperCamelCase:     Optional[int]							= tf.constant(_lowercase							)
    self.assertTrue(np.allclose(transpose(_lowercase		,  axes=(1, 2, 0)							)		,  transpose(_lowercase		,  axes=(1, 2, 0)							).numpy()							)							)



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



    """simple docstring"""



    _UpperCamelCase:     List[Any]							= np.random.randn(3		,  4							)
    _UpperCamelCase:     Optional[int]							= jnp.array(_lowercase							)
    self.assertTrue(np.allclose(transpose(_lowercase							)		,  np.asarray(transpose(_lowercase							)							)							)							)

    _UpperCamelCase:     List[Any]							= np.random.randn(3		,  4		,  5							)
    _UpperCamelCase:     List[str]							= jnp.array(_lowercase							)
    self.assertTrue(np.allclose(transpose(_lowercase		,  axes=(1, 2, 0)							)		,  np.asarray(transpose(_lowercase		,  axes=(1, 2, 0)							)							)							)							)



   def   lowerCAmelCase						(	self					:  List[Any]							):



    """simple docstring"""



    _UpperCamelCase:     List[str]							= np.random.randn(3		,  4							)
    self.assertTrue(np.allclose(reshape(_lowercase		,  (4, 3)							)		,  np.reshape(_lowercase		,  (4, 3)							)							)							)

    _UpperCamelCase:     str							= np.random.randn(3		,  4		,  5							)
    self.assertTrue(np.allclose(reshape(_lowercase		,  (12, 5)							)		,  np.reshape(_lowercase		,  (12, 5)							)							)							)



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



    """simple docstring"""



    _UpperCamelCase:     Any							= np.random.randn(3		,  4							)
    _UpperCamelCase:     List[Any]							= torch.tensor(_lowercase							)
    self.assertTrue(np.allclose(reshape(_lowercase		,  (4, 3)							)		,  reshape(_lowercase		,  (4, 3)							).numpy()							)							)

    _UpperCamelCase:     Union[str, Any]							= np.random.randn(3		,  4		,  5							)
    _UpperCamelCase:     Tuple							= torch.tensor(_lowercase							)
    self.assertTrue(np.allclose(reshape(_lowercase		,  (12, 5)							)		,  reshape(_lowercase		,  (12, 5)							).numpy()							)							)



   @require_tf
   def   lowerCAmelCase						(	self					:  Optional[Any]							):



    """simple docstring"""



    _UpperCamelCase:     List[Any]							= np.random.randn(3		,  4							)
    _UpperCamelCase:     Any							= tf.constant(_lowercase							)
    self.assertTrue(np.allclose(reshape(_lowercase		,  (4, 3)							)		,  reshape(_lowercase		,  (4, 3)							).numpy()							)							)

    _UpperCamelCase:     Optional[Any]							= np.random.randn(3		,  4		,  5							)
    _UpperCamelCase:     List[Any]							= tf.constant(_lowercase							)
    self.assertTrue(np.allclose(reshape(_lowercase		,  (12, 5)							)		,  reshape(_lowercase		,  (12, 5)							).numpy()							)							)



   @require_flax
   def   lowerCAmelCase						(	self					:  Any							):



    """simple docstring"""



    _UpperCamelCase:     str							= np.random.randn(3		,  4							)
    _UpperCamelCase:     List[str]							= jnp.array(_lowercase							)
    self.assertTrue(np.allclose(reshape(_lowercase		,  (4, 3)							)		,  np.asarray(reshape(_lowercase		,  (4, 3)							)							)							)							)

    _UpperCamelCase:     int							= np.random.randn(3		,  4		,  5							)
    _UpperCamelCase:     int							= jnp.array(_lowercase							)
    self.assertTrue(np.allclose(reshape(_lowercase		,  (12, 5)							)		,  np.asarray(reshape(_lowercase		,  (12, 5)							)							)							)							)



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



    """simple docstring"""



    _UpperCamelCase:     Any							= np.random.randn(1		,  3		,  4							)
    self.assertTrue(np.allclose(squeeze(_lowercase							)		,  np.squeeze(_lowercase							)							)							)

    _UpperCamelCase:     List[Any]							= np.random.randn(1		,  4		,  1		,  5							)
    self.assertTrue(np.allclose(squeeze(_lowercase		,  axis=2							)		,  np.squeeze(_lowercase		,  axis=2							)							)							)



   @require_torch
   def   lowerCAmelCase						(	self					:  int							):



    """simple docstring"""



    _UpperCamelCase:     Tuple							= np.random.randn(1		,  3		,  4							)
    _UpperCamelCase:     List[str]							= torch.tensor(_lowercase							)
    self.assertTrue(np.allclose(squeeze(_lowercase							)		,  squeeze(_lowercase							).numpy()							)							)

    _UpperCamelCase:     Dict							= np.random.randn(1		,  4		,  1		,  5							)
    _UpperCamelCase:     Tuple							= torch.tensor(_lowercase							)
    self.assertTrue(np.allclose(squeeze(_lowercase		,  axis=2							)		,  squeeze(_lowercase		,  axis=2							).numpy()							)							)



   @require_tf
   def   lowerCAmelCase						(	self					:  Tuple							):



    """simple docstring"""



    _UpperCamelCase:     Any							= np.random.randn(1		,  3		,  4							)
    _UpperCamelCase:     Optional[int]							= tf.constant(_lowercase							)
    self.assertTrue(np.allclose(squeeze(_lowercase							)		,  squeeze(_lowercase							).numpy()							)							)

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



   @require_flax
   def   lowerCAmelCase						(	self					:  Union[str, Any]							):



    """simple docstring"""



    _UpperCamelCase:     Optional[Any]							= np.random.randn(1		,  3		,  4							)
    _UpperCamelCase:     int							= jnp.array(_lowercase							)
    self.assertTrue(np.allclose(squeeze(_lowercase							)		,  np.asarray(squeeze(_lowercase							)							)							)							)

    _UpperCamelCase:     Any							= np.random.randn(1		,  4		,  1		,  5							)
    _UpperCamelCase:     int							= jnp.array(_lowercase							)
    self.assertTrue(np.allclose(squeeze(_lowercase		,  axis=2							)		,  np.asarray(squeeze(_lowercase		,  axis=2							)							)							)							)



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



    """simple docstring"""



    _UpperCamelCase:     List[str]							= np.random.randn(3		,  4							)
    self.assertTrue(np.allclose(expand_dims(_lowercase		,  axis=1							)		,  np.expand_dims(_lowercase		,  axis=1							)							)							)



   @require_torch
   def   lowerCAmelCase						(	self					:  int							):



    """simple docstring"""



    _UpperCamelCase:     List[Any]							= np.random.randn(3		,  4							)
    _UpperCamelCase:     Tuple							= torch.tensor(_lowercase							)
    self.assertTrue(np.allclose(expand_dims(_lowercase		,  axis=1							)		,  expand_dims(_lowercase		,  axis=1							).numpy()							)							)



   @require_tf
   def   lowerCAmelCase						(	self					:  str							):



    """simple docstring"""



    _UpperCamelCase:     List[str]							= np.random.randn(3		,  4							)
    _UpperCamelCase:     Optional[Any]							= tf.constant(_lowercase							)
    self.assertTrue(np.allclose(expand_dims(_lowercase		,  axis=1							)		,  expand_dims(_lowercase		,  axis=1							).numpy()							)							)



   @require_flax
   def   lowerCAmelCase						(	self					:  Union[str, Any]							):



    """simple docstring"""



    _UpperCamelCase:     Tuple							= np.random.randn(3		,  4							)
    _UpperCamelCase:     Dict							= jnp.array(_lowercase							)
    self.assertTrue(np.allclose(expand_dims(_lowercase		,  axis=1							)		,  np.asarray(expand_dims(_lowercase		,  axis=1							)							)							)							)
from __future__ import annotations




def       lowerCAmelCase_     (		lowercase:							int = 4		)    ->				list[list[int]]:







 '''simple docstring'''
 _UpperCamelCase:     Dict							= abs(lowercase		) or 4
 return [[1 + x + y * row_size for x in range(lowercase		)] for y in range(lowercase		)]




def       lowerCAmelCase_     (		lowercase:							list[list[int]]		)    ->				list[list[int]]:







 '''simple docstring'''
 return reverse_row(transpose(lowercase		)		)
 # OR.. transpose(reverse_column(matrix))




def       lowerCAmelCase_     (		lowercase:							list[list[int]]		)    ->				list[list[int]]:







 '''simple docstring'''
 return reverse_row(reverse_column(lowercase		)		)
 # OR.. reverse_column(reverse_row(matrix))




def       lowerCAmelCase_     (		lowercase:							list[list[int]]		)    ->				list[list[int]]:







 '''simple docstring'''
 return reverse_column(transpose(lowercase		)		)
 # OR.. transpose(reverse_row(matrix))




def       lowerCAmelCase_     (		lowercase:							list[list[int]]		)    ->				list[list[int]]:







 '''simple docstring'''
 _UpperCamelCase:     int							= [list(lowercase		) for x in zip(*lowercase		)]
 return matrix




def       lowerCAmelCase_     (		lowercase:							list[list[int]]		)    ->				list[list[int]]:







 '''simple docstring'''
 _UpperCamelCase:     str							= matrix[::-1]
 return matrix




def       lowerCAmelCase_     (		lowercase:							list[list[int]]		)    ->				list[list[int]]:







 '''simple docstring'''
 _UpperCamelCase:     str							= [x[::-1] for x in matrix]
 return matrix




def       lowerCAmelCase_     (		lowercase:							list[list[int]]		)    ->				None:







 '''simple docstring'''
 for i in matrix:
  print(*lowercase		)


if __name__ == "__main__":
  UpperCAmelCase_			    =							make_matrix()
  print('''\norigin:\n''')
  print_matrix(matrix)
  print('''\nrotate 90 counterclockwise:\n''')
  print_matrix(rotate_aa(matrix))

  UpperCAmelCase_			    =							make_matrix()
  print('''\norigin:\n''')
  print_matrix(matrix)
  print('''\nrotate 180:\n''')
  print_matrix(rotate_aaa(matrix))

  UpperCAmelCase_			    =							make_matrix()
  print('''\norigin:\n''')
  print_matrix(matrix)
  print('''\nrotate 270 counterclockwise:\n''')
  print_matrix(rotate_aaa(matrix))