

import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

       if is_vision_available():
              from transformers import MaskFormerImageProcessor

if is_vision_available():
       from PIL import Image



class       __snake_case  :

  def __init__(					self						,		_A						,		_A=2						,		_A=True						,		_A=False						,		_A=10						,		_A=3						,		_A=32 * 4						,		_A=32 * 6						,		_A=4						,		_A=32						,		):
      SCREAMING_SNAKE_CASE_									=						parent
      SCREAMING_SNAKE_CASE_									=						batch_size
      SCREAMING_SNAKE_CASE_									=						is_training
      SCREAMING_SNAKE_CASE_									=						use_auxiliary_loss
      SCREAMING_SNAKE_CASE_									=						num_queries
      SCREAMING_SNAKE_CASE_									=						num_channels
      SCREAMING_SNAKE_CASE_									=						min_size
      SCREAMING_SNAKE_CASE_									=						max_size
      SCREAMING_SNAKE_CASE_									=						num_labels
      SCREAMING_SNAKE_CASE_									=						mask_feature_size

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]).to(
          _A)

      SCREAMING_SNAKE_CASE_									=						torch.ones([self.batch_size, self.min_size, self.max_size]						,		device=_A)

      SCREAMING_SNAKE_CASE_									=						(
          torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]						,		device=_A) > 0.5
      ).float()
      SCREAMING_SNAKE_CASE_									=						(torch.rand((self.batch_size, self.num_labels)						,		device=_A) > 0.5).long()

      SCREAMING_SNAKE_CASE_									=						self.get_config()
      return config, pixel_values, pixel_mask, mask_labels, class_labels

  def 						lowerCAmelCase__     (					self):
      return MaskFormerConfig.from_backbone_and_decoder_configs(
          backbone_config=SwinConfig(
              depths=[1, 1, 1, 1]						,		)						,		decoder_config=DetrConfig(
              decoder_ffn_dim=128						,		num_queries=self.num_queries						,		decoder_attention_heads=2						,		d_model=self.mask_feature_size						,		)						,		mask_feature_size=self.mask_feature_size						,		fpn_feature_size=self.mask_feature_size						,		num_channels=self.num_channels						,		num_labels=self.num_labels						,		)

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_									=						self.prepare_config_and_inputs()
      SCREAMING_SNAKE_CASE_									=						{'pixel_values': pixel_values, 'pixel_mask': pixel_mask}
      return config, inputs_dict

  def 						lowerCAmelCase__     (					self						,		_A						,		_A):
      SCREAMING_SNAKE_CASE_									=						output.encoder_hidden_states
      SCREAMING_SNAKE_CASE_									=						output.pixel_decoder_hidden_states
      SCREAMING_SNAKE_CASE_									=						output.transformer_decoder_hidden_states

      self.parent.assertTrue(len(_A)						,		len(config.backbone_config.depths))
      self.parent.assertTrue(len(_A)						,		len(config.backbone_config.depths))
      self.parent.assertTrue(len(_A)						,		config.decoder_config.decoder_layers)

  def 						lowerCAmelCase__     (					self						,		_A						,		_A						,		_A						,		_A=False):
      with torch.no_grad():
          SCREAMING_SNAKE_CASE_									=						MaskFormerModel(config=_A)
          model.to(_A)
          model.eval()

          SCREAMING_SNAKE_CASE_									=						model(pixel_values=_A						,		pixel_mask=_A)
          SCREAMING_SNAKE_CASE_									=						model(_A						,		output_hidden_states=_A)
      # the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
      # encoder and pixel decoder
      self.parent.assertEqual(
          output.transformer_decoder_last_hidden_state.shape						,		(self.batch_size, self.num_queries, self.mask_feature_size)						,		)
      # let's ensure the other two hidden state exists
      self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None)
      self.parent.assertTrue(output.encoder_last_hidden_state is not None)

      if output_hidden_states:
          self.check_output_hidden_state(_A						,		_A)


  def 						lowerCAmelCase__     (					self						,		_A						,		_A						,		_A						,		_A						,		_A):
      SCREAMING_SNAKE_CASE_									=						MaskFormerForInstanceSegmentation(config=_A)
      model.to(_A)
      model.eval()

      def comm_check_on_output(_A):
          # let's still check that all the required stuff is there
          self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None)
          self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None)
          self.parent.assertTrue(result.encoder_last_hidden_state is not None)
          # okay, now we need to check the logits shape
          # due to the encoder compression, masks have a //4 spatial size
          self.parent.assertEqual(
              result.masks_queries_logits.shape						,		(self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)						,		)
          # + 1 for null class
          self.parent.assertEqual(
              result.class_queries_logits.shape						,		(self.batch_size, self.num_queries, self.num_labels + 1))

      with torch.no_grad():
          SCREAMING_SNAKE_CASE_									=						model(pixel_values=_A						,		pixel_mask=_A)
          SCREAMING_SNAKE_CASE_									=						model(_A)

          comm_check_on_output(_A)

          SCREAMING_SNAKE_CASE_									=						model(
              pixel_values=_A						,		pixel_mask=_A						,		mask_labels=_A						,		class_labels=_A)

      comm_check_on_output(_A)

      self.parent.assertTrue(result.loss is not None)
      self.parent.assertEqual(result.loss.shape						,		torch.Size([1]))






@require_torch
class       __snake_case  (    lowerCAmelCase__     , lowerCAmelCase__     , unittest.TestCase       ):
  __lowerCAmelCase     :	List[str]						 =  (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
  __lowerCAmelCase     :	str						 =  (
      {'feature-extraction': MaskFormerModel, 'image-segmentation': MaskFormerForInstanceSegmentation}
      if is_torch_available()
      else {}
  )

  __lowerCAmelCase     :	Optional[Any]						 =  False
  __lowerCAmelCase     :	Optional[Any]						 =  False
  __lowerCAmelCase     :	Dict						 =  False
  __lowerCAmelCase     :	Tuple						 =  False

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						MaskFormerModelTester(self)
      SCREAMING_SNAKE_CASE_									=						ConfigTester(self						,		config_class=_A						,		has_text_modality=_A)

  def 						lowerCAmelCase__     (					self):
      self.config_tester.run_common_tests()

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_									=						self.model_tester.prepare_config_and_inputs_for_common()
      self.model_tester.create_and_check_maskformer_model(_A						,		**_A						,		output_hidden_states=_A)

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_maskformer_instance_segmentation_head_model(*_A)

  @unittest.skip(reason='MaskFormer does not use inputs_embeds')
  def 						lowerCAmelCase__     (					self):
      pass

  @unittest.skip(reason='MaskFormer does not have a get_input_embeddings method')
  def 						lowerCAmelCase__     (					self):
      pass

  @unittest.skip(reason='MaskFormer is not a generative model')
  def 						lowerCAmelCase__     (					self):
      pass

  @unittest.skip(reason='MaskFormer does not use token embeddings')
  def 						lowerCAmelCase__     (					self):
      pass

  @require_torch_multi_gpu
  @unittest.skip(
      reason='MaskFormer has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`')
  def 						lowerCAmelCase__     (					self):
      pass

  @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.')
  def 						lowerCAmelCase__     (					self):
      pass

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_									=						self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
          SCREAMING_SNAKE_CASE_									=						model_class(_A)
          SCREAMING_SNAKE_CASE_									=						inspect.signature(model.forward)
          # signature.parameters is an OrderedDict => so arg_names order is deterministic
          SCREAMING_SNAKE_CASE_									=						[*signature.parameters.keys()]

          SCREAMING_SNAKE_CASE_									=						['pixel_values']
          self.assertListEqual(arg_names[:1]						,		_A)

  @slow
  def 						lowerCAmelCase__     (					self):
      for model_name in ["facebook/maskformer-swin-small-coco"]:
          SCREAMING_SNAKE_CASE_									=						MaskFormerModel.from_pretrained(_A)
          self.assertIsNotNone(_A)

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						(self.model_tester.min_size,) * 2
      SCREAMING_SNAKE_CASE_									=						{
          'pixel_values': torch.randn((2, 3, *size)						,		device=_A),
          'mask_labels': torch.randn((2, 10, *size)						,		device=_A),
          'class_labels': torch.zeros(2						,		10						,		device=_A).long(),
      }

      SCREAMING_SNAKE_CASE_									=						MaskFormerForInstanceSegmentation(MaskFormerConfig()).to(_A)
      SCREAMING_SNAKE_CASE_									=						model(**_A)
      self.assertTrue(outputs.loss is not None)

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_									=						self.model_tester.prepare_config_and_inputs_for_common()
      self.model_tester.create_and_check_maskformer_model(_A						,		**_A						,		output_hidden_states=_A)

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_									=						self.model_tester.prepare_config_and_inputs_for_common()

      for model_class in self.all_model_classes:
          SCREAMING_SNAKE_CASE_									=						model_class(_A).to(_A)
          SCREAMING_SNAKE_CASE_									=						model(**_A						,		output_attentions=_A)
          self.assertTrue(outputs.attentions is not None)

  def 						lowerCAmelCase__     (					self):
      if not self.model_tester.is_training:
          return
      # only MaskFormerForInstanceSegmentation has the loss
      SCREAMING_SNAKE_CASE_									=						self.all_model_classes[1]
      SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_									=						self.model_tester.prepare_config_and_inputs()

      SCREAMING_SNAKE_CASE_									=						model_class(_A)
      model.to(_A)
      model.train()

      SCREAMING_SNAKE_CASE_									=						model(_A						,		mask_labels=_A						,		class_labels=_A).loss
      loss.backward()


  def 						lowerCAmelCase__     (					self):
      # only MaskFormerForInstanceSegmentation has the loss
      SCREAMING_SNAKE_CASE_									=						self.all_model_classes[1]
      SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_							,			SCREAMING_SNAKE_CASE_									=						self.model_tester.prepare_config_and_inputs()
      SCREAMING_SNAKE_CASE_									=						True
      SCREAMING_SNAKE_CASE_									=						True

      SCREAMING_SNAKE_CASE_									=						model_class(_A)
      model.to(_A)
      model.train()

      SCREAMING_SNAKE_CASE_									=						model(_A						,		mask_labels=_A						,		class_labels=_A)

      SCREAMING_SNAKE_CASE_									=						outputs.encoder_hidden_states[0]
      encoder_hidden_states.retain_grad()

      SCREAMING_SNAKE_CASE_									=						outputs.pixel_decoder_hidden_states[0]
      pixel_decoder_hidden_states.retain_grad()
      # we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
      SCREAMING_SNAKE_CASE_									=						outputs.transformer_decoder_hidden_states[0]
      transformer_decoder_hidden_states.retain_grad()

      SCREAMING_SNAKE_CASE_									=						outputs.attentions[0]
      attentions.retain_grad()

      outputs.loss.backward(retain_graph=_A)

      self.assertIsNotNone(encoder_hidden_states.grad)
      self.assertIsNotNone(pixel_decoder_hidden_states.grad)
      self.assertIsNotNone(transformer_decoder_hidden_states.grad)
      self.assertIsNotNone(attentions.grad)






UpperCamelCase__  :      Any			=    1E-4


def 					_UpperCAmelCase       (  ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'       )
    return image





@require_vision
@slow
class       __snake_case  (    unittest.TestCase       ):

  @cached_property
  def 						lowerCAmelCase__     (					self):
      return (
          MaskFormerImageProcessor.from_pretrained('facebook/maskformer-swin-small-coco')
          if is_vision_available()
          else None
      )

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						MaskFormerModel.from_pretrained('facebook/maskformer-swin-small-coco').to(_A)
      SCREAMING_SNAKE_CASE_									=						self.default_image_processor
      SCREAMING_SNAKE_CASE_									=						prepare_img()
      SCREAMING_SNAKE_CASE_									=						image_processor(_A						,		return_tensors='pt').to(_A)
      SCREAMING_SNAKE_CASE_									=						inputs['pixel_values'].shape
      # check size is divisible by 32
      self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0)
      # check size
      self.assertEqual(_A						,		(1, 3, 800, 1088))

      with torch.no_grad():
          SCREAMING_SNAKE_CASE_									=						model(**_A)

      SCREAMING_SNAKE_CASE_									=						torch.tensor(
          [[-0.0_4_8_2, 0.9_2_2_8, 0.4_9_5_1], [-0.2_5_4_7, 0.8_0_1_7, 0.8_5_2_7], [-0.0_0_6_9, 0.3_3_8_5, -0.0_0_8_9]]).to(_A)
      self.assertTrue(
          torch.allclose(
              outputs.encoder_last_hidden_state[0, 0, :3, :3]						,		_A						,		atol=_A))

      SCREAMING_SNAKE_CASE_									=						torch.tensor(
          [[-0.8_4_2_2, -0.8_4_3_4, -0.9_7_1_8], [-1.0_1_4_4, -0.5_5_6_5, -0.4_1_9_5], [-1.0_0_3_8, -0.4_4_8_4, -0.1_9_6_1]]).to(_A)
      self.assertTrue(
          torch.allclose(
              outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]						,		_A						,		atol=_A))

      SCREAMING_SNAKE_CASE_									=						torch.tensor(
          [[0.2_8_5_2, -0.0_1_5_9, 0.9_7_3_5], [0.6_2_5_4, 0.1_8_5_8, 0.8_5_2_9], [-0.0_6_8_0, -0.4_1_1_6, 1.8_4_1_3]]).to(_A)
      self.assertTrue(
          torch.allclose(
              outputs.transformer_decoder_last_hidden_state[0, :3, :3]						,		_A						,		atol=_A))

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						(
          MaskFormerForInstanceSegmentation.from_pretrained('facebook/maskformer-swin-small-coco')
          .to(_A)
          .eval()
      )
      SCREAMING_SNAKE_CASE_									=						self.default_image_processor
      SCREAMING_SNAKE_CASE_									=						prepare_img()
      SCREAMING_SNAKE_CASE_									=						image_processor(_A						,		return_tensors='pt').to(_A)
      SCREAMING_SNAKE_CASE_									=						inputs['pixel_values'].shape
      # check size is divisible by 32
      self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0)
      # check size
      self.assertEqual(_A						,		(1, 3, 800, 1088))

      with torch.no_grad():
          SCREAMING_SNAKE_CASE_									=						model(**_A)
      # masks_queries_logits
      SCREAMING_SNAKE_CASE_									=						outputs.masks_queries_logits
      self.assertEqual(
          masks_queries_logits.shape						,		(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)						,		)
      SCREAMING_SNAKE_CASE_									=						[
          [-1.3_7_3_7_1_2_4, -1.7_7_2_4_9_3_7, -1.9_3_6_4_2_3_3],
          [-1.5_9_7_7_2_8_1, -1.9_8_6_7_9_3_9, -2.1_5_2_3_6_9_5],
          [-1.5_7_9_5_3_9_8, -1.9_2_6_9_8_3_2, -2.0_9_3_9_4_2],
      ]
      SCREAMING_SNAKE_CASE_									=						torch.tensor(_A).to(_A)
      self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]						,		_A						,		atol=_A))
      # class_queries_logits
      SCREAMING_SNAKE_CASE_									=						outputs.class_queries_logits
      self.assertEqual(
          class_queries_logits.shape						,		(1, model.config.decoder_config.num_queries, model.config.num_labels + 1))
      SCREAMING_SNAKE_CASE_									=						torch.tensor(
          [
              [1.6_512E00, -5.2_572E00, -3.3_519E00],
              [3.6_169E-02, -5.9_025E00, -2.9_313E00],
              [1.0_766E-04, -7.7_630E00, -5.1_263E00],
          ]).to(_A)
      self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]						,		_A						,		atol=_A))

  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						(
          MaskFormerForInstanceSegmentation.from_pretrained('facebook/maskformer-resnet101-coco-stuff')
          .to(_A)
          .eval()
      )
      SCREAMING_SNAKE_CASE_									=						self.default_image_processor
      SCREAMING_SNAKE_CASE_									=						prepare_img()
      SCREAMING_SNAKE_CASE_									=						image_processor(_A						,		return_tensors='pt').to(_A)
      SCREAMING_SNAKE_CASE_									=						inputs['pixel_values'].shape
      # check size is divisible by 32
      self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0)
      # check size
      self.assertEqual(_A						,		(1, 3, 800, 1088))

      with torch.no_grad():
          SCREAMING_SNAKE_CASE_									=						model(**_A)
      # masks_queries_logits
      SCREAMING_SNAKE_CASE_									=						outputs.masks_queries_logits
      self.assertEqual(
          masks_queries_logits.shape						,		(1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)						,		)
      SCREAMING_SNAKE_CASE_									=						[[-0.9_0_4_6, -2.6_3_6_6, -4.6_0_6_2], [-3.4_1_7_9, -5.7_8_9_0, -8.8_0_5_7], [-4.9_1_7_9, -7.6_5_6_0, -1_0.7_7_1_1]]
      SCREAMING_SNAKE_CASE_									=						torch.tensor(_A).to(_A)
      self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]						,		_A						,		atol=_A))
      # class_queries_logits
      SCREAMING_SNAKE_CASE_									=						outputs.class_queries_logits
      self.assertEqual(
          class_queries_logits.shape						,		(1, model.config.decoder_config.num_queries, model.config.num_labels + 1))
      SCREAMING_SNAKE_CASE_									=						torch.tensor(
          [[4.7_1_8_8, -3.2_5_8_5, -2.8_8_5_7], [6.6_8_7_1, -2.9_1_8_1, -1.2_4_8_7], [7.2_4_4_9, -2.2_7_6_4, -2.1_8_7_4]]).to(_A)
      self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]						,		_A						,		atol=_A))


  def 						lowerCAmelCase__     (					self):
      SCREAMING_SNAKE_CASE_									=						(
          MaskFormerForInstanceSegmentation.from_pretrained('facebook/maskformer-swin-small-coco')
          .to(_A)
          .eval()
      )
      SCREAMING_SNAKE_CASE_									=						self.default_image_processor

      SCREAMING_SNAKE_CASE_									=						image_processor(
          [np.zeros((3, 800, 1333)), np.zeros((3, 800, 1333))]						,		segmentation_maps=[np.zeros((384, 384)).astype(np.floataa), np.zeros((384, 384)).astype(np.floataa)]						,		return_tensors='pt'						,		)

      SCREAMING_SNAKE_CASE_									=						inputs['pixel_values'].to(_A)
      SCREAMING_SNAKE_CASE_									=						[el.to(_A) for el in inputs['mask_labels']]
      SCREAMING_SNAKE_CASE_									=						[el.to(_A) for el in inputs['class_labels']]

      with torch.no_grad():
          SCREAMING_SNAKE_CASE_									=						model(**_A)

      self.assertTrue(outputs.loss is not None)





from multiprocessing import Lock, Pipe, Process

# lock used to ensure that two processes do not access a pipe at the same time
UpperCamelCase__  :      int			=    Lock()


def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		str ,   _SCREAMING_SNAKE_CASE					:		Union[str, Any] ,   _SCREAMING_SNAKE_CASE					:		Dict ,   _SCREAMING_SNAKE_CASE					:		List[Any] ,   _SCREAMING_SNAKE_CASE					:		Optional[int] ,   _SCREAMING_SNAKE_CASE					:		Optional[int] ,   _SCREAMING_SNAKE_CASE					:		Any       ):





    """simple docstring"""


    global process_lock

    # we perform n swaps since after n swaps we know we are sorted
    # we *could* stop early if we are sorted already, but it takes as long to
    # find out we are sorted as it does to sort the list with this algorithm
    for i in range(0 ,   10       ):
        if (i + position) % 2 == 0 and r_send is not None:
            # send your value to your right neighbor
            process_lock.acquire()
            r_send[1].send(_SCREAMING_SNAKE_CASE       )
            process_lock.release()

            # receive your right neighbor's value
            process_lock.acquire()
            SCREAMING_SNAKE_CASE_									=						rr_cv[0].recv()
            process_lock.release()

            # take the lower value since you are on the left
            SCREAMING_SNAKE_CASE_									=						min(_SCREAMING_SNAKE_CASE ,   _SCREAMING_SNAKE_CASE       )
        elif (i + position) % 2 != 0 and l_send is not None:
            # send your value to your left neighbor
            process_lock.acquire()
            l_send[1].send(_SCREAMING_SNAKE_CASE       )
            process_lock.release()

            # receive your left neighbor's value
            process_lock.acquire()
            SCREAMING_SNAKE_CASE_									=						lr_cv[0].recv()
            process_lock.release()

            # take the higher value since you are on the right
            SCREAMING_SNAKE_CASE_									=						max(_SCREAMING_SNAKE_CASE ,   _SCREAMING_SNAKE_CASE       )
    # after all swaps are performed, send the values back to main
    result_pipe[1].send(_SCREAMING_SNAKE_CASE       )


def 					_UpperCAmelCase       (  _SCREAMING_SNAKE_CASE					:		Union[str, Any]       ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						[]
    SCREAMING_SNAKE_CASE_									=						[]
    # initialize the list of pipes where the values will be retrieved
    for _ in arr:
        result_pipe.append(Pipe()       )
    # creates the processes
    # the first and last process only have one neighbor so they are made outside
    # of the loop
    SCREAMING_SNAKE_CASE_									=						Pipe()
    SCREAMING_SNAKE_CASE_									=						Pipe()
    process_array_.append(
        Process(
            target=_SCREAMING_SNAKE_CASE ,   args=(0, arr[0], None, temp_rs, None, temp_rr, result_pipe[0]) ,   )       )
    SCREAMING_SNAKE_CASE_									=						temp_rs
    SCREAMING_SNAKE_CASE_									=						temp_rr

    for i in range(1 ,   len(_SCREAMING_SNAKE_CASE       ) - 1       ):
        SCREAMING_SNAKE_CASE_									=						Pipe()
        SCREAMING_SNAKE_CASE_									=						Pipe()
        process_array_.append(
            Process(
                target=_SCREAMING_SNAKE_CASE ,   args=(i, arr[i], temp_ls, temp_rs, temp_lr, temp_rr, result_pipe[i]) ,   )       )
        SCREAMING_SNAKE_CASE_									=						temp_rs
        SCREAMING_SNAKE_CASE_									=						temp_rr

    process_array_.append(
        Process(
            target=_SCREAMING_SNAKE_CASE ,   args=(
                len(_SCREAMING_SNAKE_CASE       ) - 1,
                arr[len(_SCREAMING_SNAKE_CASE       ) - 1],
                temp_ls,
                None,
                temp_lr,
                None,
                result_pipe[len(_SCREAMING_SNAKE_CASE       ) - 1],
            ) ,   )       )

    # start the processes
    for p in process_array_:
        p.start()

    # wait for the processes to end and write their values to the list
    for p in range(0 ,   len(_SCREAMING_SNAKE_CASE       )       ):
        SCREAMING_SNAKE_CASE_									=						result_pipe[p][0].recv()
        process_array_[p].join()
    return arr


def 					_UpperCAmelCase       (  ):





    """simple docstring"""


    SCREAMING_SNAKE_CASE_									=						list(range(10 ,   0 ,   -1       )       )
    print('Initial List'       )
    print(*_SCREAMING_SNAKE_CASE       )
    SCREAMING_SNAKE_CASE_									=						odd_even_transposition(_SCREAMING_SNAKE_CASE       )
    print('Sorted List\n'       )
    print(*_SCREAMING_SNAKE_CASE       )


if __name__ == "__main__":
       main()


