





'''simple docstring'''




import copy
import os
from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Union


if TYPE_CHECKING:
  from ...processing_utils import ProcessorMixin
  from ...utils import TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowercase__    :      Tuple						=    logging.get_logger(__name__)

lowercase__    :      List[Any]						=    {
    '''google/owlvit-base-patch32''': '''https://huggingface.co/google/owlvit-base-patch32/resolve/main/config.json''',
    '''google/owlvit-base-patch16''': '''https://huggingface.co/google/owlvit-base-patch16/resolve/main/config.json''',
    '''google/owlvit-large-patch14''': '''https://huggingface.co/google/owlvit-large-patch14/resolve/main/config.json''',
}


class  SCREAMING_SNAKE_CASE    (a__							):
     lowerCAmelCase					=       '''owlvit_text_model'''


     def __init__(						self						,	_UpperCAmelCase=4_9408						,	_UpperCAmelCase=512						,	_UpperCAmelCase=2048						,	_UpperCAmelCase=12						,	_UpperCAmelCase=8						,	_UpperCAmelCase=16						,	_UpperCAmelCase="quick_gelu"						,	_UpperCAmelCase=1e-5						,	_UpperCAmelCase=0.0						,	_UpperCAmelCase=0.02						,	_UpperCAmelCase=1.0						,	_UpperCAmelCase=0						,	_UpperCAmelCase=4_9406						,	_UpperCAmelCase=4_9407						,	**_UpperCAmelCase						,	):

          '''simple docstring'''






          super().__init__(pad_token_id=_UpperCAmelCase						,	bos_token_id=_UpperCAmelCase						,	eos_token_id=_UpperCAmelCase						,	**_UpperCAmelCase)

          __A						: Optional[int]      =       vocab_size
          __A						: List[str]      =       hidden_size
          __A						: Dict      =       intermediate_size
          __A						: Optional[Any]      =       num_hidden_layers
          __A						: Any      =       num_attention_heads
          __A						: Dict      =       max_position_embeddings
          __A						: Dict      =       hidden_act
          __A						: Tuple      =       layer_norm_eps
          __A						: Dict      =       attention_dropout
          __A						: List[str]      =       initializer_range
          __A						: Optional[Any]      =       initializer_factor


     @classmethod
     def 							SCREAMING_SNAKE_CASE  (						cls						,	_UpperCAmelCase						,	**_UpperCAmelCase):

          '''simple docstring'''






          cls._set_token_in_kwargs(_UpperCAmelCase)

          __A ,__A						: Optional[int]      =       cls.get_config_dict(_UpperCAmelCase						,	**_UpperCAmelCase)

          # get the text config dict if we are loading from OwlViTConfig
          if config_dict.get('model_type') == "owlvit":
               __A						: str      =       config_dict['text_config']

          if "model_type" in config_dict and hasattr(cls						,	'model_type') and config_dict["model_type"] != cls.model_type:
               logger.warning(
                   F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
                   F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.')

          return cls.from_dict(_UpperCAmelCase						,	**_UpperCAmelCase)




class  SCREAMING_SNAKE_CASE    (a__							):
     lowerCAmelCase					=       '''owlvit_vision_model'''


     def __init__(						self						,	_UpperCAmelCase=768						,	_UpperCAmelCase=3072						,	_UpperCAmelCase=12						,	_UpperCAmelCase=12						,	_UpperCAmelCase=3						,	_UpperCAmelCase=768						,	_UpperCAmelCase=32						,	_UpperCAmelCase="quick_gelu"						,	_UpperCAmelCase=1e-5						,	_UpperCAmelCase=0.0						,	_UpperCAmelCase=0.02						,	_UpperCAmelCase=1.0						,	**_UpperCAmelCase						,	):

          '''simple docstring'''






          super().__init__(**_UpperCAmelCase)

          __A						: int      =       hidden_size
          __A						: Optional[Any]      =       intermediate_size
          __A						: Optional[Any]      =       num_hidden_layers
          __A						: Optional[Any]      =       num_attention_heads
          __A						: Optional[int]      =       num_channels
          __A						: List[str]      =       image_size
          __A						: str      =       patch_size
          __A						: Tuple      =       hidden_act
          __A						: Optional[int]      =       layer_norm_eps
          __A						: Optional[int]      =       attention_dropout
          __A						: Optional[int]      =       initializer_range
          __A						: int      =       initializer_factor


     @classmethod
     def 							SCREAMING_SNAKE_CASE  (						cls						,	_UpperCAmelCase						,	**_UpperCAmelCase):

          '''simple docstring'''






          cls._set_token_in_kwargs(_UpperCAmelCase)

          __A ,__A						: int      =       cls.get_config_dict(_UpperCAmelCase						,	**_UpperCAmelCase)

          # get the vision config dict if we are loading from OwlViTConfig
          if config_dict.get('model_type') == "owlvit":
               __A						: Dict      =       config_dict['vision_config']

          if "model_type" in config_dict and hasattr(cls						,	'model_type') and config_dict["model_type"] != cls.model_type:
               logger.warning(
                   F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
                   F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.')

          return cls.from_dict(_UpperCAmelCase						,	**_UpperCAmelCase)




class  SCREAMING_SNAKE_CASE    (a__							):
     lowerCAmelCase					=       '''owlvit'''
     lowerCAmelCase					=       True


     def __init__(						self						,	_UpperCAmelCase=None						,	_UpperCAmelCase=None						,	_UpperCAmelCase=512						,	_UpperCAmelCase=2.6592						,	_UpperCAmelCase=True						,	**_UpperCAmelCase						,	):

          '''simple docstring'''






          super().__init__(**_UpperCAmelCase)

          if text_config is None:
               __A						: List[str]      =       {}
               logger.info('text_config is None. Initializing the OwlViTTextConfig with default values.')

          if vision_config is None:
               __A						: Dict      =       {}
               logger.info('vision_config is None. initializing the OwlViTVisionConfig with default values.')

          __A						: List[str]      =       OwlViTTextConfig(**_UpperCAmelCase)
          __A						: Optional[int]      =       OwlViTVisionConfig(**_UpperCAmelCase)

          __A						: Dict      =       projection_dim
          __A						: List[str]      =       logit_scale_init_value
          __A						: List[Any]      =       return_dict
          __A						: Dict      =       1.0


     @classmethod
     def 							SCREAMING_SNAKE_CASE  (						cls						,	_UpperCAmelCase						,	**_UpperCAmelCase):

          '''simple docstring'''






          cls._set_token_in_kwargs(_UpperCAmelCase)

          __A ,__A						: List[Any]      =       cls.get_config_dict(_UpperCAmelCase						,	**_UpperCAmelCase)

          if "model_type" in config_dict and hasattr(cls						,	'model_type') and config_dict["model_type"] != cls.model_type:
               logger.warning(
                   F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
                   F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.')

          return cls.from_dict(_UpperCAmelCase						,	**_UpperCAmelCase)


     @classmethod
     def 							SCREAMING_SNAKE_CASE  (						cls						,	_UpperCAmelCase						,	_UpperCAmelCase						,	**_UpperCAmelCase):

          '''simple docstring'''






          __A						: List[str]      =       {}
          __A						: List[Any]      =       text_config
          __A						: str      =       vision_config

          return cls.from_dict(_UpperCAmelCase						,	**_UpperCAmelCase)


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          __A						: Optional[Any]      =       copy.deepcopy(self.__dict__)
          __A						: List[Any]      =       self.text_config.to_dict()
          __A						: Optional[int]      =       self.vision_config.to_dict()
          __A						: Tuple      =       self.__class__.model_type
          return output




class  SCREAMING_SNAKE_CASE    (a__							):


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return OrderedDict(
              [
                  ('input_ids', {0: 'batch', 1: 'sequence'}),
                  ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
                  ('attention_mask', {0: 'batch', 1: 'sequence'}),
              ])


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return OrderedDict(
              [
                  ('logits_per_image', {0: 'batch'}),
                  ('logits_per_text', {0: 'batch'}),
                  ('text_embeds', {0: 'batch'}),
                  ('image_embeds', {0: 'batch'}),
              ])


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return 1e-4


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase						,	_UpperCAmelCase = -1						,	_UpperCAmelCase = -1						,	_UpperCAmelCase = None						,	):

          '''simple docstring'''






          __A						: Optional[Any]      =       super().generate_dummy_inputs(
              processor.tokenizer						,	batch_size=_UpperCAmelCase						,	seq_length=_UpperCAmelCase						,	framework=_UpperCAmelCase)
          __A						: Any      =       super().generate_dummy_inputs(
              processor.image_processor						,	batch_size=_UpperCAmelCase						,	framework=_UpperCAmelCase)
          return {**text_input_dict, **image_input_dict}


     @property
     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






          return 14






'''simple docstring'''




from __future__ import annotations

from numpy import array, cos, cross, floataa, radians, sin
from numpy.typing import NDArray






def        _lowerCAmelCase			(  __snake_case  : float ,							__snake_case  : float ,							__snake_case  : bool = False			)     ->     list[float]:
     if radian_mode:
          return [magnitude * cos(__snake_case			), magnitude * sin(__snake_case			)]
     return [magnitude * cos(radians(__snake_case			)			), magnitude * sin(radians(__snake_case			)			)]






def        _lowerCAmelCase			(  __snake_case  : NDArray[floataa] ,							__snake_case  : NDArray[floataa] ,							__snake_case  : float = 10**-1			)     ->     bool:
     __A						: NDArray[floataa]      =       cross(__snake_case ,							__snake_case			)
     __A						: float      =       sum(__snake_case			)
     return abs(__snake_case			) < eps


if __name__ == "__main__":
  # Test to check if it works
  lowercase__    :      List[Any]						=    array(
      [
          polar_force(718.4, 1_80 - 30),
          polar_force(879.54, 45),
          polar_force(1_00, -90),
      ]
  )

  lowercase__    :      NDArray[floataa]						=    array([[0, 0], [0, 0], [0, 0]])

  assert in_static_equilibrium(forces, location)

  # Problem 1 in image_data/2D_problems.jpg
  lowercase__    :      Dict						=    array(
      [
          polar_force(30 * 9.81, 15),
          polar_force(2_15, 1_80 - 45),
          polar_force(2_64, 90 - 30),
      ]
  )

  lowercase__    :      Any						=    array([[0, 0], [0, 0], [0, 0]])

  assert in_static_equilibrium(forces, location)

  # Problem in image_data/2D_problems_1.jpg
  lowercase__    :      Optional[int]						=    array([[0, -20_00], [0, -12_00], [0, 1_56_00], [0, -1_24_00]])

  lowercase__    :      Optional[int]						=    array([[0, 0], [6, 0], [10, 0], [12, 0]])

  assert in_static_equilibrium(forces, location)

  import doctest

  doctest.testmod()