




"""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 				snake_case_			(					unittest.TestCase			):







   """simple docstring"""




   def   UpperCAmelCase__			(		self)				->   Union[str, Any]:
       UpperCamelCase              =	{
           '''task_specific_params''': {
               '''summarization''': {'''length_penalty''': 1.0, '''max_length''': 1_2_8, '''min_length''': 1_2, '''num_beams''': 4},
               '''summarization_cnn''': {'''length_penalty''': 2.0, '''max_length''': 1_4_2, '''min_length''': 5_6, '''num_beams''': 4},
               '''summarization_xsum''': {'''length_penalty''': 1.0, '''max_length''': 6_2, '''min_length''': 1_1, '''num_beams''': 6},
           }
       }
       UpperCamelCase              =	{
           '''task_specific_params.summarization.length_penalty''': 1.0,
           '''task_specific_params.summarization.max_length''': 1_2_8,
           '''task_specific_params.summarization.min_length''': 1_2,
           '''task_specific_params.summarization.num_beams''': 4,
           '''task_specific_params.summarization_cnn.length_penalty''': 2.0,
           '''task_specific_params.summarization_cnn.max_length''': 1_4_2,
           '''task_specific_params.summarization_cnn.min_length''': 5_6,
           '''task_specific_params.summarization_cnn.num_beams''': 4,
           '''task_specific_params.summarization_xsum.length_penalty''': 1.0,
           '''task_specific_params.summarization_xsum.max_length''': 6_2,
           '''task_specific_params.summarization_xsum.min_length''': 1_1,
           '''task_specific_params.summarization_xsum.num_beams''': 6,
       }

       self.assertEqual(flatten_dict(lowerCamelCase_)       ,					lowerCamelCase_)







   def   UpperCAmelCase__			(		self)				->   Optional[Any]:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       self.assertTrue(np.allclose(transpose(lowerCamelCase_)       ,					x.transpose()))

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







   @require_torch
   def   UpperCAmelCase__			(		self)				->   Dict:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       UpperCamelCase              =	torch.tensor(lowerCamelCase_)
       self.assertTrue(np.allclose(transpose(lowerCamelCase_)       ,					transpose(lowerCamelCase_).numpy()))

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







   @require_tf
   def   UpperCAmelCase__			(		self)				->   Any:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       UpperCamelCase              =	tf.constant(lowerCamelCase_)
       self.assertTrue(np.allclose(transpose(lowerCamelCase_)       ,					transpose(lowerCamelCase_).numpy()))

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







   @require_flax
   def   UpperCAmelCase__			(		self)				->   Dict:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       UpperCamelCase              =	jnp.array(lowerCamelCase_)
       self.assertTrue(np.allclose(transpose(lowerCamelCase_)       ,					np.asarray(transpose(lowerCamelCase_))))

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







   def   UpperCAmelCase__			(		self)				->   List[Any]:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       self.assertTrue(np.allclose(reshape(lowerCamelCase_       ,					(4, 3))       ,					np.reshape(lowerCamelCase_       ,					(4, 3))))

       UpperCamelCase              =	np.random.randn(3       ,					4       ,					5)
       self.assertTrue(np.allclose(reshape(lowerCamelCase_       ,					(1_2, 5))       ,					np.reshape(lowerCamelCase_       ,					(1_2, 5))))







   @require_torch
   def   UpperCAmelCase__			(		self)				->   List[Any]:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       UpperCamelCase              =	torch.tensor(lowerCamelCase_)
       self.assertTrue(np.allclose(reshape(lowerCamelCase_       ,					(4, 3))       ,					reshape(lowerCamelCase_       ,					(4, 3)).numpy()))

       UpperCamelCase              =	np.random.randn(3       ,					4       ,					5)
       UpperCamelCase              =	torch.tensor(lowerCamelCase_)
       self.assertTrue(np.allclose(reshape(lowerCamelCase_       ,					(1_2, 5))       ,					reshape(lowerCamelCase_       ,					(1_2, 5)).numpy()))







   @require_tf
   def   UpperCAmelCase__			(		self)				->   List[Any]:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       UpperCamelCase              =	tf.constant(lowerCamelCase_)
       self.assertTrue(np.allclose(reshape(lowerCamelCase_       ,					(4, 3))       ,					reshape(lowerCamelCase_       ,					(4, 3)).numpy()))

       UpperCamelCase              =	np.random.randn(3       ,					4       ,					5)
       UpperCamelCase              =	tf.constant(lowerCamelCase_)
       self.assertTrue(np.allclose(reshape(lowerCamelCase_       ,					(1_2, 5))       ,					reshape(lowerCamelCase_       ,					(1_2, 5)).numpy()))







   @require_flax
   def   UpperCAmelCase__			(		self)				->   Tuple:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       UpperCamelCase              =	jnp.array(lowerCamelCase_)
       self.assertTrue(np.allclose(reshape(lowerCamelCase_       ,					(4, 3))       ,					np.asarray(reshape(lowerCamelCase_       ,					(4, 3)))))

       UpperCamelCase              =	np.random.randn(3       ,					4       ,					5)
       UpperCamelCase              =	jnp.array(lowerCamelCase_)
       self.assertTrue(np.allclose(reshape(lowerCamelCase_       ,					(1_2, 5))       ,					np.asarray(reshape(lowerCamelCase_       ,					(1_2, 5)))))







   def   UpperCAmelCase__			(		self)				->   List[str]:
       UpperCamelCase              =	np.random.randn(1       ,					3       ,					4)
       self.assertTrue(np.allclose(squeeze(lowerCamelCase_)       ,					np.squeeze(lowerCamelCase_)))

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







   @require_torch
   def   UpperCAmelCase__			(		self)				->   int:
       UpperCamelCase              =	np.random.randn(1       ,					3       ,					4)
       UpperCamelCase              =	torch.tensor(lowerCamelCase_)
       self.assertTrue(np.allclose(squeeze(lowerCamelCase_)       ,					squeeze(lowerCamelCase_).numpy()))

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







   @require_tf
   def   UpperCAmelCase__			(		self)				->   List[Any]:
       UpperCamelCase              =	np.random.randn(1       ,					3       ,					4)
       UpperCamelCase              =	tf.constant(lowerCamelCase_)
       self.assertTrue(np.allclose(squeeze(lowerCamelCase_)       ,					squeeze(lowerCamelCase_).numpy()))

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







   @require_flax
   def   UpperCAmelCase__			(		self)				->   str:
       UpperCamelCase              =	np.random.randn(1       ,					3       ,					4)
       UpperCamelCase              =	jnp.array(lowerCamelCase_)
       self.assertTrue(np.allclose(squeeze(lowerCamelCase_)       ,					np.asarray(squeeze(lowerCamelCase_))))

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







   def   UpperCAmelCase__			(		self)				->   Optional[Any]:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       self.assertTrue(np.allclose(expand_dims(lowerCamelCase_       ,					axis=1)       ,					np.expand_dims(lowerCamelCase_       ,					axis=1)))







   @require_torch
   def   UpperCAmelCase__			(		self)				->   List[str]:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       UpperCamelCase              =	torch.tensor(lowerCamelCase_)
       self.assertTrue(np.allclose(expand_dims(lowerCamelCase_       ,					axis=1)       ,					expand_dims(lowerCamelCase_       ,					axis=1).numpy()))







   @require_tf
   def   UpperCAmelCase__			(		self)				->   List[Any]:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       UpperCamelCase              =	tf.constant(lowerCamelCase_)
       self.assertTrue(np.allclose(expand_dims(lowerCamelCase_       ,					axis=1)       ,					expand_dims(lowerCamelCase_       ,					axis=1).numpy()))







   @require_flax
   def   UpperCAmelCase__			(		self)				->   Tuple:
       UpperCamelCase              =	np.random.randn(3       ,					4)
       UpperCamelCase              =	jnp.array(lowerCamelCase_)
       self.assertTrue(np.allclose(expand_dims(lowerCamelCase_       ,					axis=1)       ,					np.asarray(expand_dims(lowerCamelCase_       ,					axis=1))))





'''simple docstring'''



from collections import defaultdict

from graphs.minimum_spanning_tree_prims import prisms_algorithm as mst




def   lowercase__(			):

      """simple docstring"""






      SCREAMING_SNAKE_CASE					,    SCREAMING_SNAKE_CASE   :      str    					=						9, 14  # noqa: F841
      SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						[
          [0, 1, 4],
          [0, 7, 8],
          [1, 2, 8],
          [7, 8, 7],
          [7, 6, 1],
          [2, 8, 2],
          [8, 6, 6],
          [2, 3, 7],
          [2, 5, 4],
          [6, 5, 2],
          [3, 5, 14],
          [3, 4, 9],
          [5, 4, 10],
          [1, 7, 11],
      ]

      SCREAMING_SNAKE_CASE   :      Optional[int]    					=						defaultdict(__UpperCamelCase    )
      for nodea, nodea, cost in edges:
            adjancency[nodea].append([nodea, cost]    )
            adjancency[nodea].append([nodea, cost]    )

      SCREAMING_SNAKE_CASE   :      Dict    					=						mst(__UpperCamelCase    )

      SCREAMING_SNAKE_CASE   :      Optional[int]    					=						[
          [7, 6, 1],
          [2, 8, 2],
          [6, 5, 2],
          [0, 1, 4],
          [2, 5, 4],
          [2, 3, 7],
          [0, 7, 8],
          [3, 4, 9],
      ]

      for answer in expected:
            SCREAMING_SNAKE_CASE   :      Any    					=						tuple(answer[:2]    )
            SCREAMING_SNAKE_CASE   :      List[Any]    					=						tuple(edge[::-1]    )
            assert edge in result or reverse in result


