import inspect

import jax
import jax.lax as lax
import jax.numpy as jnp

from ..utils import add_start_docstrings
from ..utils.logging import get_logger


__lowerCAmelCase					: Optional[Any]        =get_logger(__name__)


__lowerCAmelCase					: Tuple        =R"""
    Args:
        input_ids (`jnp.ndarray` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`PreTrainedTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        scores (`jnp.ndarray` of shape `(batch_size, config.vocab_size)`):
            Prediction scores of a language modeling head. These can be logits for each vocabulary when not using beam
            search or log softmax for each vocabulary token when using beam search
        kwargs (`Dict[str, Any]`, *optional*):
            Additional logits processor specific kwargs.

    Return:
        `jnp.ndarray` of shape `(batch_size, config.vocab_size)`: The processed prediction scores.

"""





class 				_A		:

      @add_start_docstrings(lowercase_		)
      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            raise NotImplementedError(
                f'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'		)






class 				_A		:

      @add_start_docstrings(lowercase_		)
      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            raise NotImplementedError(
                f'{self.__class__} is an abstract class. Only classes inheriting this class can be called.'		)






class 				_A		( lowerCAmelCase			):

      @add_start_docstrings(lowercase_		)
      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase	, **__lowerCAmelCase		):







            """simple docstring"""



            for processor in self:
                  lowercase														=			inspect.signature(processor.__call__		).parameters
                  if len(lowercase_		) > 3:
                        if not all(arg in kwargs for arg in list(function_args.keys()		)[2:]		):
                              raise ValueError(
                                  f'Make sure that all the required parameters: {list(function_args.keys()		)} for '
                                  f'{processor.__class__} are passed to the logits processor.'		)
                        lowercase														=			processor(lowercase_	, lowercase_	, lowercase_	, **lowercase_		)
                  else:
                        lowercase														=			processor(lowercase_	, lowercase_	, lowercase_		)
            return scores






class 				_A		( lowerCAmelCase			):

      def __init__(		self	, __lowerCAmelCase		):







            """simple docstring"""



            if not isinstance(lowercase_	, lowercase_		) or not (temperature > 0):
                  raise ValueError(f'`temperature` has to be a strictly positive float, but is {temperature}'		)

            lowercase														=			temperature







      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			scores / self.temperature
            return scores






class 				_A		( lowerCAmelCase			):

      def __init__(		self	, __lowerCAmelCase	, __lowerCAmelCase = -float("""Inf"""		)	, __lowerCAmelCase = 1		):







            """simple docstring"""



            if not isinstance(lowercase_	, lowercase_		) or (top_p < 0 or top_p > 1.0):
                  raise ValueError(f'`top_p` has to be a float > 0 and < 1, but is {top_p}'		)
            if not isinstance(lowercase_	, lowercase_		) or (min_tokens_to_keep < 1):
                  raise ValueError(f'`min_tokens_to_keep` has to be a positive integer, but is {min_tokens_to_keep}'		)

            lowercase														=			top_p
            lowercase														=			filter_value
            lowercase														=			min_tokens_to_keep







      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase							,							lowercase														=			lax.top_k(lowercase_	, scores.shape[-1]		)

            lowercase														=			jnp.full_like(lowercase_	, self.filter_value		)
            lowercase														=			jax.nn.softmax(lowercase_	, axis=-1		).cumsum(axis=-1		)
            lowercase														=			cumulative_probs < self.top_p

            # include the token that is higher than top_p as well
            lowercase														=			jnp.roll(lowercase_	, 1		)
            score_mask |= score_mask.at[:, 0].set(lowercase_		)

            # min tokens to keep
            lowercase														=			score_mask.at[:, : self.min_tokens_to_keep].set(lowercase_		)

            lowercase														=			jnp.where(lowercase_	, lowercase_	, lowercase_		)
            lowercase														=			jax.lax.sort_key_val(lowercase_	, lowercase_		)[-1]

            return next_scores






class 				_A		( lowerCAmelCase			):

      def __init__(		self	, __lowerCAmelCase	, __lowerCAmelCase = -float("""Inf"""		)	, __lowerCAmelCase = 1		):







            """simple docstring"""



            if not isinstance(lowercase_	, lowercase_		) or top_k <= 0:
                  raise ValueError(f'`top_k` has to be a strictly positive integer, but is {top_k}'		)

            lowercase														=			max(lowercase_	, lowercase_		)
            lowercase														=			filter_value







      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase							,							lowercase														=			scores.shape
            lowercase														=			jnp.full(batch_size * vocab_size	, self.filter_value		)

            lowercase														=			min(self.top_k	, scores.shape[-1]		)  # Safety check
            lowercase							,							lowercase														=			lax.top_k(lowercase_	, lowercase_		)
            lowercase														=			jnp.broadcast_to((jnp.arange(lowercase_		) * vocab_size)[:, None]	, (batch_size, topk)		).flatten()
            lowercase														=			topk_scores.flatten()
            lowercase														=			topk_indices.flatten() + shift

            lowercase														=			next_scores_flat.at[topk_indices_flat].set(lowercase_		)
            lowercase														=			next_scores_flat.reshape(lowercase_	, lowercase_		)
            return next_scores






class 				_A		( lowerCAmelCase			):

      def __init__(		self	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			bos_token_id







      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			jnp.full(scores.shape	, -float("""inf"""		)		)

            lowercase														=			1 - jnp.bool_(cur_len - 1		)

            lowercase														=			jnp.where(lowercase_	, new_scores.at[:, self.bos_token_id].set(0		)	, lowercase_		)

            return scores






class 				_A		( lowerCAmelCase			):

      def __init__(		self	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			max_length
            lowercase														=			eos_token_id







      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			jnp.full(scores.shape	, -float("""inf"""		)		)

            lowercase														=			1 - jnp.bool_(cur_len - self.max_length + 1		)

            lowercase														=			jnp.where(lowercase_	, new_scores.at[:, self.eos_token_id].set(0		)	, lowercase_		)

            return scores






class 				_A		( lowerCAmelCase			):

      def __init__(		self	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            if not isinstance(lowercase_	, lowercase_		) or min_length < 0:
                  raise ValueError(f'`min_length` has to be a positive integer, but is {min_length}'		)

            if not isinstance(lowercase_	, lowercase_		) or eos_token_id < 0:
                  raise ValueError(f'`eos_token_id` has to be a positive integer, but is {eos_token_id}'		)

            lowercase														=			min_length
            lowercase														=			eos_token_id







      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			1 - jnp.clip(cur_len - self.min_length	, 0	, 1		)

            lowercase														=			jnp.where(lowercase_	, scores.at[:, self.eos_token_id].set(-float("""inf"""		)		)	, lowercase_		)

            return scores






class 				_A		( lowerCAmelCase			):

      def __init__(		self	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			list(lowercase_		)
            lowercase														=			begin_index







      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			1 - jnp.bool_(cur_len - self.begin_index		)

            lowercase														=			jnp.where(lowercase_	, scores.at[:, self.begin_suppress_tokens].set(-float("""inf"""		)		)	, lowercase_		)

            return scores






class 				_A		( lowerCAmelCase			):

      def __init__(		self	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			list(lowercase_		)







      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			scores.at[..., self.suppress_tokens].set(-float("""inf"""		)		)

            return scores






class 				_A		( lowerCAmelCase			):

      def __init__(		self	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			dict(lowercase_		)
            # Converts the dictionary of format {index: token} containing the tokens to be forced to an array, where the
            # index of the array corresponds to the index of the token to be forced, for XLA compatibility.
            # Indexes without forced tokens will have a negative value.
            lowercase														=			jnp.ones((max(force_token_map.keys()		) + 1)	, dtype=jnp.intaa		) * -1
            for index, token in force_token_map.items():
                  if token is not None:
                        lowercase														=			force_token_array.at[index].set(lowercase_		)
            lowercase														=			jnp.intaa(lowercase_		)







      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            def _force_token(__lowerCAmelCase		):
                  lowercase														=			scores.shape[0]
                  lowercase														=			self.force_token_array[generation_idx]

                  lowercase														=			jnp.ones_like(lowercase_	, dtype=scores.dtype		) * -float("""inf"""		)
                  lowercase														=			jnp.zeros((batch_size, 1)	, dtype=scores.dtype		)
                  lowercase														=			lax.dynamic_update_slice(lowercase_	, lowercase_	, (0, current_token)		)
                  return new_scores

            lowercase														=			lax.cond(
                cur_len >= self.force_token_array.shape[0]	, lambda: scores	, lambda: lax.cond(
                    self.force_token_array[cur_len] >= 0	, lambda: _force_token(lowercase_		)	, lambda: scores	, )	, )
            return scores






class 				_A		( lowerCAmelCase			):

      def __init__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			generate_config.eos_token_id
            lowercase														=			generate_config.no_timestamps_token_id
            lowercase														=			generate_config.no_timestamps_token_id + 1

            lowercase														=			decoder_input_length + 1

            if generate_config.is_multilingual:
                  # room for language token and task token
                  self.begin_index += 2
            if hasattr(lowercase_	, """max_initial_timestamp_index"""		):
                  lowercase														=			generate_config.max_initial_timestamp_index
            else:
                  lowercase														=			model_config.vocab_size
            if self.max_initial_timestamp_index is None:
                  lowercase														=			model_config.vocab_size







      def __call__(		self	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase		):







            """simple docstring"""



            lowercase														=			scores.at[:, self.no_timestamps_token_id].set(-float("""inf"""		)		)

            def handle_pairs(__lowerCAmelCase	, __lowerCAmelCase		):
                  lowercase														=			jnp.where((cur_len - self.begin_index) >= 1	, lowercase_	, lowercase_		)
                  lowercase														=			jnp.where(
                      input_ids_k[cur_len - 1] >= self.timestamp_begin	, True and last_was_timestamp	, lowercase_	, )

                  lowercase														=			jnp.where((cur_len - self.begin_index) < 2	, lowercase_	, lowercase_		)
                  lowercase														=			jnp.where(
                      input_ids_k[cur_len - 2] >= self.timestamp_begin	, lowercase_	, lowercase_	, )

                  return jnp.where(
                      lowercase_	, jnp.where(
                          penultimate_was_timestamp > 0	, scores_k.at[self.timestamp_begin :].set(-float("""inf"""		)		)	, scores_k.at[: self.eos_token_id].set(-float("""inf"""		)		)	, )	, lowercase_	, )

            lowercase														=			jax.vmap(lowercase_		)(lowercase_	, lowercase_		)

            lowercase														=			jnp.where(cur_len == self.begin_index	, lowercase_	, lowercase_		)
            lowercase														=			jnp.where(
                self.max_initial_timestamp_index is not None	, True and apply_max_initial_timestamp	, lowercase_	, )

            lowercase														=			self.timestamp_begin + self.max_initial_timestamp_index

            lowercase														=			jnp.where(
                lowercase_	, scores.at[:, last_allowed + 1 :].set(-float("""inf"""		)		)	, lowercase_	, )

            # if sum of probability over timestamps is above any other token, sample timestamp
            lowercase														=			jax.nn.log_softmax(lowercase_	, axis=-1		)

            def handle_cumulative_probs(__lowerCAmelCase	, __lowerCAmelCase		):
                  lowercase														=			jax.nn.logsumexp(logprobs_k[self.timestamp_begin :]	, axis=-1		)
                  lowercase														=			jnp.max(logprobs_k[: self.timestamp_begin]		)
                  return jnp.where(
                      timestamp_logprob > max_text_token_logprob	, scores_k.at[: self.timestamp_begin].set(-float("""inf"""		)		)	, lowercase_	, )

            lowercase														=			jax.vmap(lowercase_		)(lowercase_	, lowercase_		)

            return scores




"""simple docstring"""






from __future__ import annotations


def     UpperCAmelCase__ (       lowerCAmelCase__  :list[float]      ,	lowerCAmelCase__  :list[float]	)				->					float:
      '''simple docstring'''


      lowercase														=			sorted(numsa + numsa	)
      lowercase							,							lowercase														=			divmod(len(lowerCAmelCase__	)      ,	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[Any]        =[float(x) for x in input("""Enter the elements of first array: """).split()]
       __lowerCAmelCase					: List[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)}""")



