





import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin





class A_					(			_lowerCamelCase   ):
   lowerCAmelCase__        = """MCTCTFeatureExtractor"""
   lowerCAmelCase__        = """AutoTokenizer"""




   def __init__(self	:Optional[Any]    ,   _UpperCamelCase	:str    ,   _UpperCamelCase	:Dict )->					Optional[Any]:
         super().__init__(_UpperCamelCase    ,   _UpperCamelCase )
         __A          =				self.feature_extractor
         __A          =				False




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

         if "raw_speech" in kwargs:
               warnings.warn('''Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.''' )
               __A          =				kwargs.pop('''raw_speech''' )
         else:
               __A          =				kwargs.pop('''audio'''    ,   _UpperCamelCase )
         __A          =				kwargs.pop('''sampling_rate'''    ,   _UpperCamelCase )
         __A          =				kwargs.pop('''text'''    ,   _UpperCamelCase )
         if len(_UpperCamelCase ) > 0:
               __A          =				args[0]
               __A          =				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 audio is not None:
               __A          =				self.feature_extractor(_UpperCamelCase    ,   *_UpperCamelCase    ,   sampling_rate=_UpperCamelCase    ,   **_UpperCamelCase )
         if text is not None:
               __A          =				self.tokenizer(_UpperCamelCase    ,   **_UpperCamelCase )

         if text is None:
               return inputs
         elif audio is None:
               return encodings
         else:
               __A          =				encodings['''input_ids''']
               return inputs




   def _lowerCAmelCase      (self	:Dict    ,   *_UpperCamelCase	:List[Any]    ,   **_UpperCamelCase	:Union[str, Any] )->					str:
         return self.tokenizer.batch_decode(*_UpperCamelCase    ,   **_UpperCamelCase )




   def _lowerCAmelCase      (self	:Optional[Any]    ,   *_UpperCamelCase	:Optional[int]    ,   **_UpperCamelCase	:int )->					Optional[Any]:
         # For backward compatibility
         if self._in_target_context_manager:
               return self.current_processor.pad(*_UpperCamelCase    ,   **_UpperCamelCase )

         __A          =				kwargs.pop('''input_features'''    ,   _UpperCamelCase )
         __A          =				kwargs.pop('''labels'''    ,   _UpperCamelCase )
         if len(_UpperCamelCase ) > 0:
               __A          =				args[0]
               __A          =				args[1:]

         if input_features is not None:
               __A          =				self.feature_extractor.pad(_UpperCamelCase    ,   *_UpperCamelCase    ,   **_UpperCamelCase )
         if labels is not None:
               __A          =				self.tokenizer.pad(_UpperCamelCase    ,   **_UpperCamelCase )

         if labels is None:
               return input_features
         elif input_features is None:
               return labels
         else:
               __A          =				labels['''input_ids''']
               return input_features




   def _lowerCAmelCase      (self	:Union[str, Any]    ,   *_UpperCamelCase	:Optional[Any]    ,   **_UpperCamelCase	:Optional[int] )->					Any:
         return self.tokenizer.decode(*_UpperCamelCase    ,   **_UpperCamelCase )






   @contextmanager
   def _lowerCAmelCase      (self	:str )->					str:
         warnings.warn(
             '''`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '''
             '''labels by using the argument `text` of the regular `__call__` method (either in the same call as '''
             '''your audio inputs, or in a separate call.''' )
         __A          =				True
         __A          =				self.tokenizer
         yield
         __A          =				self.feature_extractor
         __A          =				False












import numpy as np
from PIL import Image



def _a				(	lowerCamelCase:   np.ndarray					,				lowerCamelCase:   int					,				lowerCamelCase:   int )	->						np.ndarray:







      '''simple docstring'''






      __A          =				np.array(lowerCamelCase )
      if arr.shape[0] != arr.shape[1]:
            raise ValueError('''The input array is not a square matrix''' )
      __A          =				0
      __A          =				0
      __A          =				0
      __A          =				0

      # compute the shape of the output matrix
      __A          =				(arr.shape[0] - size) // stride + 1
      # initialize the output matrix with zeros of shape maxpool_shape
      __A          =				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
                  __A          =				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
            __A          =				0
            __A          =				0

      return updated_arr



def _a				(	lowerCamelCase:   np.ndarray					,				lowerCamelCase:   int					,				lowerCamelCase:   int )	->						np.ndarray:







      '''simple docstring'''






      __A          =				np.array(lowerCamelCase )
      if arr.shape[0] != arr.shape[1]:
            raise ValueError('''The input array is not a square matrix''' )
      __A          =				0
      __A          =				0
      __A          =				0
      __A          =				0

      # compute the shape of the output matrix
      __A          =				(arr.shape[0] - size) // stride + 1
      # initialize the output matrix with zeros of shape avgpool_shape
      __A          =				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
                  __A          =				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
            __A          =				0
            __A          =				0

      return updated_arr


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

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

       # Loading the image
       snake_case__					:							Optional[Any]													=     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()





