



'''simple docstring'''


import unittest

from .lib import (
    Matrix,
    Vector,
    axpy,
    square_zero_matrix,
    unit_basis_vector,
    zero_vector,
)

class  SCREAMING_SNAKE_CASE (  unittest.TestCase		):






    """simple docstring"""





    def  A       (  self      :					Tuple ):


       """simple docstring"""







       UpperCamelCase					=  Vector([1, 2, 3] )
       self.assertEqual(x.component(0 )  ,						1 )
       self.assertEqual(x.component(2 )  ,						3 )
       UpperCamelCase					=  Vector()






    def  A       (  self      :					Any ):


       """simple docstring"""







       UpperCamelCase					=  Vector([0, 0, 0, 0, 0, 1] )
       self.assertEqual(str(UpperCamelCase__ )  ,						'(0,0,0,0,0,1)' )






    def  A       (  self      :					Dict ):


       """simple docstring"""







       UpperCamelCase					=  Vector([1, 2, 3, 4] )
       self.assertEqual(len(UpperCamelCase__ )  ,						4 )






    def  A       (  self      :					Dict ):


       """simple docstring"""







       UpperCamelCase					=  Vector([1, 2] )
       UpperCamelCase					=  Vector([1, 2, 3, 4, 5] )
       UpperCamelCase					=  Vector([0, 0, 0, 0, 0, 0, 0, 0, 0, 0] )
       UpperCamelCase					=  Vector([1, -1, 1, -1, 2, -3, 4, -5] )
       self.assertAlmostEqual(x.euclidean_length()  ,						2.2_3_6  ,						3 )
       self.assertAlmostEqual(y.euclidean_length()  ,						7.4_1_6  ,						3 )
       self.assertEqual(z.euclidean_length()  ,						0 )
       self.assertAlmostEqual(w.euclidean_length()  ,						7.6_1_6  ,						3 )






    def  A       (  self      :					List[Any] ):


       """simple docstring"""







       UpperCamelCase					=  Vector([1, 2, 3] )
       UpperCamelCase					=  Vector([1, 1, 1] )
       self.assertEqual((x + y).component(0 )  ,						2 )
       self.assertEqual((x + y).component(1 )  ,						3 )
       self.assertEqual((x + y).component(2 )  ,						4 )






    def  A       (  self      :					Any ):


       """simple docstring"""







       UpperCamelCase					=  Vector([1, 2, 3] )
       UpperCamelCase					=  Vector([1, 1, 1] )
       self.assertEqual((x - y).component(0 )  ,						0 )
       self.assertEqual((x - y).component(1 )  ,						1 )
       self.assertEqual((x - y).component(2 )  ,						2 )






    def  A       (  self      :					Tuple ):


       """simple docstring"""







       UpperCamelCase					=  Vector([1, 2, 3] )
       UpperCamelCase					=  Vector([2, -1, 4] )  # for test of dot product
       UpperCamelCase					=  Vector([1, -2, -1] )
       self.assertEqual(str(x * 3.0 )  ,						'(3.0,6.0,9.0)' )
       self.assertEqual((a * b)  ,						0 )






    def  A       (  self      :					Dict ):


       """simple docstring"""







       self.assertEqual(str(zero_vector(1_0 ) ).count('0' )  ,						1_0 )






    def  A       (  self      :					Union[str, Any] ):


       """simple docstring"""







       self.assertEqual(str(unit_basis_vector(3  ,						1 ) )  ,						'(0,1,0)' )






    def  A       (  self      :					str ):


       """simple docstring"""







       UpperCamelCase					=  Vector([1, 2, 3] )
       UpperCamelCase					=  Vector([1, 0, 1] )
       self.assertEqual(str(axpy(2  ,						UpperCamelCase__  ,						UpperCamelCase__ ) )  ,						'(3,4,7)' )






    def  A       (  self      :					Optional[Any] ):


       """simple docstring"""







       UpperCamelCase					=  Vector([1, 0, 0, 0, 0, 0] )
       UpperCamelCase					=  x.copy()
       self.assertEqual(str(UpperCamelCase__ )  ,						str(UpperCamelCase__ ) )






    def  A       (  self      :					List[str] ):


       """simple docstring"""







       UpperCamelCase					=  Vector([1, 0, 0] )
       x.change_component(0  ,						0 )
       x.change_component(1  ,						1 )
       self.assertEqual(str(UpperCamelCase__ )  ,						'(0,1,0)' )






    def  A       (  self      :					Optional[Any] ):


       """simple docstring"""







       UpperCamelCase					=  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]  ,						3  ,						3 )
       self.assertEqual('|1,2,3|\n|2,4,5|\n|6,7,8|\n'  ,						str(UpperCamelCase__ ) )






    def  A       (  self      :					Any ):


       """simple docstring"""







       UpperCamelCase					=  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]  ,						3  ,						3 )
       UpperCamelCase					=  [[-3, -1_4, -1_0], [-5, -1_0, -5], [-2, -1, 0]]
       for x in range(a.height() ):
          for y in range(a.width() ):
             self.assertEqual(minors[x][y]  ,						a.minor(UpperCamelCase__  ,						UpperCamelCase__ ) )






    def  A       (  self      :					Union[str, Any] ):


       """simple docstring"""







       UpperCamelCase					=  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]  ,						3  ,						3 )
       UpperCamelCase					=  [[-3, 1_4, -1_0], [5, -1_0, 5], [-2, 1, 0]]
       for x in range(a.height() ):
          for y in range(a.width() ):
             self.assertEqual(cofactors[x][y]  ,						a.cofactor(UpperCamelCase__  ,						UpperCamelCase__ ) )






    def  A       (  self      :					List[Any] ):


       """simple docstring"""







       UpperCamelCase					=  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]  ,						3  ,						3 )
       self.assertEqual(-5  ,						a.determinant() )






    def  A       (  self      :					List[str] ):


       """simple docstring"""







       UpperCamelCase					=  Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]  ,						3  ,						3 )
       UpperCamelCase					=  Vector([1, 2, 3] )
       self.assertEqual('(14,32,50)'  ,						str(a * x ) )
       self.assertEqual('|2,4,6|\n|8,10,12|\n|14,16,18|\n'  ,						str(a * 2 ) )






    def  A       (  self      :					Optional[Any] ):


       """simple docstring"""







       UpperCamelCase					=  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]  ,						3  ,						3 )
       a.change_component(0  ,						2  ,						5 )
       self.assertEqual('|1,2,5|\n|2,4,5|\n|6,7,8|\n'  ,						str(UpperCamelCase__ ) )






    def  A       (  self      :					List[str] ):


       """simple docstring"""







       UpperCamelCase					=  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]  ,						3  ,						3 )
       self.assertEqual(7  ,						a.component(2  ,						1 )  ,						0.0_1 )






    def  A       (  self      :					List[str] ):


       """simple docstring"""







       UpperCamelCase					=  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]  ,						3  ,						3 )
       UpperCamelCase					=  Matrix([[1, 2, 7], [2, 4, 5], [6, 7, 1_0]]  ,						3  ,						3 )
       self.assertEqual('|2,4,10|\n|4,8,10|\n|12,14,18|\n'  ,						str(a + b ) )






    def  A       (  self      :					List[str] ):


       """simple docstring"""







       UpperCamelCase					=  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]  ,						3  ,						3 )
       UpperCamelCase					=  Matrix([[1, 2, 7], [2, 4, 5], [6, 7, 1_0]]  ,						3  ,						3 )
       self.assertEqual('|0,0,-4|\n|0,0,0|\n|0,0,-2|\n'  ,						str(a - b ) )






    def  A       (  self      :					List[str] ):


       """simple docstring"""







       self.assertEqual(
           '|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n'  ,						str(square_zero_matrix(5 ) )  ,						)


if __name__ == "__main__":
   unittest.main()






'''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

_lowerCamelCase	:       Any      	=	logging.get_logger(__name__)

@add_end_docstrings(_a		)
class  SCREAMING_SNAKE_CASE (  _a		):






    """simple docstring"""





    def __init__(  self      :					Any  ,						*UpperCamelCase__      :					Dict  ,						**UpperCamelCase__      :					Union[str, Any] ):


       """simple docstring"""







       super().__init__(*UpperCamelCase__  ,						**UpperCamelCase__ )
       requires_backends(self  ,						'decord' )
       self.check_model_type(UpperCamelCase__ )






    def  A       (  self      :					Optional[int]  ,						UpperCamelCase__      :					Optional[int]=None  ,						UpperCamelCase__      :					Optional[Any]=None  ,						UpperCamelCase__      :					Optional[Any]=None ):


       """simple docstring"""







       UpperCamelCase					=  {}
       if frame_sampling_rate is not None:
          UpperCamelCase					=  frame_sampling_rate
       if num_frames is not None:
          UpperCamelCase					=  num_frames

       UpperCamelCase					=  {}
       if top_k is not None:
          UpperCamelCase					=  top_k
       return preprocess_params, {}, postprocess_params






    def __call__(  self      :					List[str]  ,						UpperCamelCase__      :					Union[str, List[str]]  ,						**UpperCamelCase__      :					Dict ):


       """simple docstring"""







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






    def  A       (  self      :					Tuple  ,						UpperCamelCase__      :					Union[str, Any]  ,						UpperCamelCase__      :					Tuple=None  ,						UpperCamelCase__      :					Tuple=1 ):


       """simple docstring"""







       if num_frames is None:
          UpperCamelCase					=  self.model.config.num_frames

       if video.startswith('http://' ) or video.startswith('https://' ):
          UpperCamelCase					=  BytesIO(requests.get(UpperCamelCase__ ).content )

       UpperCamelCase					=  VideoReader(UpperCamelCase__ )
       videoreader.seek(0 )

       UpperCamelCase					=  0
       UpperCamelCase					=  num_frames * frame_sampling_rate - 1
       UpperCamelCase					=  np.linspace(UpperCamelCase__  ,						UpperCamelCase__  ,						num=UpperCamelCase__  ,						dtype=np.intaa )

       UpperCamelCase					=  videoreader.get_batch(UpperCamelCase__ ).asnumpy()
       UpperCamelCase					=  list(UpperCamelCase__ )

       UpperCamelCase					=  self.image_processor(UpperCamelCase__  ,						return_tensors=self.framework )
       return model_inputs






    def  A       (  self      :					Union[str, Any]  ,						UpperCamelCase__      :					List[str] ):


       """simple docstring"""







       UpperCamelCase					=  self.model(**UpperCamelCase__ )
       return model_outputs






    def  A       (  self      :					int  ,						UpperCamelCase__      :					str  ,						UpperCamelCase__      :					List[Any]=5 ):


       """simple docstring"""







       if top_k > self.model.config.num_labels:
          UpperCamelCase					=  self.model.config.num_labels

       if self.framework == "pt":
          UpperCamelCase					=  model_outputs.logits.softmax(-1 )[0]
          UpperCamelCase				,      UpperCamelCase					=  probs.topk(UpperCamelCase__ )
       else:
          raise ValueError(f"""Unsupported framework: {self.framework}""" )

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

