



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__					  =  get_logger(__name__)


lowerCAmelCase__					  =  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 				snake_case__:

					"""simple docstring"""






					@add_start_docstrings(__snake_case					)
					def __call__(							self :     Dict				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray					):
									raise NotImplementedError(
									    f"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""					)






class 				snake_case__:

					"""simple docstring"""






					@add_start_docstrings(__snake_case					)
					def __call__(							self :     List[str]				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray					):
									raise NotImplementedError(
									    f"""{self.__class__} is an abstract class. Only classes inheriting this class can be called."""					)






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					@add_start_docstrings(__snake_case					)
					def __call__(							self :     Dict				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     int				,       **SCREAMING_SNAKE_CASE :     Any					):
									for processor in self:
													lowercase__					:   Optional[int]													=					inspect.signature(processor.__call__					).parameters
													if len(__snake_case					) > 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__					:   Any													=					processor(__snake_case				,       __snake_case				,       __snake_case				,       **__snake_case					)
													else:
																	lowercase__					:   List[str]													=					processor(__snake_case				,       __snake_case				,       __snake_case					)
									return scores






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					def __init__(							self :     str				,       SCREAMING_SNAKE_CASE :     float					):
									if not isinstance(__snake_case				,       __snake_case					) or not (temperature > 0):
													raise ValueError(f"""`temperature` has to be a strictly positive float, but is {temperature}"""					)

									lowercase__					:   List[Any]													=					temperature







					def __call__(							self :     Optional[int]				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   List[str]													=					scores / self.temperature
									return scores






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					def __init__(							self :     Any				,       SCREAMING_SNAKE_CASE :     float				,       SCREAMING_SNAKE_CASE :     float = -float("Inf"					)				,       SCREAMING_SNAKE_CASE :     int = 1					):
									if not isinstance(__snake_case				,       __snake_case					) 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(__snake_case				,       __snake_case					) 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__					:   Any													=					top_p
									lowercase__					:   List[str]													=					filter_value
									lowercase__					:   Any													=					min_tokens_to_keep







					def __call__(							self :     Optional[int]				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__							,							lowercase__					:   List[Any]													=					lax.top_k(__snake_case				,       scores.shape[-1]					)

									lowercase__					:   List[Any]													=					jnp.full_like(__snake_case				,       self.filter_value					)
									lowercase__					:   List[str]													=					jax.nn.softmax(__snake_case				,       axis=-1					).cumsum(axis=-1					)
									lowercase__					:   Union[str, Any]													=					cumulative_probs < self.top_p

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

									# min tokens to keep
									lowercase__					:   Dict													=					score_mask.at[:, : self.min_tokens_to_keep].set(__snake_case					)

									lowercase__					:   Dict													=					jnp.where(__snake_case				,       __snake_case				,       __snake_case					)
									lowercase__					:   Union[str, Any]													=					jax.lax.sort_key_val(__snake_case				,       __snake_case					)[-1]

									return next_scores






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					def __init__(							self :     List[str]				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     float = -float("Inf"					)				,       SCREAMING_SNAKE_CASE :     int = 1					):
									if not isinstance(__snake_case				,       __snake_case					) or top_k <= 0:
													raise ValueError(f"""`top_k` has to be a strictly positive integer, but is {top_k}"""					)

									lowercase__					:   Optional[int]													=					max(__snake_case				,       __snake_case					)
									lowercase__					:   Optional[Any]													=					filter_value







					def __call__(							self :     int				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__							,							lowercase__					:   List[str]													=					scores.shape
									lowercase__					:   int													=					jnp.full(batch_size * vocab_size				,       self.filter_value					)

									lowercase__					:   Optional[int]													=					min(self.top_k				,       scores.shape[-1]					)  # Safety check
									lowercase__							,							lowercase__					:   Optional[Any]													=					lax.top_k(__snake_case				,       __snake_case					)
									lowercase__					:   Optional[Any]													=					jnp.broadcast_to((jnp.arange(__snake_case					) * vocab_size)[:, None]				,       (batch_size, topk)					).flatten()
									lowercase__					:   Optional[Any]													=					topk_scores.flatten()
									lowercase__					:   Union[str, Any]													=					topk_indices.flatten() + shift

									lowercase__					:   Union[str, Any]													=					next_scores_flat.at[topk_indices_flat].set(__snake_case					)
									lowercase__					:   Tuple													=					next_scores_flat.reshape(__snake_case				,       __snake_case					)
									return next_scores






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					def __init__(							self :     int				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   List[Any]													=					bos_token_id







					def __call__(							self :     List[Any]				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   str													=					jnp.full(scores.shape				,       -float("inf"					)					)

									lowercase__					:   Optional[Any]													=					1 - jnp.bool_(cur_len - 1					)

									lowercase__					:   Optional[int]													=					jnp.where(__snake_case				,       new_scores.at[:, self.bos_token_id].set(0					)				,       __snake_case					)

									return scores






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					def __init__(							self :     Union[str, Any]				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   str													=					max_length
									lowercase__					:   Union[str, Any]													=					eos_token_id







					def __call__(							self :     int				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   List[str]													=					jnp.full(scores.shape				,       -float("inf"					)					)

									lowercase__					:   str													=					1 - jnp.bool_(cur_len - self.max_length + 1					)

									lowercase__					:   Optional[int]													=					jnp.where(__snake_case				,       new_scores.at[:, self.eos_token_id].set(0					)				,       __snake_case					)

									return scores






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					def __init__(							self :     str				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     int					):
									if not isinstance(__snake_case				,       __snake_case					) or min_length < 0:
													raise ValueError(f"""`min_length` has to be a positive integer, but is {min_length}"""					)

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

									lowercase__					:   List[str]													=					min_length
									lowercase__					:   List[str]													=					eos_token_id







					def __call__(							self :     Any				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     int					):
									# create boolean flag to decide if min length penalty should be applied
									lowercase__					:   str													=					1 - jnp.clip(cur_len - self.min_length				,       0				,       1					)

									lowercase__					:   List[Any]													=					jnp.where(__snake_case				,       scores.at[:, self.eos_token_id].set(-float("inf"					)					)				,       __snake_case					)

									return scores






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					def __init__(							self :     Optional[int]				,       SCREAMING_SNAKE_CASE :     List[str]				,       SCREAMING_SNAKE_CASE :     Optional[int]					):
									lowercase__					:   List[Any]													=					list(__snake_case					)
									lowercase__					:   Optional[Any]													=					begin_index







					def __call__(							self :     str				,       SCREAMING_SNAKE_CASE :     List[str]				,       SCREAMING_SNAKE_CASE :     str				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   Tuple													=					1 - jnp.bool_(cur_len - self.begin_index					)

									lowercase__					:   str													=					jnp.where(__snake_case				,       scores.at[:, self.begin_suppress_tokens].set(-float("inf"					)					)				,       __snake_case					)

									return scores






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					def __init__(							self :     List[str]				,       SCREAMING_SNAKE_CASE :     list					):
									lowercase__					:   str													=					list(__snake_case					)







					def __call__(							self :     Dict				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   Optional[int]													=					scores.at[..., self.suppress_tokens].set(-float("inf"					)					)

									return scores






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					def __init__(							self :     Dict				,       SCREAMING_SNAKE_CASE :     Optional[int]					):
									lowercase__					:   Dict													=					dict(__snake_case					)
									# 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__					:   Optional[Any]													=					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__					:   int													=					force_token_array.at[index].set(__snake_case					)
									lowercase__					:   Dict													=					jnp.intaa(__snake_case					)







					def __call__(							self :     Optional[int]				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     jnp.ndarray				,       SCREAMING_SNAKE_CASE :     int					):
									def _force_token(SCREAMING_SNAKE_CASE :     Optional[Any]					):
													lowercase__					:   Optional[Any]													=					scores.shape[0]
													lowercase__					:   List[Any]													=					self.force_token_array[generation_idx]

													lowercase__					:   Optional[int]													=					jnp.ones_like(__snake_case				,       dtype=scores.dtype					) * -float("inf"					)
													lowercase__					:   str													=					jnp.zeros((batch_size, 1)				,       dtype=scores.dtype					)
													lowercase__					:   int													=					lax.dynamic_update_slice(__snake_case				,       __snake_case				,       (0, current_token)					)
													return new_scores

									lowercase__					:   int													=					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(__snake_case					)				,       lambda: scores				,       )				,       )
									return scores






class 				snake_case__(lowerCamelCase_      ):

					"""simple docstring"""






					def __init__(							self :     Any				,       SCREAMING_SNAKE_CASE :     List[str]				,       SCREAMING_SNAKE_CASE :     str				,       SCREAMING_SNAKE_CASE :     List[Any]					):
									lowercase__					:   Tuple													=					generate_config.eos_token_id
									lowercase__					:   Dict													=					generate_config.no_timestamps_token_id
									lowercase__					:   Union[str, Any]													=					generate_config.no_timestamps_token_id + 1

									lowercase__					:   List[Any]													=					decoder_input_length + 1

									if generate_config.is_multilingual:
													# room for language token and task token
													self.begin_index += 2
									if hasattr(__snake_case				,       "max_initial_timestamp_index"					):
													lowercase__					:   Optional[int]													=					generate_config.max_initial_timestamp_index
									else:
													lowercase__					:   Dict													=					model_config.vocab_size
									if self.max_initial_timestamp_index is None:
													lowercase__					:   int													=					model_config.vocab_size







					def __call__(							self :     Any				,       SCREAMING_SNAKE_CASE :     List[Any]				,       SCREAMING_SNAKE_CASE :     Optional[int]				,       SCREAMING_SNAKE_CASE :     Optional[Any]					):
									# suppress <|notimestamps|> which is handled by without_timestamps
									lowercase__					:   Dict													=					scores.at[:, self.no_timestamps_token_id].set(-float("inf"					)					)

									def handle_pairs(SCREAMING_SNAKE_CASE :     List[str]				,       SCREAMING_SNAKE_CASE :     Union[str, Any]					):
													lowercase__					:   str													=					jnp.where((cur_len - self.begin_index) >= 1				,       __snake_case				,       __snake_case					)
													lowercase__					:   List[str]													=					jnp.where(
													    input_ids_k[cur_len - 1] >= self.timestamp_begin				,       True and last_was_timestamp				,       __snake_case				,       )

													lowercase__					:   Optional[int]													=					jnp.where((cur_len - self.begin_index) < 2				,       __snake_case				,       __snake_case					)
													lowercase__					:   Any													=					jnp.where(
													    input_ids_k[cur_len - 2] >= self.timestamp_begin				,       __snake_case				,       __snake_case				,       )

													return jnp.where(
													    __snake_case				,       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"					)					)				,       )				,       __snake_case				,       )

									lowercase__					:   Optional[int]													=					jax.vmap(__snake_case					)(__snake_case				,       __snake_case					)

									lowercase__					:   Any													=					jnp.where(cur_len == self.begin_index				,       __snake_case				,       __snake_case					)
									lowercase__					:   Optional[int]													=					jnp.where(
									    self.max_initial_timestamp_index is not None				,       True and apply_max_initial_timestamp				,       __snake_case				,       )

									lowercase__					:   List[str]													=					self.timestamp_begin + self.max_initial_timestamp_index

									lowercase__					:   List[Any]													=					jnp.where(
									    __snake_case				,       scores.at[:, last_allowed + 1 :].set(-float("inf"					)					)				,       __snake_case				,       )

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

									def handle_cumulative_probs(SCREAMING_SNAKE_CASE :     Dict				,       SCREAMING_SNAKE_CASE :     List[Any]					):
													lowercase__					:   Any													=					jax.nn.logsumexp(logprobs_k[self.timestamp_begin :]				,       axis=-1					)
													lowercase__					:   Optional[Any]													=					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"					)					)				,       __snake_case				,       )

									lowercase__					:   int													=					jax.vmap(__snake_case					)(__snake_case				,       __snake_case					)

									return scores









from __future__ import annotations

import math
import random
from collections.abc import Collection
from typing import overload

class 				snake_case__:

					"""simple docstring"""






					def __init__(							self :     Optional[Any]				,       SCREAMING_SNAKE_CASE :     Collection[float] | None = None					):
									if components is None:
													lowercase__					:   List[Any]													=					[]
									lowercase__					:   str													=					list(SCREAMING_SNAKE_CASE					)







					def __len__(							self :     Tuple					):
									return len(self.__components					)







					def __str__(							self :     int					):
									return "(" + ",".join(map(SCREAMING_SNAKE_CASE				,       self.__components					)					) + ")"







					def __add__(							self :     List[Any]				,       SCREAMING_SNAKE_CASE :     Vector					):
									lowercase__					:   Optional[Any]													=					len(self					)
									if size == len(SCREAMING_SNAKE_CASE					):
													lowercase__					:   int													=					[self.__components[i] + other.component(SCREAMING_SNAKE_CASE					) for i in range(SCREAMING_SNAKE_CASE					)]
													return Vector(SCREAMING_SNAKE_CASE					)
									else:
													raise Exception("must have the same size"					)







					def __sub__(							self :     Any				,       SCREAMING_SNAKE_CASE :     Vector					):
									lowercase__					:   Any													=					len(self					)
									if size == len(SCREAMING_SNAKE_CASE					):
													lowercase__					:   Any													=					[self.__components[i] - other.component(SCREAMING_SNAKE_CASE					) for i in range(SCREAMING_SNAKE_CASE					)]
													return Vector(SCREAMING_SNAKE_CASE					)
									else:  # error case
													raise Exception("must have the same size"					)







					@overload
					def __mul__(							self :     int				,       SCREAMING_SNAKE_CASE :     float					):
									...







					@overload
					def __mul__(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     Vector					):
									...







					def __mul__(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     float | Vector					):
									if isinstance(SCREAMING_SNAKE_CASE				,       (float, int)					):
													lowercase__					:   Dict													=					[c * other for c in self.__components]
													return Vector(SCREAMING_SNAKE_CASE					)
									elif isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					) and len(self					) == len(SCREAMING_SNAKE_CASE					):
													lowercase__					:   List[str]													=					len(self					)
													lowercase__					:   Union[str, Any]													=					[self.__components[i] * other.component(SCREAMING_SNAKE_CASE					) for i in range(SCREAMING_SNAKE_CASE					)]
													return sum(SCREAMING_SNAKE_CASE					)
									else:  # error case
													raise Exception("invalid operand!"					)







					def 			snake_case					(							self :     Any					):
									return Vector(self.__components					)







					def 			snake_case					(							self :     Optional[int]				,       SCREAMING_SNAKE_CASE :     int					):
									if isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					) and -len(self.__components					) <= i < len(self.__components					):
													return self.__components[i]
									else:
													raise Exception("index out of range"					)







					def 			snake_case					(							self :     Optional[int]				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     float					):
									assert -len(self.__components					) <= pos < len(self.__components					)
									lowercase__					:   int													=					value







					def 			snake_case					(							self :     Any					):
									if len(self.__components					) == 0:
													raise Exception("Vector is empty"					)
									lowercase__					:   Union[str, Any]													=					[c**2 for c in self.__components]
									return math.sqrt(sum(SCREAMING_SNAKE_CASE					)					)







					def 			snake_case					(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     Vector				,       SCREAMING_SNAKE_CASE :     bool = False					):
									lowercase__					:   Optional[Any]													=					self * other
									lowercase__					:   Union[str, Any]													=					self.euclidean_length() * other.euclidean_length()
									if deg:
													return math.degrees(math.acos(num / den					)					)
									else:
													return math.acos(num / den					)






def  __lowerCamelCase (       lowerCamelCase__						):

				"""simple docstring"""


				assert isinstance(lowerCamelCase__					,			lowerCamelCase__						)
				return Vector([0] * dimension						)


def  __lowerCamelCase (       lowerCamelCase__					,			lowerCamelCase__						):

				"""simple docstring"""


				assert isinstance(lowerCamelCase__					,			lowerCamelCase__						) and (isinstance(lowerCamelCase__					,			lowerCamelCase__						))
				lowercase__					:   Tuple													=					[0] * dimension
				lowercase__					:   Union[str, Any]													=					1
				return Vector(lowerCamelCase__						)


def  __lowerCamelCase (       lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__						):

				"""simple docstring"""


				assert (
				    isinstance(lowerCamelCase__					,			lowerCamelCase__						)
				    and isinstance(lowerCamelCase__					,			lowerCamelCase__						)
				    and (isinstance(lowerCamelCase__					,			(int, float)						))
				)
				return x * scalar + y


def  __lowerCamelCase (       lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__						):

				"""simple docstring"""


				random.seed(lowerCamelCase__						)
				lowercase__					:   Optional[Any]													=					[random.randint(lowerCamelCase__					,			lowerCamelCase__						) for _ in range(lowerCamelCase__						)]
				return Vector(lowerCamelCase__						)

class 				snake_case__:

					"""simple docstring"""






					def __init__(							self :     Optional[Any]				,       SCREAMING_SNAKE_CASE :     list[list[float]]				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     int					):
									lowercase__					:   List[str]													=					matrix
									lowercase__					:   int													=					w
									lowercase__					:   str													=					h







					def __str__(							self :     int					):
									lowercase__					:   int													=					""
									for i in range(self.__height					):
													ans += "|"
													for j in range(self.__width					):
																	if j < self.__width - 1:
																					ans += str(self.__matrix[i][j]					) + ","
																	else:
																					ans += str(self.__matrix[i][j]					) + "|\n"
									return ans







					def __add__(							self :     str				,       SCREAMING_SNAKE_CASE :     Matrix					):
									if self.__width == other.width() and self.__height == other.height():
													lowercase__					:   Union[str, Any]													=					[]
													for i in range(self.__height					):
																	lowercase__					:   int													=					[
																	    self.__matrix[i][j] + other.component(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					)
																	    for j in range(self.__width					)
																	]
																	matrix.append(SCREAMING_SNAKE_CASE					)
													return Matrix(SCREAMING_SNAKE_CASE				,       self.__width				,       self.__height					)
									else:
													raise Exception("matrix must have the same dimension!"					)







					def __sub__(							self :     Dict				,       SCREAMING_SNAKE_CASE :     Matrix					):
									if self.__width == other.width() and self.__height == other.height():
													lowercase__					:   Dict													=					[]
													for i in range(self.__height					):
																	lowercase__					:   Optional[Any]													=					[
																	    self.__matrix[i][j] - other.component(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					)
																	    for j in range(self.__width					)
																	]
																	matrix.append(SCREAMING_SNAKE_CASE					)
													return Matrix(SCREAMING_SNAKE_CASE				,       self.__width				,       self.__height					)
									else:
													raise Exception("matrices must have the same dimension!"					)







					@overload
					def __mul__(							self :     Any				,       SCREAMING_SNAKE_CASE :     float					):
									...







					@overload
					def __mul__(							self :     Tuple				,       SCREAMING_SNAKE_CASE :     Vector					):
									...







					def __mul__(							self :     Optional[Any]				,       SCREAMING_SNAKE_CASE :     float | Vector					):
									if isinstance(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					):  # matrix-vector
													if len(SCREAMING_SNAKE_CASE					) == self.__width:
																	lowercase__					:   Any													=					zero_vector(self.__height					)
																	for i in range(self.__height					):
																					lowercase__					:   Union[str, Any]													=					[
																					    self.__matrix[i][j] * other.component(SCREAMING_SNAKE_CASE					)
																					    for j in range(self.__width					)
																					]
																					ans.change_component(SCREAMING_SNAKE_CASE				,       sum(SCREAMING_SNAKE_CASE					)					)
																	return ans
													else:
																	raise Exception(
																	    "vector must have the same size as the "
																	    "number of columns of the matrix!"					)
									elif isinstance(SCREAMING_SNAKE_CASE				,       (int, float)					):  # matrix-scalar
													lowercase__					:   str													=					[
													    [self.__matrix[i][j] * other for j in range(self.__width					)]
													    for i in range(self.__height					)
													]
													return Matrix(SCREAMING_SNAKE_CASE				,       self.__width				,       self.__height					)
									return None







					def 			snake_case					(							self :     Union[str, Any]					):
									return self.__height







					def 			snake_case					(							self :     Optional[Any]					):
									return self.__width







					def 			snake_case					(							self :     int				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     int					):
									if 0 <= x < self.__height and 0 <= y < self.__width:
													return self.__matrix[x][y]
									else:
													raise Exception("change_component: indices out of bounds"					)







					def 			snake_case					(							self :     Optional[Any]				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     float					):
									if 0 <= x < self.__height and 0 <= y < self.__width:
													lowercase__					:   Union[str, Any]													=					value
									else:
													raise Exception("change_component: indices out of bounds"					)







					def 			snake_case					(							self :     int				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     int					):
									if self.__height != self.__width:
													raise Exception("Matrix is not square"					)
									lowercase__					:   str													=					self.__matrix[:x] + self.__matrix[x + 1 :]
									for i in range(len(SCREAMING_SNAKE_CASE					)					):
													lowercase__					:   Optional[int]													=					minor[i][:y] + minor[i][y + 1 :]
									return Matrix(SCREAMING_SNAKE_CASE				,       self.__width - 1				,       self.__height - 1					).determinant()







					def 			snake_case					(							self :     Dict				,       SCREAMING_SNAKE_CASE :     int				,       SCREAMING_SNAKE_CASE :     int					):
									if self.__height != self.__width:
													raise Exception("Matrix is not square"					)
									if 0 <= x < self.__height and 0 <= y < self.__width:
													return (-1) ** (x + y) * self.minor(SCREAMING_SNAKE_CASE				,       SCREAMING_SNAKE_CASE					)
									else:
													raise Exception("Indices out of bounds"					)







					def 			snake_case					(							self :     List[str]					):
									if self.__height != self.__width:
													raise Exception("Matrix is not square"					)
									if self.__height < 1:
													raise Exception("Matrix has no element"					)
									elif self.__height == 1:
													return self.__matrix[0][0]
									elif self.__height == 2:
													return (
													    self.__matrix[0][0] * self.__matrix[1][1]
													    - self.__matrix[0][1] * self.__matrix[1][0]
													)
									else:
													lowercase__					:   Dict													=					[
													    self.__matrix[0][y] * self.cofactor(0				,       SCREAMING_SNAKE_CASE					) for y in range(self.__width					)
													]
													return sum(SCREAMING_SNAKE_CASE					)






def  __lowerCamelCase (       lowerCamelCase__						):

				"""simple docstring"""


				lowercase__					:   list[list[float]]													=					[[0] * n for _ in range(lowerCamelCase__						)]
				return Matrix(lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__						)


def  __lowerCamelCase (       lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__						):

				"""simple docstring"""


				random.seed(lowerCamelCase__						)
				lowercase__					:   list[list[float]]													=					[
				    [random.randint(lowerCamelCase__					,			lowerCamelCase__						) for _ in range(lowerCamelCase__						)] for _ in range(lowerCamelCase__						)
				]
				return Matrix(lowerCamelCase__					,			lowerCamelCase__					,			lowerCamelCase__						)




