





import copy
import unittest

from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, 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, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
     import torch

     from transformers import (
         MODEL_FOR_MULTIPLE_CHOICE_MAPPING,
         MODEL_FOR_QUESTION_ANSWERING_MAPPING,
         MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
         MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING,
         LayoutLMvaConfig,
         LayoutLMvaForQuestionAnswering,
         LayoutLMvaForSequenceClassification,
         LayoutLMvaForTokenClassification,
         LayoutLMvaModel,
     )
     from transformers.models.layoutlmva.modeling_layoutlmva import LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
     from PIL import Image

     from transformers import LayoutLMvaImageProcessor



class    _SCREAMING_SNAKE_CASE						:







 '''simple docstring'''

 def __init__(self				:   Dict       , UpperCAmelCase_				:   Dict       , UpperCAmelCase_				:   Tuple=2       , UpperCAmelCase_				:   Dict=3       , UpperCAmelCase_				:   Dict=4       , UpperCAmelCase_				:   List[str]=2       , UpperCAmelCase_				:   Optional[Any]=7       , UpperCAmelCase_				:   int=True       , UpperCAmelCase_				:   Optional[Any]=True       , UpperCAmelCase_				:   List[Any]=True       , UpperCAmelCase_				:   Any=True       , UpperCAmelCase_				:   Any=99       , UpperCAmelCase_				:   Optional[int]=36       , UpperCAmelCase_				:   Dict=3       , UpperCAmelCase_				:   int=4       , UpperCAmelCase_				:   List[str]=37       , UpperCAmelCase_				:   Optional[Any]="gelu"       , UpperCAmelCase_				:   Tuple=0.1       , UpperCAmelCase_				:   Union[str, Any]=0.1       , UpperCAmelCase_				:   List[str]=512       , UpperCAmelCase_				:   int=16       , UpperCAmelCase_				:   int=2       , UpperCAmelCase_				:   Optional[int]=0.02       , UpperCAmelCase_				:   int=6       , UpperCAmelCase_				:   Dict=6       , UpperCAmelCase_				:   Any=3       , UpperCAmelCase_				:   int=4       , UpperCAmelCase_				:   Optional[Any]=None       , UpperCAmelCase_				:   Optional[Any]=1_000       , )       ->Tuple:



   '''simple docstring'''



   lowerCamelCase__:      Tuple			  =parent
   lowerCamelCase__:      Union[str, Any]			  =batch_size
   lowerCamelCase__:      Dict			  =num_channels
   lowerCamelCase__:      int			  =image_size
   lowerCamelCase__:      List[Any]			  =patch_size
   lowerCamelCase__:      Union[str, Any]			  =text_seq_length
   lowerCamelCase__:      str			  =is_training
   lowerCamelCase__:      Dict			  =use_input_mask
   lowerCamelCase__:      Optional[Any]			  =use_token_type_ids
   lowerCamelCase__:      List[str]			  =use_labels
   lowerCamelCase__:      int			  =vocab_size
   lowerCamelCase__:      Optional[Any]			  =hidden_size
   lowerCamelCase__:      Tuple			  =num_hidden_layers
   lowerCamelCase__:      Optional[Any]			  =num_attention_heads
   lowerCamelCase__:      Optional[int]			  =intermediate_size
   lowerCamelCase__:      Union[str, Any]			  =hidden_act
   lowerCamelCase__:      Union[str, Any]			  =hidden_dropout_prob
   lowerCamelCase__:      Dict			  =attention_probs_dropout_prob
   lowerCamelCase__:      Any			  =max_position_embeddings
   lowerCamelCase__:      Tuple			  =type_vocab_size
   lowerCamelCase__:      str			  =type_sequence_label_size
   lowerCamelCase__:      Optional[Any]			  =initializer_range
   lowerCamelCase__:      Optional[int]			  =coordinate_size
   lowerCamelCase__:      Any			  =shape_size
   lowerCamelCase__:      Optional[Any]			  =num_labels
   lowerCamelCase__:      Optional[int]			  =num_choices
   lowerCamelCase__:      int			  =scope
   lowerCamelCase__:      str			  =range_bbox

   # LayoutLMv3's sequence length equals the number of text tokens + number of patches + 1 (we add 1 for the CLS token)
   lowerCamelCase__:      str			  =text_seq_length
   lowerCamelCase__:      List[Any]			  =(image_size // patch_size) ** 2 + 1
   lowerCamelCase__:      List[Any]			  =self.text_seq_length + self.image_seq_length

 def 							SCREAMING_SNAKE_CASE_					(self				:   Any)       ->Any:



   '''simple docstring'''



   lowerCamelCase__:      Optional[Any]			  =ids_tensor([self.batch_size, self.text_seq_length]       , self.vocab_size)

   lowerCamelCase__:      Union[str, Any]			  =ids_tensor([self.batch_size, self.text_seq_length, 4]       , self.range_bbox)
   # Ensure that bbox is legal
   for i in range(bbox.shape[0]):
     for j in range(bbox.shape[1]):
       if bbox[i, j, 3] < bbox[i, j, 1]:
         lowerCamelCase__:      Dict			  =bbox[i, j, 3]
         lowerCamelCase__:      Union[str, Any]			  =bbox[i, j, 1]
         lowerCamelCase__:      str			  =t
       if bbox[i, j, 2] < bbox[i, j, 0]:
         lowerCamelCase__:      Tuple			  =bbox[i, j, 2]
         lowerCamelCase__:      Any			  =bbox[i, j, 0]
         lowerCamelCase__:      Optional[Any]			  =t

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

   lowerCamelCase__:      Union[str, Any]			  =None
   if self.use_input_mask:
     lowerCamelCase__:      Optional[int]			  =random_attention_mask([self.batch_size, self.text_seq_length])

   lowerCamelCase__:      Any			  =None
   if self.use_token_type_ids:
     lowerCamelCase__:      Any			  =ids_tensor([self.batch_size, self.text_seq_length]       , self.type_vocab_size)

   lowerCamelCase__:      str			  =None
   lowerCamelCase__:      List[Any]			  =None
   if self.use_labels:
     lowerCamelCase__:      Tuple			  =ids_tensor([self.batch_size]       , self.type_sequence_label_size)
     lowerCamelCase__:      Tuple			  =ids_tensor([self.batch_size, self.text_seq_length]       , self.num_labels)

   lowerCamelCase__:      str			  =LayoutLMvaConfig(
       vocab_size=self.vocab_size       , hidden_size=self.hidden_size       , num_hidden_layers=self.num_hidden_layers       , num_attention_heads=self.num_attention_heads       , intermediate_size=self.intermediate_size       , hidden_act=self.hidden_act       , hidden_dropout_prob=self.hidden_dropout_prob       , attention_probs_dropout_prob=self.attention_probs_dropout_prob       , max_position_embeddings=self.max_position_embeddings       , type_vocab_size=self.type_vocab_size       , initializer_range=self.initializer_range       , coordinate_size=self.coordinate_size       , shape_size=self.shape_size       , input_size=self.image_size       , patch_size=self.patch_size       , )

   return config, input_ids, bbox, pixel_values, token_type_ids, input_mask, sequence_labels, token_labels

 def 							SCREAMING_SNAKE_CASE_					(self				:   int       , UpperCAmelCase_				:   List[Any]       , UpperCAmelCase_				:   Tuple       , UpperCAmelCase_				:   Union[str, Any]       , UpperCAmelCase_				:   Union[str, Any]       , UpperCAmelCase_				:   List[str]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Dict)       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =LayoutLMvaModel(config=UpperCAmelCase_)
   model.to(UpperCAmelCase_)
   model.eval()

   # text + image
   lowerCamelCase__:      Optional[int]			  =model(UpperCAmelCase_       , pixel_values=UpperCAmelCase_)
   lowerCamelCase__:      Tuple			  =model(
       UpperCAmelCase_       , bbox=UpperCAmelCase_       , pixel_values=UpperCAmelCase_       , attention_mask=UpperCAmelCase_       , token_type_ids=UpperCAmelCase_)
   lowerCamelCase__:      Any			  =model(UpperCAmelCase_       , bbox=UpperCAmelCase_       , pixel_values=UpperCAmelCase_       , token_type_ids=UpperCAmelCase_)
   lowerCamelCase__:      int			  =model(UpperCAmelCase_       , bbox=UpperCAmelCase_       , pixel_values=UpperCAmelCase_)

   self.parent.assertEqual(result.last_hidden_state.shape       , (self.batch_size, self.seq_length, self.hidden_size))

   # text only
   lowerCamelCase__:      str			  =model(UpperCAmelCase_)
   self.parent.assertEqual(
       result.last_hidden_state.shape       , (self.batch_size, self.text_seq_length, self.hidden_size))

   # image only
   lowerCamelCase__:      int			  =model(pixel_values=UpperCAmelCase_)
   self.parent.assertEqual(
       result.last_hidden_state.shape       , (self.batch_size, self.image_seq_length, self.hidden_size))

 def 							SCREAMING_SNAKE_CASE_					(self				:   int       , UpperCAmelCase_				:   Tuple       , UpperCAmelCase_				:   List[str]       , UpperCAmelCase_				:   Union[str, Any]       , UpperCAmelCase_				:   int       , UpperCAmelCase_				:   str       , UpperCAmelCase_				:   Optional[Any]       , UpperCAmelCase_				:   str       , UpperCAmelCase_				:   Optional[Any])       ->List[str]:



   '''simple docstring'''



   lowerCamelCase__:      Any			  =self.num_labels
   lowerCamelCase__:      Optional[Any]			  =LayoutLMvaForSequenceClassification(UpperCAmelCase_)
   model.to(UpperCAmelCase_)
   model.eval()
   lowerCamelCase__:      int			  =model(
       UpperCAmelCase_       , bbox=UpperCAmelCase_       , pixel_values=UpperCAmelCase_       , attention_mask=UpperCAmelCase_       , token_type_ids=UpperCAmelCase_       , labels=UpperCAmelCase_       , )
   self.parent.assertEqual(result.logits.shape       , (self.batch_size, self.num_labels))

 def 							SCREAMING_SNAKE_CASE_					(self				:   Tuple       , UpperCAmelCase_				:   Dict       , UpperCAmelCase_				:   Tuple       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Optional[int]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   str       , UpperCAmelCase_				:   Optional[Any])       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Tuple			  =self.num_labels
   lowerCamelCase__:      List[str]			  =LayoutLMvaForTokenClassification(config=UpperCAmelCase_)
   model.to(UpperCAmelCase_)
   model.eval()
   lowerCamelCase__:      Union[str, Any]			  =model(
       UpperCAmelCase_       , bbox=UpperCAmelCase_       , pixel_values=UpperCAmelCase_       , attention_mask=UpperCAmelCase_       , token_type_ids=UpperCAmelCase_       , labels=UpperCAmelCase_       , )
   self.parent.assertEqual(result.logits.shape       , (self.batch_size, self.text_seq_length, self.num_labels))

 def 							SCREAMING_SNAKE_CASE_					(self				:   Tuple       , UpperCAmelCase_				:   int       , UpperCAmelCase_				:   int       , UpperCAmelCase_				:   Tuple       , UpperCAmelCase_				:   str       , UpperCAmelCase_				:   List[Any]       , UpperCAmelCase_				:   List[str]       , UpperCAmelCase_				:   List[str]       , UpperCAmelCase_				:   List[str])       ->Tuple:



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =LayoutLMvaForQuestionAnswering(config=UpperCAmelCase_)
   model.to(UpperCAmelCase_)
   model.eval()
   lowerCamelCase__:      Union[str, Any]			  =model(
       UpperCAmelCase_       , bbox=UpperCAmelCase_       , pixel_values=UpperCAmelCase_       , attention_mask=UpperCAmelCase_       , token_type_ids=UpperCAmelCase_       , start_positions=UpperCAmelCase_       , end_positions=UpperCAmelCase_       , )
   self.parent.assertEqual(result.start_logits.shape       , (self.batch_size, self.seq_length))
   self.parent.assertEqual(result.end_logits.shape       , (self.batch_size, self.seq_length))







 def 							SCREAMING_SNAKE_CASE_					(self				:   Dict)       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Optional[Any]			  =self.prepare_config_and_inputs()
   (
       (
       lowerCamelCase__
   )  ,					(
       lowerCamelCase__
   )  ,					(
       lowerCamelCase__
   )  ,					(
       lowerCamelCase__
   )  ,					(
       lowerCamelCase__
   )  ,					(
       lowerCamelCase__
   )  ,					(
       lowerCamelCase__
   )  ,					(
       lowerCamelCase__
   )  ,					
   ):      List[Any]			  =config_and_inputs
   lowerCamelCase__:      List[str]			  ={
       "input_ids": input_ids,
       "bbox": bbox,
       "pixel_values": pixel_values,
       "token_type_ids": token_type_ids,
       "attention_mask": input_mask,
   }
   return config, inputs_dict



@require_torch
class    _SCREAMING_SNAKE_CASE						(	__SCREAMING_SNAKE_CASE    ,							__SCREAMING_SNAKE_CASE    ,							unittest.TestCase    ):







 '''simple docstring'''
 lowercase_		=			False
 lowercase_		=			False
 lowercase_		=			False

 lowercase_		=			(
     (
         LayoutLMvaModel,
         LayoutLMvaForSequenceClassification,
         LayoutLMvaForTokenClassification,
         LayoutLMvaForQuestionAnswering,
     )
     if is_torch_available()
     else ()
 )
 lowercase_		=			(
     {"document-question-answering": LayoutLMvaForQuestionAnswering, "feature-extraction": LayoutLMvaModel}
     if is_torch_available()
     else {}
 )

 def 							SCREAMING_SNAKE_CASE_					(self				:   Dict       , UpperCAmelCase_				:   str       , UpperCAmelCase_				:   Dict       , UpperCAmelCase_				:   Optional[int]       , UpperCAmelCase_				:   str       , UpperCAmelCase_				:   Any)       ->Optional[int]:



   '''simple docstring'''



   return True

 def 							SCREAMING_SNAKE_CASE_					(self				:   int)       ->Dict:



   '''simple docstring'''



   lowerCamelCase__:      Union[str, Any]			  =LayoutLMvaModelTester(self)
   lowerCamelCase__:      Union[str, Any]			  =ConfigTester(self       , config_class=UpperCAmelCase_       , hidden_size=37)

 def 							SCREAMING_SNAKE_CASE_					(self				:   List[str]       , UpperCAmelCase_				:   List[Any]       , UpperCAmelCase_				:   Any       , UpperCAmelCase_				:   List[Any]=False)       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Any			  =copy.deepcopy(UpperCAmelCase_)
   if model_class in get_values(UpperCAmelCase_):
     lowerCamelCase__:      Union[str, Any]			  ={
         k: v.unsqueeze(1).expand(-1       , self.model_tester.num_choices       , -1).contiguous()
         if isinstance(UpperCAmelCase_       , torch.Tensor) and v.ndim > 1
         else v
         for k, v in inputs_dict.items()
     }
   if return_labels:
     if model_class in get_values(UpperCAmelCase_):
       lowerCamelCase__:      Optional[int]			  =torch.ones(self.model_tester.batch_size       , dtype=torch.long       , device=UpperCAmelCase_)
     elif model_class in get_values(UpperCAmelCase_):
       lowerCamelCase__:      int			  =torch.zeros(
           self.model_tester.batch_size       , dtype=torch.long       , device=UpperCAmelCase_)
       lowerCamelCase__:      int			  =torch.zeros(
           self.model_tester.batch_size       , dtype=torch.long       , device=UpperCAmelCase_)
     elif model_class in [
         *get_values(UpperCAmelCase_),
     ]:
       lowerCamelCase__:      Union[str, Any]			  =torch.zeros(
           self.model_tester.batch_size       , dtype=torch.long       , device=UpperCAmelCase_)
     elif model_class in [
         *get_values(UpperCAmelCase_),
     ]:
       lowerCamelCase__:      int			  =torch.zeros(
           (self.model_tester.batch_size, self.model_tester.text_seq_length)       , dtype=torch.long       , device=UpperCAmelCase_       , )

   return inputs_dict

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



   '''simple docstring'''



   self.config_tester.run_common_tests()

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



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_model(*UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_					(self				:   str)       ->str:



   '''simple docstring'''



   lowerCamelCase__:      Tuple			  =self.model_tester.prepare_config_and_inputs()
   for type in ["absolute", "relative_key", "relative_key_query"]:
     lowerCamelCase__:      Union[str, Any]			  =type
     self.model_tester.create_and_check_model(*UpperCAmelCase_)

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



   '''simple docstring'''



   lowerCamelCase__:      Union[str, Any]			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_sequence_classification(*UpperCAmelCase_)

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



   '''simple docstring'''



   lowerCamelCase__:      List[str]			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_					(self				:   List[str])       ->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:      List[Any]			  =self.model_tester.prepare_config_and_inputs()
   self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase_)







 @slow
 def 							SCREAMING_SNAKE_CASE_					(self				:   Optional[Any])       ->Union[str, Any]:



   '''simple docstring'''



   for model_name in LAYOUTLMV3_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
     lowerCamelCase__:      int			  =LayoutLMvaModel.from_pretrained(UpperCAmelCase_)
     self.assertIsNotNone(UpperCAmelCase_)





def      lowerCAmelCase_ (       )     ->		Dict:







  """simple docstring"""





  lowerCamelCase__:      str			  =Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
  return image






@require_torch
class    _SCREAMING_SNAKE_CASE						(	unittest.TestCase    ):







 '''simple docstring'''

 @cached_property
 def 							SCREAMING_SNAKE_CASE_					(self				:   Any)       ->str:



   '''simple docstring'''



   return LayoutLMvaImageProcessor(apply_ocr=UpperCAmelCase_) if is_vision_available() else None







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



   '''simple docstring'''



   lowerCamelCase__:      Optional[Any]			  =LayoutLMvaModel.from_pretrained("microsoft/layoutlmv3-base").to(UpperCAmelCase_)

   lowerCamelCase__:      Union[str, Any]			  =self.default_image_processor
   lowerCamelCase__:      List[Any]			  =prepare_img()
   lowerCamelCase__:      Union[str, Any]			  =image_processor(images=UpperCAmelCase_       , return_tensors="pt").pixel_values.to(UpperCAmelCase_)

   lowerCamelCase__:      Any			  =torch.tensor([[1, 2]])
   lowerCamelCase__:      str			  =torch.tensor([[1, 2, 3, 4], [5, 6, 7, 8]]).unsqueeze(0)

   # forward pass
   lowerCamelCase__:      Tuple			  =model(
       input_ids=input_ids.to(UpperCAmelCase_)       , bbox=bbox.to(UpperCAmelCase_)       , pixel_values=pixel_values.to(UpperCAmelCase_)       , )

   # verify the logits
   lowerCamelCase__:      str			  =torch.Size((1, 199, 768))
   self.assertEqual(outputs.last_hidden_state.shape       , UpperCAmelCase_)

   lowerCamelCase__:      Dict			  =torch.tensor(
       [[-0.0529, 0.3618, 0.1632], [-0.1587, -0.1667, -0.0400], [-0.1557, -0.1671, -0.0505]]).to(UpperCAmelCase_)

   self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3]       , UpperCAmelCase_       , atol=1E-4))


"""simple docstring"""
import itertools
import random
import unittest

import numpy as np

from transformers import WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST, WavaVecaConfig, WavaVecaFeatureExtractor
from transformers.testing_utils import require_torch, slow

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


lowercase__					       =	random.Random()







def 						__a   (	_SCREAMING_SNAKE_CASE		,     _SCREAMING_SNAKE_CASE=1.0		,     _SCREAMING_SNAKE_CASE=None		,     _SCREAMING_SNAKE_CASE=None   )	->Optional[int]:
  if rng is None:
    a__:     Any										=	global_rng

  a__:     int										=	[]
  for batch_idx in range(shape[0]   ):
    values.append([]   )
    for _ in range(shape[1]   ):
      values[-1].append(rng.random() * scale   )

  return values




class    __snake_case       (     unittest.TestCase				):



      def __init__(						self    ,			lowercase    ,			lowercase=7    ,			lowercase=4_00    ,			lowercase=20_00    ,			lowercase=1    ,			lowercase=0.0    ,			lowercase=1_60_00    ,			lowercase=True    ,			lowercase=True    ,			)	->			Union[str, Any]:





        '''simple docstring'''





        a__:     Tuple										=	parent
        a__:     Optional[int]										=	batch_size
        a__:     Optional[Any]										=	min_seq_length
        a__:     Optional[int]										=	max_seq_length
        a__:     Tuple										=	(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
        a__:     Dict										=	feature_size
        a__:     Any										=	padding_value
        a__:     Optional[Any]										=	sampling_rate
        a__:     Optional[Any]										=	return_attention_mask
        a__:     str										=	do_normalize



      def   lowerCamelCase_   (						self)	->			Dict:





        '''simple docstring'''





        return {
            "feature_size": self.feature_size,
            "padding_value": self.padding_value,
            "sampling_rate": self.sampling_rate,
            "return_attention_mask": self.return_attention_mask,
            "do_normalize": self.do_normalize,
        }



      def   lowerCamelCase_   (						self    ,			lowercase=False    ,			lowercase=False)	->			Tuple:





        '''simple docstring'''





        def _flatten(lowercase):
          return list(itertools.chain(*lowercase))

        if equal_length:
          a__:     Dict										=	floats_list((self.batch_size, self.max_seq_length))
        else:
          # make sure that inputs increase in size
          a__:     List[Any]										=	[
              _flatten(floats_list((x, self.feature_size)))
              for x in range(self.min_seq_length    ,			self.max_seq_length    ,			self.seq_length_diff)
          ]

        if numpify:
          a__:     str										=	[np.asarray(lowercase) for x in speech_inputs]

        return speech_inputs







class    __snake_case       (     __lowerCAmelCase       ,      unittest.TestCase				):
      a__        =		WavaVecaFeatureExtractor



      def   lowerCamelCase_   (						self)	->			Tuple:





        '''simple docstring'''





        a__:     Optional[int]										=	WavaVecaFeatureExtractionTester(self)



      def   lowerCamelCase_   (						self    ,			lowercase)	->			List[Any]:





        '''simple docstring'''





        self.assertTrue(np.all(np.mean(lowercase    ,			axis=0) < 1e-3))
        self.assertTrue(np.all(np.abs(np.var(lowercase    ,			axis=0) - 1) < 1e-3))



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





        '''simple docstring'''





        a__:     List[Any]										=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
        # create three inputs of length 800, 1000, and 1200
        a__:     Optional[Any]										=	[floats_list((1, x))[0] for x in range(8_00    ,			14_00    ,			2_00)]
        a__:     List[str]										=	[np.asarray(lowercase) for speech_input in speech_inputs]

        # Test not batched input
        a__:     Optional[Any]										=	feat_extract(speech_inputs[0]    ,			return_tensors='np').input_values
        a__:     Dict										=	feat_extract(np_speech_inputs[0]    ,			return_tensors='np').input_values
        self.assertTrue(np.allclose(lowercase    ,			lowercase    ,			atol=1e-3))

        # Test batched
        a__:     Dict										=	feat_extract(lowercase    ,			return_tensors='np').input_values
        a__:     int										=	feat_extract(lowercase    ,			return_tensors='np').input_values
        for enc_seq_a, enc_seq_a in zip(lowercase    ,			lowercase):
          self.assertTrue(np.allclose(lowercase    ,			lowercase    ,			atol=1e-3))

        # Test 2-D numpy arrays are batched.
        a__:     int										=	[floats_list((1, x))[0] for x in (8_00, 8_00, 8_00)]
        a__:     Union[str, Any]										=	np.asarray(lowercase)
        a__:     int										=	feat_extract(lowercase    ,			return_tensors='np').input_values
        a__:     Any										=	feat_extract(lowercase    ,			return_tensors='np').input_values
        for enc_seq_a, enc_seq_a in zip(lowercase    ,			lowercase):
          self.assertTrue(np.allclose(lowercase    ,			lowercase    ,			atol=1e-3))



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





        '''simple docstring'''





        a__:     Tuple										=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
        a__:     List[Any]										=	[floats_list((1, x))[0] for x in range(8_00    ,			14_00    ,			2_00)]

        a__:     Optional[int]										=	['longest', 'max_length', 'do_not_pad']
        a__:     List[Any]										=	[None, 16_00, None]
        for max_length, padding in zip(lowercase    ,			lowercase):
          a__:     Dict										=	feat_extract(lowercase    ,			padding=lowercase    ,			max_length=lowercase    ,			return_tensors='np')
          a__:     Union[str, Any]										=	processed.input_values

          self._check_zero_mean_unit_variance(input_values[0][:8_00])
          self.assertTrue(input_values[0][8_00:].sum() < 1e-6)
          self._check_zero_mean_unit_variance(input_values[1][:10_00])
          self.assertTrue(input_values[0][10_00:].sum() < 1e-6)
          self._check_zero_mean_unit_variance(input_values[2][:12_00])



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





        '''simple docstring'''





        a__:     str										=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
        a__:     Optional[int]										=	range(8_00    ,			14_00    ,			2_00)
        a__:     List[str]										=	[floats_list((1, x))[0] for x in lengths]

        a__:     Tuple										=	['longest', 'max_length', 'do_not_pad']
        a__:     Dict										=	[None, 16_00, None]

        for max_length, padding in zip(lowercase    ,			lowercase):
          a__:     int										=	feat_extract(lowercase    ,			max_length=lowercase    ,			padding=lowercase)
          a__:     Any										=	processed.input_values

          self._check_zero_mean_unit_variance(input_values[0][:8_00])
          self._check_zero_mean_unit_variance(input_values[1][:10_00])
          self._check_zero_mean_unit_variance(input_values[2][:12_00])



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





        '''simple docstring'''





        a__:     Any										=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
        a__:     Any										=	[floats_list((1, x))[0] for x in range(8_00    ,			14_00    ,			2_00)]
        a__:     Dict										=	feat_extract(
            lowercase    ,			truncation=lowercase    ,			max_length=10_00    ,			padding='max_length'    ,			return_tensors='np')
        a__:     int										=	processed.input_values

        self._check_zero_mean_unit_variance(input_values[0, :8_00])
        self._check_zero_mean_unit_variance(input_values[1])
        self._check_zero_mean_unit_variance(input_values[2])



      def   lowerCamelCase_   (						self)	->			Dict:





        '''simple docstring'''





        a__:     Tuple										=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
        a__:     int										=	[floats_list((1, x))[0] for x in range(8_00    ,			14_00    ,			2_00)]
        a__:     str										=	feat_extract(
            lowercase    ,			truncation=lowercase    ,			max_length=10_00    ,			padding='longest'    ,			return_tensors='np')
        a__:     Any										=	processed.input_values

        self._check_zero_mean_unit_variance(input_values[0, :8_00])
        self._check_zero_mean_unit_variance(input_values[1, :10_00])
        self._check_zero_mean_unit_variance(input_values[2])

        # make sure that if max_length < longest -> then pad to max_length
        self.assertTrue(input_values.shape == (3, 10_00))

        a__:     Dict										=	[floats_list((1, x))[0] for x in range(8_00    ,			14_00    ,			2_00)]
        a__:     Tuple										=	feat_extract(
            lowercase    ,			truncation=lowercase    ,			max_length=20_00    ,			padding='longest'    ,			return_tensors='np')
        a__:     str										=	processed.input_values

        self._check_zero_mean_unit_variance(input_values[0, :8_00])
        self._check_zero_mean_unit_variance(input_values[1, :10_00])
        self._check_zero_mean_unit_variance(input_values[2])

        # make sure that if max_length > longest -> then pad to longest
        self.assertTrue(input_values.shape == (3, 12_00))



      @require_torch
      def   lowerCamelCase_   (						self)	->			Tuple:





        '''simple docstring'''





        import torch

        a__:     Optional[int]										=	self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
        a__:     Tuple										=	np.random.rand(1_00).astype(np.floataa)
        a__:     Tuple										=	np_speech_inputs.tolist()

        for inputs in [py_speech_inputs, np_speech_inputs]:
          a__:     Any										=	feature_extractor.pad([{'input_values': inputs}]    ,			return_tensors='np')
          self.assertTrue(np_processed.input_values.dtype == np.floataa)
          a__:     Optional[Any]										=	feature_extractor.pad([{'input_values': inputs}]    ,			return_tensors='pt')
          self.assertTrue(pt_processed.input_values.dtype == torch.floataa)



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





        '''simple docstring'''





        for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
          a__:     str										=	WavaVecaConfig.from_pretrained(lowercase)
          a__:     str										=	WavaVecaFeatureExtractor.from_pretrained(lowercase)

          # only "layer" feature extraction norm should make use of
          # attention_mask
          self.assertEqual(feat_extract.return_attention_mask    ,			config.feat_extract_norm == 'layer')


