



"""simple docstring"""
import collections
import inspect
import unittest

from transformers import SwinvaConfig
from transformers.testing_utils import require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch
      from torch import nn

      from transformers import SwinvaForImageClassification, SwinvaForMaskedImageModeling, SwinvaModel
      from transformers.models.swinva.modeling_swinva import SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor



class       SCREAMING_SNAKE_CASE__  :

   def __init__(   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE=13      ,     _SCREAMING_SNAKE_CASE=32      ,     _SCREAMING_SNAKE_CASE=2      ,     _SCREAMING_SNAKE_CASE=3      ,     _SCREAMING_SNAKE_CASE=16      ,     _SCREAMING_SNAKE_CASE=[1, 2, 1]      ,     _SCREAMING_SNAKE_CASE=[2, 2, 4]      ,     _SCREAMING_SNAKE_CASE=2      ,     _SCREAMING_SNAKE_CASE=2.0      ,     _SCREAMING_SNAKE_CASE=True      ,     _SCREAMING_SNAKE_CASE=0.0      ,     _SCREAMING_SNAKE_CASE=0.0      ,     _SCREAMING_SNAKE_CASE=0.1      ,     _SCREAMING_SNAKE_CASE="gelu"      ,     _SCREAMING_SNAKE_CASE=False      ,     _SCREAMING_SNAKE_CASE=True      ,     _SCREAMING_SNAKE_CASE=0.02      ,     _SCREAMING_SNAKE_CASE=1E-5      ,     _SCREAMING_SNAKE_CASE=True      ,     _SCREAMING_SNAKE_CASE=None      ,     _SCREAMING_SNAKE_CASE=True      ,     _SCREAMING_SNAKE_CASE=10      ,     _SCREAMING_SNAKE_CASE=8      ,     )  ->      List[str]:





    '''simple docstring'''




    UpperCAmelCase	:					str	=	parent
    UpperCAmelCase	:					str	=	batch_size
    UpperCAmelCase	:					int	=	image_size
    UpperCAmelCase	:					str	=	patch_size
    UpperCAmelCase	:					Any	=	num_channels
    UpperCAmelCase	:					Dict	=	embed_dim
    UpperCAmelCase	:					Any	=	depths
    UpperCAmelCase	:					str	=	num_heads
    UpperCAmelCase	:					Optional[Any]	=	window_size
    UpperCAmelCase	:					int	=	mlp_ratio
    UpperCAmelCase	:					Any	=	qkv_bias
    UpperCAmelCase	:					Union[str, Any]	=	hidden_dropout_prob
    UpperCAmelCase	:					List[Any]	=	attention_probs_dropout_prob
    UpperCAmelCase	:					Any	=	drop_path_rate
    UpperCAmelCase	:					List[Any]	=	hidden_act
    UpperCAmelCase	:					Tuple	=	use_absolute_embeddings
    UpperCAmelCase	:					Optional[Any]	=	patch_norm
    UpperCAmelCase	:					Tuple	=	layer_norm_eps
    UpperCAmelCase	:					List[Any]	=	initializer_range
    UpperCAmelCase	:					Optional[int]	=	is_training
    UpperCAmelCase	:					Any	=	scope
    UpperCAmelCase	:					List[str]	=	use_labels
    UpperCAmelCase	:					Union[str, Any]	=	type_sequence_label_size
    UpperCAmelCase	:					Any	=	encoder_stride

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Any:





    '''simple docstring'''




    UpperCAmelCase	:					str	=	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

    UpperCAmelCase	:					Optional[Any]	=	None
    if self.use_labels:
     UpperCAmelCase	:					Tuple	=	ids_tensor([self.batch_size]      ,     self.type_sequence_label_size						)

    UpperCAmelCase	:					Any	=	self.get_config()

    return config, pixel_values, labels

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Optional[int]:





    '''simple docstring'''




    return SwinvaConfig(
        image_size=self.image_size      ,     patch_size=self.patch_size      ,     num_channels=self.num_channels      ,     embed_dim=self.embed_dim      ,     depths=self.depths      ,     num_heads=self.num_heads      ,     window_size=self.window_size      ,     mlp_ratio=self.mlp_ratio      ,     qkv_bias=self.qkv_bias      ,     hidden_dropout_prob=self.hidden_dropout_prob      ,     attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,     drop_path_rate=self.drop_path_rate      ,     hidden_act=self.hidden_act      ,     use_absolute_embeddings=self.use_absolute_embeddings      ,     path_norm=self.patch_norm      ,     layer_norm_eps=self.layer_norm_eps      ,     initializer_range=self.initializer_range      ,     encoder_stride=self.encoder_stride      ,     )

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)  ->      List[str]:





    '''simple docstring'''




    UpperCAmelCase	:					Tuple	=	SwinvaModel(config=_SCREAMING_SNAKE_CASE						)
    model.to(_SCREAMING_SNAKE_CASE						)
    model.eval()
    UpperCAmelCase	:					str	=	model(_SCREAMING_SNAKE_CASE						)

    UpperCAmelCase	:					List[Any]	=	((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths						) - 1))
    UpperCAmelCase	:					str	=	int(config.embed_dim * 2 ** (len(config.depths						) - 1)						)

    self.parent.assertEqual(result.last_hidden_state.shape      ,     (self.batch_size, expected_seq_len, expected_dim)						)

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)  ->      str:





    '''simple docstring'''




    UpperCAmelCase	:					int	=	SwinvaForMaskedImageModeling(config=_SCREAMING_SNAKE_CASE						)
    model.to(_SCREAMING_SNAKE_CASE						)
    model.eval()
    UpperCAmelCase	:					List[Any]	=	model(_SCREAMING_SNAKE_CASE						)
    self.parent.assertEqual(
        result.logits.shape      ,     (self.batch_size, self.num_channels, self.image_size, self.image_size)						)

    # test greyscale images
    UpperCAmelCase	:					List[Any]	=	1
    UpperCAmelCase	:					Tuple	=	SwinvaForMaskedImageModeling(_SCREAMING_SNAKE_CASE						)
    model.to(_SCREAMING_SNAKE_CASE						)
    model.eval()

    UpperCAmelCase	:					Optional[Any]	=	floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
    UpperCAmelCase	:					Union[str, Any]	=	model(_SCREAMING_SNAKE_CASE						)
    self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, 1, self.image_size, self.image_size)						)

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)  ->      int:





    '''simple docstring'''




    UpperCAmelCase	:					Union[str, Any]	=	self.type_sequence_label_size
    UpperCAmelCase	:					str	=	SwinvaForImageClassification(_SCREAMING_SNAKE_CASE						)
    model.to(_SCREAMING_SNAKE_CASE						)
    model.eval()
    UpperCAmelCase	:					Optional[Any]	=	model(_SCREAMING_SNAKE_CASE      ,     labels=_SCREAMING_SNAKE_CASE						)
    self.parent.assertEqual(result.logits.shape      ,     (self.batch_size, self.type_sequence_label_size)						)




   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Optional[int]:





    '''simple docstring'''




    UpperCAmelCase	:					Tuple	=	self.prepare_config_and_inputs()
    UpperCAmelCase	,		UpperCAmelCase	,		UpperCAmelCase	:					Optional[int]	=	config_and_inputs
    UpperCAmelCase	:					Dict	=	{"""pixel_values""": pixel_values}
    return config, inputs_dict



@require_torch
class       SCREAMING_SNAKE_CASE__  (					UpperCAmelCase__      ,			UpperCAmelCase__      ,			unittest.TestCase ):
   __lowerCAmelCase  :   Tuple						=						(
       (SwinvaModel, SwinvaForImageClassification, SwinvaForMaskedImageModeling) if is_torch_available() else ()
   )
   __lowerCAmelCase  :   Union[str, Any]						=						(
       {'feature-extraction': SwinvaModel, 'image-classification': SwinvaForImageClassification}
       if is_torch_available()
       else {}
   )

   __lowerCAmelCase  :   Dict						=						False
   __lowerCAmelCase  :   Optional[Any]						=						False
   __lowerCAmelCase  :   Optional[int]						=						False
   __lowerCAmelCase  :   str						=						False

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Optional[Any]:





    '''simple docstring'''




    UpperCAmelCase	:					str	=	SwinvaModelTester(self						)
    UpperCAmelCase	:					Tuple	=	ConfigTester(self      ,     config_class=_SCREAMING_SNAKE_CASE      ,     embed_dim=37						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      int:





    '''simple docstring'''




    self.config_tester.create_and_test_config_to_json_string()
    self.config_tester.create_and_test_config_to_json_file()
    self.config_tester.create_and_test_config_from_and_save_pretrained()
    self.config_tester.create_and_test_config_with_num_labels()
    self.config_tester.check_config_can_be_init_without_params()
    self.config_tester.check_config_arguments_init()

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      int:





    '''simple docstring'''




    UpperCAmelCase	:					List[Any]	=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*_SCREAMING_SNAKE_CASE						)

   @unittest.skip(reason="""Got `CUDA error: misaligned address` with PyTorch 2.0.0."""						)
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Union[str, Any]:





    '''simple docstring'''




    pass

   @unittest.skip(reason="""Swinv2 does not use inputs_embeds"""						)
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Optional[int]:





    '''simple docstring'''




    pass

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      List[Any]:





    '''simple docstring'''




    UpperCAmelCase	,		UpperCAmelCase	:					str	=	self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
     UpperCAmelCase	:					int	=	model_class(_SCREAMING_SNAKE_CASE						)
     self.assertIsInstance(model.get_input_embeddings()      ,     (nn.Module)						)
     UpperCAmelCase	:					List[str]	=	model.get_output_embeddings()
     self.assertTrue(x is None or isinstance(_SCREAMING_SNAKE_CASE      ,     nn.Linear						)						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      List[str]:





    '''simple docstring'''




    UpperCAmelCase	,		UpperCAmelCase	:					Any	=	self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
     UpperCAmelCase	:					List[str]	=	model_class(_SCREAMING_SNAKE_CASE						)
     UpperCAmelCase	:					List[str]	=	inspect.signature(model.forward						)
     # signature.parameters is an OrderedDict => so arg_names order is deterministic
     UpperCAmelCase	:					List[str]	=	[*signature.parameters.keys()]

     UpperCAmelCase	:					int	=	["""pixel_values"""]
     self.assertListEqual(arg_names[:1]      ,     _SCREAMING_SNAKE_CASE						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Tuple:





    '''simple docstring'''




    UpperCAmelCase	,		UpperCAmelCase	:					List[str]	=	self.model_tester.prepare_config_and_inputs_for_common()
    UpperCAmelCase	:					List[str]	=	True

    for model_class in self.all_model_classes:
     UpperCAmelCase	:					str	=	True
     UpperCAmelCase	:					str	=	False
     UpperCAmelCase	:					Dict	=	True
     UpperCAmelCase	:					Dict	=	model_class(_SCREAMING_SNAKE_CASE						)
     model.to(_SCREAMING_SNAKE_CASE						)
     model.eval()
     with torch.no_grad():
      UpperCAmelCase	:					Union[str, Any]	=	model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)						)
     UpperCAmelCase	:					Any	=	outputs.attentions
     UpperCAmelCase	:					Tuple	=	len(self.model_tester.depths						)
     self.assertEqual(len(_SCREAMING_SNAKE_CASE						)      ,     _SCREAMING_SNAKE_CASE						)

     # check that output_attentions also work using config
     del inputs_dict["output_attentions"]
     UpperCAmelCase	:					Any	=	True
     UpperCAmelCase	:					Optional[int]	=	config.window_size**2
     UpperCAmelCase	:					Dict	=	model_class(_SCREAMING_SNAKE_CASE						)
     model.to(_SCREAMING_SNAKE_CASE						)
     model.eval()
     with torch.no_grad():
      UpperCAmelCase	:					Optional[int]	=	model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)						)
     UpperCAmelCase	:					Dict	=	outputs.attentions
     self.assertEqual(len(_SCREAMING_SNAKE_CASE						)      ,     _SCREAMING_SNAKE_CASE						)

     self.assertListEqual(
         list(attentions[0].shape[-3:]						)      ,     [self.model_tester.num_heads[0], window_size_squared, window_size_squared]      ,     )
     UpperCAmelCase	:					Any	=	len(_SCREAMING_SNAKE_CASE						)

     # Check attention is always last and order is fine
     UpperCAmelCase	:					int	=	True
     UpperCAmelCase	:					int	=	True
     UpperCAmelCase	:					Union[str, Any]	=	model_class(_SCREAMING_SNAKE_CASE						)
     model.to(_SCREAMING_SNAKE_CASE						)
     model.eval()
     with torch.no_grad():
      UpperCAmelCase	:					int	=	model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)						)

     if hasattr(self.model_tester      ,     """num_hidden_states_types"""						):
      UpperCAmelCase	:					List[Any]	=	self.model_tester.num_hidden_states_types
     else:
      # also another +1 for reshaped_hidden_states
      UpperCAmelCase	:					List[Any]	=	2
     self.assertEqual(out_len + added_hidden_states      ,     len(_SCREAMING_SNAKE_CASE						)						)

     UpperCAmelCase	:					Optional[int]	=	outputs.attentions

     self.assertEqual(len(_SCREAMING_SNAKE_CASE						)      ,     _SCREAMING_SNAKE_CASE						)

     self.assertListEqual(
         list(self_attentions[0].shape[-3:]						)      ,     [self.model_tester.num_heads[0], window_size_squared, window_size_squared]      ,     )

   def 	SCREAMING_SNAKE_CASE     (   self      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)  ->      List[str]:





    '''simple docstring'''




    UpperCAmelCase	:					Dict	=	model_class(_SCREAMING_SNAKE_CASE						)
    model.to(_SCREAMING_SNAKE_CASE						)
    model.eval()

    with torch.no_grad():
     UpperCAmelCase	:					int	=	model(**self._prepare_for_class(_SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)						)

    UpperCAmelCase	:					List[Any]	=	outputs.hidden_states

    UpperCAmelCase	:					Optional[Any]	=	getattr(
        self.model_tester      ,     """expected_num_hidden_layers"""      ,     len(self.model_tester.depths						) + 1						)
    self.assertEqual(len(_SCREAMING_SNAKE_CASE						)      ,     _SCREAMING_SNAKE_CASE						)

    # Swinv2 has a different seq_length
    UpperCAmelCase	:					Union[str, Any]	=	(
        config.patch_size
        if isinstance(config.patch_size      ,     collections.abc.Iterable						)
        else (config.patch_size, config.patch_size)
    )

    UpperCAmelCase	:					Tuple	=	(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

    self.assertListEqual(
        list(hidden_states[0].shape[-2:]						)      ,     [num_patches, self.model_tester.embed_dim]      ,     )

    UpperCAmelCase	:					List[str]	=	outputs.reshaped_hidden_states
    self.assertEqual(len(_SCREAMING_SNAKE_CASE						)      ,     _SCREAMING_SNAKE_CASE						)

    UpperCAmelCase	,		UpperCAmelCase	,		UpperCAmelCase	,		UpperCAmelCase	:					Any	=	reshaped_hidden_states[0].shape
    UpperCAmelCase	:					List[str]	=	(
        reshaped_hidden_states[0].view(_SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     height * width						).permute(0      ,     2      ,     1						)
    )
    self.assertListEqual(
        list(reshaped_hidden_states.shape[-2:]						)      ,     [num_patches, self.model_tester.embed_dim]      ,     )

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Dict:





    '''simple docstring'''




    UpperCAmelCase	,		UpperCAmelCase	:					int	=	self.model_tester.prepare_config_and_inputs_for_common()

    UpperCAmelCase	:					Optional[int]	=	(
        self.model_tester.image_size
        if isinstance(self.model_tester.image_size      ,     collections.abc.Iterable						)
        else (self.model_tester.image_size, self.model_tester.image_size)
    )

    for model_class in self.all_model_classes:
     UpperCAmelCase	:					List[str]	=	True
     self.check_hidden_states_output(_SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)

     # check that output_hidden_states also work using config
     del inputs_dict["output_hidden_states"]
     UpperCAmelCase	:					Optional[Any]	=	True

     self.check_hidden_states_output(_SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      List[str]:





    '''simple docstring'''




    UpperCAmelCase	,		UpperCAmelCase	:					Any	=	self.model_tester.prepare_config_and_inputs_for_common()
    UpperCAmelCase	:					List[str]	=	3

    UpperCAmelCase	:					Union[str, Any]	=	(
        self.model_tester.image_size
        if isinstance(self.model_tester.image_size      ,     collections.abc.Iterable						)
        else (self.model_tester.image_size, self.model_tester.image_size)
    )
    UpperCAmelCase	:					Dict	=	(
        config.patch_size
        if isinstance(config.patch_size      ,     collections.abc.Iterable						)
        else (config.patch_size, config.patch_size)
    )

    UpperCAmelCase	:					Optional[int]	=	image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
    UpperCAmelCase	:					Dict	=	image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

    for model_class in self.all_model_classes:
     UpperCAmelCase	:					List[Any]	=	True
     self.check_hidden_states_output(_SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     (padded_height, padded_width)						)

     # check that output_hidden_states also work using config
     del inputs_dict["output_hidden_states"]
     UpperCAmelCase	:					Union[str, Any]	=	True
     self.check_hidden_states_output(_SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     _SCREAMING_SNAKE_CASE      ,     (padded_height, padded_width)						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Optional[int]:





    '''simple docstring'''




    UpperCAmelCase	:					int	=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_masked_image_modeling(*_SCREAMING_SNAKE_CASE						)

   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Union[str, Any]:





    '''simple docstring'''




    UpperCAmelCase	:					Union[str, Any]	=	self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_image_classification(*_SCREAMING_SNAKE_CASE						)

   @slow
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Optional[Any]:





    '''simple docstring'''




    for model_name in SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     UpperCAmelCase	:					Tuple	=	SwinvaModel.from_pretrained(_SCREAMING_SNAKE_CASE						)
     self.assertIsNotNone(_SCREAMING_SNAKE_CASE						)




   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      List[Any]:





    '''simple docstring'''




    UpperCAmelCase	,		UpperCAmelCase	:					Optional[Any]	=	self.model_tester.prepare_config_and_inputs_for_common()

    UpperCAmelCase	:					Any	=	_config_zero_init(_SCREAMING_SNAKE_CASE						)
    for model_class in self.all_model_classes:
     UpperCAmelCase	:					List[str]	=	model_class(config=_SCREAMING_SNAKE_CASE						)
     for name, param in model.named_parameters():
      if "embeddings" not in name and "logit_scale" not in name and param.requires_grad:
       self.assertIn(
           ((param.data.mean() * 1E9).round() / 1E9).item()      ,     [0.0, 1.0]      ,     msg=F"Parameter {name} of model {model_class} seems not properly initialized"      ,     )



@require_vision
@require_torch
class       SCREAMING_SNAKE_CASE__  (					unittest.TestCase ):

   @cached_property
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      Optional[Any]:





    '''simple docstring'''




    return (
        AutoImageProcessor.from_pretrained("""microsoft/swinv2-tiny-patch4-window8-256"""						)
        if is_vision_available()
        else None
    )




   @slow
   def 	SCREAMING_SNAKE_CASE     (   self						)  ->      str:





    '''simple docstring'''




    UpperCAmelCase	:					Union[str, Any]	=	SwinvaForImageClassification.from_pretrained("""microsoft/swinv2-tiny-patch4-window8-256"""						).to(
        _SCREAMING_SNAKE_CASE						)
    UpperCAmelCase	:					List[str]	=	self.default_image_processor

    UpperCAmelCase	:					Any	=	Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""						)
    UpperCAmelCase	:					Tuple	=	image_processor(images=_SCREAMING_SNAKE_CASE      ,     return_tensors="""pt"""						).to(_SCREAMING_SNAKE_CASE						)

    # forward pass
    with torch.no_grad():
     UpperCAmelCase	:					Dict	=	model(**_SCREAMING_SNAKE_CASE						)

    # verify the logits
    UpperCAmelCase	:					int	=	torch.Size((1, 1000)						)
    self.assertEqual(outputs.logits.shape      ,     _SCREAMING_SNAKE_CASE						)
    UpperCAmelCase	:					str	=	torch.tensor([-0.3947, -0.4306, 0.0026]						).to(_SCREAMING_SNAKE_CASE						)
    self.assertTrue(torch.allclose(outputs.logits[0, :3]      ,     _SCREAMING_SNAKE_CASE      ,     atol=1E-4						)						)





"""simple docstring"""
from math import pi, sqrt, tan

def       _snake_case						(						UpperCamelCase						:		float						):
 if side_length < 0:
  raise ValueError("""surface_area_cube() only accepts non-negative values"""						)
 return 6 * side_length**2

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if length < 0 or breadth < 0 or height < 0:
  raise ValueError("""surface_area_cuboid() only accepts non-negative values"""						)
 return 2 * ((length * breadth) + (breadth * height) + (length * height))

def       _snake_case						(						UpperCamelCase						:		float						):
 if radius < 0:
  raise ValueError("""surface_area_sphere() only accepts non-negative values"""						)
 return 4 * pi * radius**2

def       _snake_case						(						UpperCamelCase						:		float						):
 if radius < 0:
  raise ValueError("""surface_area_hemisphere() only accepts non-negative values"""						)
 return 3 * pi * radius**2

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if radius < 0 or height < 0:
  raise ValueError("""surface_area_cone() only accepts non-negative values"""						)
 return pi * radius * (radius + (height**2 + radius**2) ** 0.5)

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if radius_a < 0 or radius_a < 0 or height < 0:
  raise ValueError(
      """surface_area_conical_frustum() only accepts non-negative values"""						)
 UpperCAmelCase	:					Tuple	=	(height**2 + (radius_a - radius_a) ** 2) ** 0.5
 return pi * ((slant_height * (radius_a + radius_a)) + radius_a**2 + radius_a**2)

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if radius < 0 or height < 0:
  raise ValueError("""surface_area_cylinder() only accepts non-negative values"""						)
 return 2 * pi * radius * (height + radius)

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if torus_radius < 0 or tube_radius < 0:
  raise ValueError("""surface_area_torus() only accepts non-negative values"""						)
 if torus_radius < tube_radius:
  raise ValueError(
      """surface_area_torus() does not support spindle or self intersecting tori"""						)
 return 4 * pow(UpperCamelCase			,		2						) * torus_radius * tube_radius

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if length < 0 or width < 0:
  raise ValueError("""area_rectangle() only accepts non-negative values"""						)
 return length * width

def       _snake_case						(						UpperCamelCase						:		float						):
 if side_length < 0:
  raise ValueError("""area_square() only accepts non-negative values"""						)
 return side_length**2

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if base < 0 or height < 0:
  raise ValueError("""area_triangle() only accepts non-negative values"""						)
 return (base * height) / 2

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if sidea < 0 or sidea < 0 or sidea < 0:
  raise ValueError("""area_triangle_three_sides() only accepts non-negative values"""						)
 elif sidea + sidea < sidea or sidea + sidea < sidea or sidea + sidea < sidea:
  raise ValueError("""Given three sides do not form a triangle"""						)
 UpperCAmelCase	:					Union[str, Any]	=	(sidea + sidea + sidea) / 2
 UpperCAmelCase	:					Union[str, Any]	=	sqrt(
     semi_perimeter
     * (semi_perimeter - sidea)
     * (semi_perimeter - sidea)
     * (semi_perimeter - sidea)						)
 return area

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if base < 0 or height < 0:
  raise ValueError("""area_parallelogram() only accepts non-negative values"""						)
 return base * height

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if basea < 0 or basea < 0 or height < 0:
  raise ValueError("""area_trapezium() only accepts non-negative values"""						)
 return 1 / 2 * (basea + basea) * height

def       _snake_case						(						UpperCamelCase						:		float						):
 if radius < 0:
  raise ValueError("""area_circle() only accepts non-negative values"""						)
 return pi * radius**2

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if radius_x < 0 or radius_y < 0:
  raise ValueError("""area_ellipse() only accepts non-negative values"""						)
 return pi * radius_x * radius_y

def       _snake_case						(						UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 if diagonal_a < 0 or diagonal_a < 0:
  raise ValueError("""area_rhombus() only accepts non-negative values"""						)
 return 1 / 2 * diagonal_a * diagonal_a

def       _snake_case						(						UpperCamelCase						:		int			,		UpperCamelCase						:		float						):
 if not isinstance(UpperCamelCase			,		UpperCamelCase						) or sides < 3:
  raise ValueError(
      """area_reg_polygon() only accepts integers greater than or \
equal to three as number of sides"""						)
 elif length < 0:
  raise ValueError(
      """area_reg_polygon() only accepts non-negative values as \
length of a side"""						)
 return (sides * length**2) / (4 * tan(pi / sides						))
 return (sides * length**2) / (4 * tan(pi / sides						))


if __name__ == "__main__":
      import doctest

      doctest.testmod(verbose=True)  # verbose so we can see methods missing tests

      print("[DEMO] Areas of various geometric shapes: \n")
      print(f"""Rectangle: {area_rectangle(1_0, 2_0) = }""")
      print(f"""Square: {area_square(1_0) = }""")
      print(f"""Triangle: {area_triangle(1_0, 1_0) = }""")
      print(f"""Triangle: {area_triangle_three_sides(5, 1_2, 1_3) = }""")
      print(f"""Parallelogram: {area_parallelogram(1_0, 2_0) = }""")
      print(f"""Rhombus: {area_rhombus(1_0, 2_0) = }""")
      print(f"""Trapezium: {area_trapezium(1_0, 2_0, 3_0) = }""")
      print(f"""Circle: {area_circle(2_0) = }""")
      print(f"""Ellipse: {area_ellipse(1_0, 2_0) = }""")
      print("\nSurface Areas of various geometric shapes: \n")
      print(f"""Cube: {surface_area_cube(2_0) = }""")
      print(f"""Cuboid: {surface_area_cuboid(1_0, 2_0, 3_0) = }""")
      print(f"""Sphere: {surface_area_sphere(2_0) = }""")
      print(f"""Hemisphere: {surface_area_hemisphere(2_0) = }""")
      print(f"""Cone: {surface_area_cone(1_0, 2_0) = }""")
      print(f"""Conical Frustum: {surface_area_conical_frustum(1_0, 2_0, 3_0) = }""")
      print(f"""Cylinder: {surface_area_cylinder(1_0, 2_0) = }""")
      print(f"""Torus: {surface_area_torus(2_0, 1_0) = }""")
      print(f"""Equilateral Triangle: {area_reg_polygon(3, 1_0) = }""")
      print(f"""Square: {area_reg_polygon(4, 1_0) = }""")
      print(f"""Reqular Pentagon: {area_reg_polygon(5, 1_0) = }""")
