





import random
import unittest

import numpy as np

import transformers
from transformers import is_flax_available, is_torch_available
from transformers.testing_utils import is_pt_flax_cross_test, require_flax


if is_flax_available():
		import os

		import jax.numpy as jnp
		from jax import jit

		from transformers import AutoTokenizer, FlaxAutoModelForCausalLM
		from transformers.modeling_flax_pytorch_utils import load_flax_weights_in_pytorch_model

		_lowerCamelCase :    List[str]  							= '''0.12'''  # assumed parallelism: 8


if is_torch_available():
		import torch




def _a (  SCREAMING_SNAKE_CASE__      :  Any			,				SCREAMING_SNAKE_CASE__      :  str			,				SCREAMING_SNAKE_CASE__      :  int=None       )	->    str:

							'''simple docstring'''






							if rng is None:
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						random.Random()

							SCREAMING_SNAKE_CASE__       :      List[str]     =						1
							for dim in shape:
														total_dims *= dim

							SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						[]
							for _ in range(SCREAMING_SNAKE_CASE__       ):
														values.append(rng.randint(0			,				vocab_size - 1       )       )

							SCREAMING_SNAKE_CASE__       :      Optional[int]     =						np.array(SCREAMING_SNAKE_CASE__			,				dtype=jnp.intaa       ).reshape(SCREAMING_SNAKE_CASE__       )

							return output




def _a (  SCREAMING_SNAKE_CASE__      :  Union[str, Any]			,				SCREAMING_SNAKE_CASE__      :  str=None       )	->    Dict:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__       :      str     =						ids_tensor(SCREAMING_SNAKE_CASE__			,				vocab_size=2			,				rng=SCREAMING_SNAKE_CASE__       )
							# make sure that at least one token is attended to for each batch
							SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						1
							return attn_mask


@require_flax
class 						lowerCamelCase       :







							"""simple docstring"""




							UpperCAmelCase_      						=   None
							UpperCAmelCase_      						=   ()






							def  A_     ( self     :					str						)				->			Optional[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self.model_tester.prepare_config_and_inputs_for_common()

														# cut to half length & take max batch_size 3
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						2
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						inputs["input_ids"].shape[-1] // 2
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						inputs["input_ids"][:max_batch_size, :sequence_length]

														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						jnp.ones_like(_UpperCAmelCase						)
														SCREAMING_SNAKE_CASE__       :      Any     =						attention_mask[:max_batch_size, :sequence_length]

														# generate max 5 tokens
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						input_ids.shape[-1] + 5
														if config.eos_token_id is not None and config.pad_token_id is None:
																					# hack to allow generate for models such as GPT2 as is done in `generate()`
																					SCREAMING_SNAKE_CASE__       :      str     =						config.eos_token_id
														return config, input_ids, attention_mask, max_length






							@is_pt_flax_cross_test
							def  A_     ( self     :					Dict						)				->			Optional[int]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self._get_input_ids_and_config()
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						False
														SCREAMING_SNAKE_CASE__       :      Any     =						max_length
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						0

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Any     =						model_class.__name__[4:]  # Skip the "Flax" at the beginning
																					SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						getattr(_UpperCAmelCase,			_UpperCAmelCase						)
																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						pt_model_class(_UpperCAmelCase						).eval()
																					SCREAMING_SNAKE_CASE__       :      Tuple     =						load_flax_weights_in_pytorch_model(_UpperCAmelCase,			flax_model.params						)

																					SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						flax_model.generate(_UpperCAmelCase						).sequences
																					SCREAMING_SNAKE_CASE__       :      List[str]     =						pt_model.generate(torch.tensor(_UpperCAmelCase,			dtype=torch.long						)						)

																					if flax_generation_outputs.shape[-1] > pt_generation_outputs.shape[-1]:
																												SCREAMING_SNAKE_CASE__       :      Dict     =						flax_generation_outputs[:, : pt_generation_outputs.shape[-1]]

																					self.assertListEqual(pt_generation_outputs.numpy().tolist(),			flax_generation_outputs.tolist()						)






							def  A_     ( self     :					Tuple						)				->			Tuple:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self._get_input_ids_and_config()
														SCREAMING_SNAKE_CASE__       :      Tuple     =						False
														SCREAMING_SNAKE_CASE__       :      Dict     =						max_length

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      str     =						model.generate(_UpperCAmelCase						).sequences
																					self.assertEqual(generation_outputs.shape[-1],			_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Any     =						jit(model.generate						)
																					SCREAMING_SNAKE_CASE__       :      Tuple     =						jit_generate(_UpperCAmelCase						).sequences

																					self.assertListEqual(generation_outputs.tolist(),			jit_generation_outputs.tolist()						)






							def  A_     ( self     :					List[str]						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      str     =						self._get_input_ids_and_config()
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						True
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						max_length

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      List[str]     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						model.generate(_UpperCAmelCase						).sequences
																					self.assertEqual(generation_outputs.shape[-1],			_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      List[str]     =						jit(model.generate						)
																					SCREAMING_SNAKE_CASE__       :      Dict     =						jit_generate(_UpperCAmelCase						).sequences

																					self.assertListEqual(generation_outputs.tolist(),			jit_generation_outputs.tolist()						)






							def  A_     ( self     :					Tuple						)				->			List[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						self._get_input_ids_and_config()
														SCREAMING_SNAKE_CASE__       :      Any     =						False
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						max_length
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						2

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						model.generate(_UpperCAmelCase						).sequences
																					self.assertEqual(generation_outputs.shape[-1],			_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						jit(model.generate						)
																					SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						jit_generate(_UpperCAmelCase						).sequences

																					self.assertListEqual(generation_outputs.tolist(),			jit_generation_outputs.tolist()						)






							def  A_     ( self     :					List[str]						)				->			Optional[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self._get_input_ids_and_config()
														SCREAMING_SNAKE_CASE__       :      Any     =						False
														SCREAMING_SNAKE_CASE__       :      List[str]     =						max_length
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						2
														SCREAMING_SNAKE_CASE__       :      Any     =						2

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						model.generate(_UpperCAmelCase						).sequences
																					self.assertEqual(generation_outputs.shape[0],			input_ids.shape[0] * config.num_return_sequences						)






							def  A_     ( self     :					int						)				->			int:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      str     =						self._get_input_ids_and_config()
														SCREAMING_SNAKE_CASE__       :      int     =						True
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						max_length
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						0.8
														SCREAMING_SNAKE_CASE__       :      Tuple     =						1_0
														SCREAMING_SNAKE_CASE__       :      Dict     =						0.3
														SCREAMING_SNAKE_CASE__       :      Any     =						1
														SCREAMING_SNAKE_CASE__       :      int     =						8
														SCREAMING_SNAKE_CASE__       :      Dict     =						9

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      Dict     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      int     =						model.generate(_UpperCAmelCase						).sequences
																					self.assertEqual(generation_outputs.shape[-1],			_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						jit(model.generate						)
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						jit_generate(_UpperCAmelCase						).sequences

																					self.assertListEqual(generation_outputs.tolist(),			jit_generation_outputs.tolist()						)






							def  A_     ( self     :					str						)				->			int:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Optional[int]     =						self._get_input_ids_and_config()
														SCREAMING_SNAKE_CASE__       :      str     =						max_length
														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						1
														SCREAMING_SNAKE_CASE__       :      Dict     =						8
														SCREAMING_SNAKE_CASE__       :      str     =						9

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Tuple     =						model.generate(_UpperCAmelCase						).sequences
																					self.assertEqual(generation_outputs.shape[-1],			_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						jit(model.generate						)
																					SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						jit_generate(_UpperCAmelCase						).sequences

																					self.assertListEqual(generation_outputs.tolist(),			jit_generation_outputs.tolist()						)






							def  A_     ( self     :					Union[str, Any]						)				->			Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						self._get_input_ids_and_config()
														SCREAMING_SNAKE_CASE__       :      Tuple     =						max_length
														SCREAMING_SNAKE_CASE__       :      List[str]     =						2
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						1
														SCREAMING_SNAKE_CASE__       :      List[str]     =						8
														SCREAMING_SNAKE_CASE__       :      str     =						9

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      str     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Dict     =						model.generate(_UpperCAmelCase						).sequences
																					self.assertEqual(generation_outputs.shape[-1],			_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      List[Any]     =						jit(model.generate						)
																					SCREAMING_SNAKE_CASE__       :      Tuple     =						jit_generate(_UpperCAmelCase						).sequences

																					self.assertListEqual(generation_outputs.tolist(),			jit_generation_outputs.tolist()						)






							def  A_     ( self     :					Tuple						)				->			Any:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      int     =						self._get_input_ids_and_config()

														# pad attention mask on the left
														SCREAMING_SNAKE_CASE__       :      Tuple     =						attention_mask.at[(0, 0)].set(0						)

														SCREAMING_SNAKE_CASE__       :      Tuple     =						False
														SCREAMING_SNAKE_CASE__       :      Any     =						max_length

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      int     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      int     =						model.generate(_UpperCAmelCase,			attention_mask=_UpperCAmelCase						).sequences
																					self.assertEqual(generation_outputs.shape[-1],			_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      str     =						jit(model.generate						)
																					SCREAMING_SNAKE_CASE__       :      int     =						jit_generate(_UpperCAmelCase,			attention_mask=_UpperCAmelCase						).sequences

																					self.assertListEqual(generation_outputs.tolist(),			jit_generation_outputs.tolist()						)






							def  A_     ( self     :					Dict						)				->			Union[str, Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      List[str]     =						self._get_input_ids_and_config()

														# pad attention mask on the left
														SCREAMING_SNAKE_CASE__       :      Dict     =						attention_mask.at[(0, 0)].set(0						)

														SCREAMING_SNAKE_CASE__       :      List[Any]     =						True
														SCREAMING_SNAKE_CASE__       :      List[Any]     =						max_length

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      List[str]     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						model.generate(_UpperCAmelCase,			attention_mask=_UpperCAmelCase						).sequences
																					self.assertEqual(generation_outputs.shape[-1],			_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						jit(model.generate						)
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						jit_generate(_UpperCAmelCase,			attention_mask=_UpperCAmelCase						).sequences

																					self.assertListEqual(generation_outputs.tolist(),			jit_generation_outputs.tolist()						)






							def  A_     ( self     :					Any						)				->			List[Any]:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      List[Any]     =						self._get_input_ids_and_config()

														# pad attention mask on the left
														SCREAMING_SNAKE_CASE__       :      Tuple     =						attention_mask.at[(0, 0)].set(0						)

														SCREAMING_SNAKE_CASE__       :      List[Any]     =						2
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						max_length

														for model_class in self.all_generative_model_classes:
																					SCREAMING_SNAKE_CASE__       :      Optional[int]     =						model_class(_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      Tuple     =						model.generate(_UpperCAmelCase,			attention_mask=_UpperCAmelCase						).sequences
																					self.assertEqual(generation_outputs.shape[-1],			_UpperCAmelCase						)

																					SCREAMING_SNAKE_CASE__       :      str     =						jit(model.generate						)
																					SCREAMING_SNAKE_CASE__       :      Any     =						jit_generate(_UpperCAmelCase,			attention_mask=_UpperCAmelCase						).sequences

																					self.assertListEqual(generation_outputs.tolist(),			jit_generation_outputs.tolist()						)


@require_flax
class 						lowerCamelCase       (unittest.TestCase      ):







							"""simple docstring"""




							def  A_     ( self     :					Dict						)				->			int:





														"""simple docstring"""
														SCREAMING_SNAKE_CASE__       :      Optional[Any]     =						AutoTokenizer.from_pretrained("hf-internal-testing/tiny-bert"						)
														SCREAMING_SNAKE_CASE__       :      Optional[int]     =						FlaxAutoModelForCausalLM.from_pretrained("hf-internal-testing/tiny-bert-flax-only"						)

														SCREAMING_SNAKE_CASE__       :      Union[str, Any]     =						"Hello world"
														SCREAMING_SNAKE_CASE__       :      Dict     =						tokenizer(_UpperCAmelCase,			return_tensors="np"						).input_ids

														# typos are quickly detected (the correct argument is `do_sample`)
														with self.assertRaisesRegex(_UpperCAmelCase,			"do_samples"						):
																					model.generate(_UpperCAmelCase,			do_samples=_UpperCAmelCase						)

														# arbitrary arguments that will not be used anywhere are also not accepted
														with self.assertRaisesRegex(_UpperCAmelCase,			"foo"						):
																					SCREAMING_SNAKE_CASE__       :      int     =						{"foo": "bar"}
																					model.generate(_UpperCAmelCase,			**_UpperCAmelCase						)













from __future__ import annotations




def _a (  SCREAMING_SNAKE_CASE__      :  list[float]			,				SCREAMING_SNAKE_CASE__      :  list[float]       )	->    float:

							'''simple docstring'''






							SCREAMING_SNAKE_CASE__       :      List[Any]     =						sorted(numsa + numsa       )
							SCREAMING_SNAKE_CASE__   ,SCREAMING_SNAKE_CASE__       :      Dict     =						divmod(len(SCREAMING_SNAKE_CASE__       )			,				2       )
							if mod == 1:
														return all_numbers[div]
							else:
														return (all_numbers[div] + all_numbers[div - 1]) / 2


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		_lowerCamelCase :    List[str]  							= [float(x) for x in input('''Enter the elements of first array: ''').split()]
		_lowerCamelCase :    Any  							= [float(x) for x in input('''Enter the elements of second array: ''').split()]
		print(f"The median of two arrays is: {median_of_two_arrays(array_a, array_a)}")






