



"""simple docstring"""






from typing import List, Optional

import numpy as np

from ...processing_utils import ProcessorMixin
from ...utils import to_numpy

class 	__SCREAMING_SNAKE_CASE     (				lowerCAmelCase_       ):


					'''simple docstring'''





					_a             =							'EncodecFeatureExtractor'
					_a             =							('T5Tokenizer', 'T5TokenizerFast')



					def __init__(	self							:  Any,  lowerCamelCase							:  str,  lowerCamelCase							:  List[str]					)-> str:
								super().__init__(lowerCamelCase,  lowerCamelCase					)
								lowerCamelCase__		:		Union[str, Any]		     =self.feature_extractor
								lowerCamelCase__		:		Tuple		     =False



					def 		snake_case	(	self							:  Any,  lowerCamelCase							:  Dict=None,  lowerCamelCase							:  str=None,  lowerCamelCase							:  List[Any]=True					)-> str:
								return self.tokenizer.get_decoder_prompt_ids(task=lowerCamelCase,  language=lowerCamelCase,  no_timestamps=lowerCamelCase					)



					def __call__(	self							:  List[Any],  *lowerCamelCase							:  Optional[Any],  **lowerCamelCase							:  Tuple					)-> List[Any]:
								# For backward compatibility
								if self._in_target_context_manager:
											return self.current_processor(*lowerCamelCase,  **lowerCamelCase					)

								lowerCamelCase__		:		List[str]		     =kwargs.pop('''audio''',  lowerCamelCase					)
								lowerCamelCase__		:		List[Any]		     =kwargs.pop('''sampling_rate''',  lowerCamelCase					)
								lowerCamelCase__		:		Any		     =kwargs.pop('''text''',  lowerCamelCase					)
								if len(lowerCamelCase					) > 0:
											lowerCamelCase__		:		Union[str, Any]		     =args[0]
											lowerCamelCase__		:		str		     =args[1:]

								if audio is None and text is None:
											raise ValueError('''You need to specify either an `audio` or `text` input to process.'''					)

								if text is not None:
											lowerCamelCase__		:		Tuple		     =self.tokenizer(lowerCamelCase,  **lowerCamelCase					)

								if audio is not None:
											lowerCamelCase__		:		int		     =self.feature_extractor(lowerCamelCase,  *lowerCamelCase,  sampling_rate=lowerCamelCase,  **lowerCamelCase					)

								if audio is None:
											return inputs

								elif text is None:
											return audio_inputs

								else:
											lowerCamelCase__		:		Optional[int]		     =audio_inputs['''input_values''']
											if "padding_mask" in audio_inputs:
														lowerCamelCase__		:		Dict		     =audio_inputs['''padding_mask''']
											return inputs



					def 		snake_case	(	self							:  Optional[Any],  *lowerCamelCase							:  Any,  **lowerCamelCase							:  Union[str, Any]					)-> List[Any]:
								lowerCamelCase__		:		Dict		     =kwargs.pop('''audio''',  lowerCamelCase					)
								lowerCamelCase__		:		List[Any]		     =kwargs.pop('''padding_mask''',  lowerCamelCase					)

								if len(lowerCamelCase					) > 0:
											lowerCamelCase__		:		str		     =args[0]
											lowerCamelCase__		:		Dict		     =args[1:]

								if audio_values is not None:
											return self._decode_audio(lowerCamelCase,  padding_mask=lowerCamelCase					)
								else:
											return self.tokenizer.batch_decode(*lowerCamelCase,  **lowerCamelCase					)



					def 		snake_case	(	self							:  Dict,  *lowerCamelCase							:  List[Any],  **lowerCamelCase							:  Dict					)-> int:
								return self.tokenizer.decode(*lowerCamelCase,  **lowerCamelCase					)




					def 		snake_case	(	self							:  Any,  lowerCamelCase							:  Tuple,  lowerCamelCase							:  Optional = None					)-> List[np.ndarray]:
								lowerCamelCase__		:		List[str]		     =to_numpy(lowerCamelCase					)
								lowerCamelCase__     ,       lowerCamelCase__     ,       lowerCamelCase__		:		List[str]		     =audio_values.shape

								if padding_mask is None:
											return list(lowerCamelCase					)

								lowerCamelCase__		:		Optional[Any]		     =to_numpy(lowerCamelCase					)

								# match the sequence length of the padding mask to the generated audio arrays by padding with the **non-padding**
								# token (so that the generated audio values are **not** treated as padded tokens)
								lowerCamelCase__		:		Optional[Any]		     =seq_len - padding_mask.shape[-1]
								lowerCamelCase__		:		int		     =1 - self.feature_extractor.padding_value
								lowerCamelCase__		:		str		     =np.pad(lowerCamelCase,  ((0, 0), (0, difference)),  '''constant''',  constant_values=lowerCamelCase					)

								lowerCamelCase__		:		Dict		     =audio_values.tolist()
								for i in range(lowerCamelCase					):
											lowerCamelCase__		:		Optional[Any]		     =np.asarray(audio_values[i]					)[
											    padding_mask[i][None, :] != self.feature_extractor.padding_value
											]
											lowerCamelCase__		:		Any		     =sliced_audio.reshape(lowerCamelCase,  -1					)

								return audio_values









"""simple docstring"""






import numpy as np
from PIL import Image






def 					snake_case__       (		__lowerCamelCase    :   np.ndarray							,		__lowerCamelCase    :   int							,		__lowerCamelCase    :   int     ):
			"""simple docstring"""
			lowerCamelCase__		:		List[Any]		     =np.array(__lowerCamelCase     )
			if arr.shape[0] != arr.shape[1]:
						raise ValueError('''The input array is not a square matrix'''     )
			lowerCamelCase__		:		int		     =0
			lowerCamelCase__		:		int		     =0
			lowerCamelCase__		:		Optional[int]		     =0
			lowerCamelCase__		:		List[Any]		     =0

			# compute the shape of the output matrix
			lowerCamelCase__		:		Union[str, Any]		     =(arr.shape[0] - size) // stride + 1
			# initialize the output matrix with zeros of shape maxpool_shape
			lowerCamelCase__		:		Union[str, Any]		     =np.zeros((maxpool_shape, maxpool_shape)     )

			while i < arr.shape[0]:
						if i + size > arr.shape[0]:
									# if the end of the matrix is reached, break
									break
						while j < arr.shape[1]:
									# if the end of the matrix is reached, break
									if j + size > arr.shape[1]:
												break
									# compute the maximum of the pooling matrix
									lowerCamelCase__		:		str		     =np.max(arr[i : i + size, j : j + size]     )
									# shift the pooling matrix by stride of column pixels
									j += stride
									mat_j += 1

						# shift the pooling matrix by stride of row pixels
						i += stride
						mat_i += 1

						# reset the column index to 0
						lowerCamelCase__		:		Optional[int]		     =0
						lowerCamelCase__		:		Optional[int]		     =0

			return updated_arr






def 					snake_case__       (		__lowerCamelCase    :   np.ndarray							,		__lowerCamelCase    :   int							,		__lowerCamelCase    :   int     ):
			"""simple docstring"""
			lowerCamelCase__		:		List[Any]		     =np.array(__lowerCamelCase     )
			if arr.shape[0] != arr.shape[1]:
						raise ValueError('''The input array is not a square matrix'''     )
			lowerCamelCase__		:		str		     =0
			lowerCamelCase__		:		List[Any]		     =0
			lowerCamelCase__		:		Optional[int]		     =0
			lowerCamelCase__		:		List[Any]		     =0

			# compute the shape of the output matrix
			lowerCamelCase__		:		Dict		     =(arr.shape[0] - size) // stride + 1
			# initialize the output matrix with zeros of shape avgpool_shape
			lowerCamelCase__		:		Optional[Any]		     =np.zeros((avgpool_shape, avgpool_shape)     )

			while i < arr.shape[0]:
						# if the end of the matrix is reached, break
						if i + size > arr.shape[0]:
									break
						while j < arr.shape[1]:
									# if the end of the matrix is reached, break
									if j + size > arr.shape[1]:
												break
									# compute the average of the pooling matrix
									lowerCamelCase__		:		Optional[int]		     =int(np.average(arr[i : i + size, j : j + size]     )     )
									# shift the pooling matrix by stride of column pixels
									j += stride
									mat_j += 1

						# shift the pooling matrix by stride of row pixels
						i += stride
						mat_i += 1
						# reset the column index to 0
						lowerCamelCase__		:		Optional[Any]		     =0
						lowerCamelCase__		:		int		     =0

			return updated_arr


# Main Function
if __name__ == "__main__":
		from doctest import testmod

		testmod(name="avgpooling", verbose=True)

		# Loading the image
		_lowercase			:			int										=						Image.open("path_to_image")

		# Converting the image to numpy array and maxpooling, displaying the result
		# Ensure that the image is a square matrix

		Image.fromarray(maxpooling(np.array(image), size=3, stride=2)).show()

		# Converting the image to numpy array and averagepooling, displaying the result
		# Ensure that the image is a square matrix

		Image.fromarray(avgpooling(np.array(image), size=3, stride=2)).show()




