


"""simple docstring"""



from io import BytesIO
from typing import List, Union

import requests

from ..utils import add_end_docstrings, is_decord_available, is_torch_available, logging, requires_backends
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_decord_available():
  import numpy as np
  from decord import VideoReader


if is_torch_available():
  from ..models.auto.modeling_auto import MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING

__snake_case             =   logging.get_logger(__name__)







@add_end_docstrings(__SCREAMING_SNAKE_CASE     )
class _lowerCAmelCase    (				__SCREAMING_SNAKE_CASE     ):







   def __init__(     self						,     *UpperCamelCase__						,     **UpperCamelCase__						)     ->		List[Any]:

       '''simple docstring'''




       super().__init__(*_snake_case						,     **_snake_case						)
       requires_backends(self						,     "decord"						)
       self.check_model_type(_snake_case						)







   def 			lowerCamelCase		(     self						,     UpperCamelCase__=None						,     UpperCamelCase__=None						,     UpperCamelCase__=None						)     ->		Union[str, Any]:

       '''simple docstring'''




       snake_case   :				Optional[Any]				 =   {}
       if frame_sampling_rate is not None:
           snake_case   :				Optional[int]				 =   frame_sampling_rate
       if num_frames is not None:
           snake_case   :				Union[str, Any]				 =   num_frames

       snake_case   :				int				 =   {}
       if top_k is not None:
           snake_case   :				Dict				 =   top_k
       return preprocess_params, {}, postprocess_params







   def __call__(     self						,     UpperCamelCase__						,     **UpperCamelCase__						)     ->		Optional[Any]:

       '''simple docstring'''




       return super().__call__(_snake_case						,     **_snake_case						)







   def 			lowerCamelCase		(     self						,     UpperCamelCase__						,     UpperCamelCase__=None						,     UpperCamelCase__=1						)     ->		str:

       '''simple docstring'''




       if num_frames is None:
           snake_case   :				Any				 =   self.model.config.num_frames

       if video.startswith("http://"						) or video.startswith("https://"						):
           snake_case   :				Optional[int]				 =   BytesIO(requests.get(_snake_case						).content						)

       snake_case   :				Tuple				 =   VideoReader(_snake_case						)
       videoreader.seek(0						)

       snake_case   :				Dict				 =   0
       snake_case   :				Optional[Any]				 =   num_frames * frame_sampling_rate - 1
       snake_case   :				Dict				 =   np.linspace(_snake_case						,     _snake_case						,     num=_snake_case						,     dtype=np.intaa						)

       snake_case   :				int				 =   videoreader.get_batch(_snake_case						).asnumpy()
       snake_case   :				int				 =   list(_snake_case						)

       snake_case   :				Any				 =   self.image_processor(_snake_case						,     return_tensors=self.framework						)
       return model_inputs







   def 			lowerCamelCase		(     self						,     UpperCamelCase__						)     ->		Dict:

       '''simple docstring'''




       snake_case   :				int				 =   self.model(**_snake_case						)
       return model_outputs







   def 			lowerCamelCase		(     self						,     UpperCamelCase__						,     UpperCamelCase__=5						)     ->		Tuple:

       '''simple docstring'''




       if top_k > self.model.config.num_labels:
           snake_case   :				List[str]				 =   self.model.config.num_labels

       if self.framework == "pt":
           snake_case   :				str				 =   model_outputs.logits.softmax(-1						)[0]
           snake_case   :				Optional[Any]				 =   probs.topk(_snake_case						)
       else:
           raise ValueError(F'Unsupported framework: {self.framework}'						)

       snake_case   :				int				 =   scores.tolist()
       snake_case   :				Tuple				 =   ids.tolist()
       return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(_snake_case						,     _snake_case						)]










"""simple docstring"""



def   __lowerCAmelCase						(						lowercase  :  int						,							lowercase  :  int						,							lowercase  :  list[list[int]]			)     ->						int:


    """simple docstring"""





    def update_area_of_max_square(lowercase  :  int						,							lowercase  :  int			) -> int:
        # BASE CASE
        if row >= rows or col >= cols:
            return 0

        snake_case   :				Dict				 =   update_area_of_max_square(lowercase						,							col + 1			)
        snake_case   :				Tuple				 =   update_area_of_max_square(row + 1						,							col + 1			)
        snake_case   :				Any				 =   update_area_of_max_square(row + 1						,							lowercase			)

        if mat[row][col]:
            snake_case   :				List[Any]				 =   1 + min([right, diagonal, down]			)
            snake_case   :				Any				 =   max(largest_square_area[0]						,							lowercase			)
            return sub_problem_sol
        else:
            return 0

    snake_case   :				int				 =   [0]
    update_area_of_max_square(0						,							0			)
    return largest_square_area[0]







def   __lowerCAmelCase						(						lowercase  :  int						,							lowercase  :  int						,							lowercase  :  list[list[int]]			)     ->						int:


    """simple docstring"""





    def update_area_of_max_square_using_dp_array(
        lowercase  :  int						,							lowercase  :  int						,							lowercase  :  list[list[int]]			) -> int:
        if row >= rows or col >= cols:
            return 0
        if dp_array[row][col] != -1:
            return dp_array[row][col]

        snake_case   :				List[str]				 =   update_area_of_max_square_using_dp_array(lowercase						,							col + 1						,							lowercase			)
        snake_case   :				Optional[int]				 =   update_area_of_max_square_using_dp_array(row + 1						,							col + 1						,							lowercase			)
        snake_case   :				Optional[int]				 =   update_area_of_max_square_using_dp_array(row + 1						,							lowercase						,							lowercase			)

        if mat[row][col]:
            snake_case   :				Dict				 =   1 + min([right, diagonal, down]			)
            snake_case   :				Union[str, Any]				 =   max(largest_square_area[0]						,							lowercase			)
            snake_case   :				str				 =   sub_problem_sol
            return sub_problem_sol
        else:
            return 0

    snake_case   :				Union[str, Any]				 =   [0]
    snake_case   :				int				 =   [[-1] * cols for _ in range(lowercase			)]
    update_area_of_max_square_using_dp_array(0						,							0						,							lowercase			)

    return largest_square_area[0]







def   __lowerCAmelCase						(						lowercase  :  int						,							lowercase  :  int						,							lowercase  :  list[list[int]]			)     ->						int:


    """simple docstring"""





    snake_case   :				int				 =   [[0] * (cols + 1) for _ in range(rows + 1			)]
    snake_case   :				List[Any]				 =   0
    for row in range(rows - 1						,							-1						,							-1			):
        for col in range(cols - 1						,							-1						,							-1			):
            snake_case   :				Tuple				 =   dp_array[row][col + 1]
            snake_case   :				Any				 =   dp_array[row + 1][col + 1]
            snake_case   :				List[str]				 =   dp_array[row + 1][col]

            if mat[row][col] == 1:
                snake_case   :				Optional[int]				 =   1 + min(lowercase						,							lowercase						,							lowercase			)
                snake_case   :				Tuple				 =   max(dp_array[row][col]						,							lowercase			)
            else:
                snake_case   :				List[Any]				 =   0

    return largest_square_area







def   __lowerCAmelCase						(						lowercase  :  int						,							lowercase  :  int						,							lowercase  :  list[list[int]]			)     ->						int:


    """simple docstring"""





    snake_case   :				Any				 =   [0] * (cols + 1)
    snake_case   :				Any				 =   [0] * (cols + 1)
    snake_case   :				Any				 =   0
    for row in range(rows - 1						,							-1						,							-1			):
        for col in range(cols - 1						,							-1						,							-1			):
            snake_case   :				Dict				 =   current_row[col + 1]
            snake_case   :				List[Any]				 =   next_row[col + 1]
            snake_case   :				Dict				 =   next_row[col]

            if mat[row][col] == 1:
                snake_case   :				Union[str, Any]				 =   1 + min(lowercase						,							lowercase						,							lowercase			)
                snake_case   :				Optional[int]				 =   max(current_row[col]						,							lowercase			)
            else:
                snake_case   :				Optional[Any]				 =   0
        snake_case   :				str				 =   current_row

    return largest_square_area


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  print(largest_square_area_in_matrix_bottom_up(2, 2, [[1, 1], [1, 1]]))





