





'''simple docstring'''

import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


__lowerCAmelCase							:     List[str]		     =logging.get_logger(__name__)

__lowerCAmelCase							:     List[Any]		     ={
    "facebook/wav2vec2-base-960h": "https://huggingface.co/facebook/wav2vec2-base-960h/resolve/main/config.json",
    # See all Wav2Vec2 models at https://huggingface.co/models?filter=wav2vec2
}






class        UpperCAmelCase     (	UpperCamelCase__    ):
 __lowercase       		=    """wav2vec2"""
 def __init__(    self				:Dict						,	lowercase_				:List[Any]=32						,	lowercase_				:Tuple=7_68						,	lowercase_				:Tuple=12						,	lowercase_				:List[Any]=12						,	lowercase_				:Tuple=30_72						,	lowercase_				:str="gelu"						,	lowercase_				:Tuple=0.1						,	lowercase_				:List[str]=0.1						,	lowercase_				:str=0.1						,	lowercase_				:List[str]=0.0						,	lowercase_				:List[str]=0.0						,	lowercase_				:List[str]=0.1						,	lowercase_				:Optional[int]=0.1						,	lowercase_				:Union[str, Any]=0.0_2						,	lowercase_				:List[Any]=1E-5						,	lowercase_				:Optional[Any]="group"						,	lowercase_				:int="gelu"						,	lowercase_				:str=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)						,	lowercase_				:List[str]=(5, 2, 2, 2, 2, 2, 2)						,	lowercase_				:int=(10, 3, 3, 3, 3, 2, 2)						,	lowercase_				:str=False						,	lowercase_				:Dict=1_28						,	lowercase_				:Any=16						,	lowercase_				:str=False						,	lowercase_				:Optional[Any]=True						,	lowercase_				:str=0.0_5						,	lowercase_				:Optional[Any]=10						,	lowercase_				:List[Any]=2						,	lowercase_				:Optional[int]=0.0						,	lowercase_				:Dict=10						,	lowercase_				:Optional[Any]=0						,	lowercase_				:Any=3_20						,	lowercase_				:Any=2						,	lowercase_				:Optional[Any]=0.1						,	lowercase_				:List[Any]=1_00						,	lowercase_				:Optional[Any]=2_56						,	lowercase_				:Optional[Any]=2_56						,	lowercase_				:Optional[Any]=0.1						,	lowercase_				:Union[str, Any]="sum"						,	lowercase_				:Optional[Any]=False						,	lowercase_				:str=False						,	lowercase_				:Optional[int]=2_56						,	lowercase_				:Dict=(5_12, 5_12, 5_12, 5_12, 15_00)						,	lowercase_				:Optional[int]=(5, 3, 3, 1, 1)						,	lowercase_				:List[Any]=(1, 2, 3, 1, 1)						,	lowercase_				:Any=5_12						,	lowercase_				:int=0						,	lowercase_				:str=1						,	lowercase_				:List[str]=2						,	lowercase_				:Optional[Any]=False						,	lowercase_				:Optional[Any]=3						,	lowercase_				:List[str]=2						,	lowercase_				:Tuple=3						,	lowercase_				:int=None						,	lowercase_				:List[str]=None						,	**lowercase_				:Dict						,	)->							Dict:
     super().__init__(**lowercase_						,	pad_token_id=lowercase_						,	bos_token_id=lowercase_						,	eos_token_id=lowercase_							)
     A__    =      hidden_size
     A__    =      feat_extract_norm
     A__    =      feat_extract_activation
     A__    =      list(lowercase_							)
     A__    =      list(lowercase_							)
     A__    =      list(lowercase_							)
     A__    =      conv_bias
     A__    =      num_conv_pos_embeddings
     A__    =      num_conv_pos_embedding_groups
     A__    =      len(self.conv_dim							)
     A__    =      num_hidden_layers
     A__    =      intermediate_size
     A__    =      hidden_act
     A__    =      num_attention_heads
     A__    =      hidden_dropout
     A__    =      attention_dropout
     A__    =      activation_dropout
     A__    =      feat_proj_dropout
     A__    =      final_dropout
     A__    =      layerdrop
     A__    =      layer_norm_eps
     A__    =      initializer_range
     A__    =      vocab_size
     A__    =      do_stable_layer_norm
     A__    =      use_weighted_layer_sum

     if (
         (len(self.conv_stride							) != self.num_feat_extract_layers)
         or (len(self.conv_kernel							) != self.num_feat_extract_layers)
         or (len(self.conv_dim							) != self.num_feat_extract_layers)
     ):
         raise ValueError(
             "Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =="
             " `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ="
             F" {len(self.conv_dim							)}`, `len(config.conv_stride) = {len(self.conv_stride							)}`,"
             F" `len(config.conv_kernel) = {len(self.conv_kernel							)}`."							)

     # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
     A__    =      apply_spec_augment
     A__    =      mask_time_prob
     A__    =      mask_time_length
     A__    =      mask_time_min_masks
     A__    =      mask_feature_prob
     A__    =      mask_feature_length
     A__    =      mask_feature_min_masks

     # parameters for pretraining with codevector quantized representations
     A__    =      num_codevectors_per_group
     A__    =      num_codevector_groups
     A__    =      contrastive_logits_temperature
     A__    =      feat_quantizer_dropout
     A__    =      num_negatives
     A__    =      codevector_dim
     A__    =      proj_codevector_dim
     A__    =      diversity_loss_weight

     # ctc loss
     A__    =      ctc_loss_reduction
     A__    =      ctc_zero_infinity

     # adapter
     A__    =      add_adapter
     A__    =      adapter_kernel_size
     A__    =      adapter_stride
     A__    =      num_adapter_layers
     A__    =      output_hidden_size or hidden_size
     A__    =      adapter_attn_dim

     # SequenceClassification-specific parameter. Feel free to ignore for other classes.
     A__    =      classifier_proj_size

     # XVector-specific parameters. Feel free to ignore for other classes.
     A__    =      list(lowercase_							)
     A__    =      list(lowercase_							)
     A__    =      list(lowercase_							)
     A__    =      xvector_output_dim



 @property
 def 					UpperCAmelCase_							(    self				:Union[str, Any]							)->							Optional[Any]:
     return functools.reduce(operator.mul						,	self.conv_stride						,	1							)









'''simple docstring'''

import unittest

import numpy as np





def 						UpperCamelCase    (							_lowerCamelCase : np.ndarray						,	_lowerCamelCase : np.ndarray						,	_lowerCamelCase : np.ndarray						,	_lowerCamelCase : np.ndarray | None = None						,	):
    A__    =      np.shape(_lowerCamelCase	)
    A__    =      np.shape(_lowerCamelCase	)
    A__    =      np.shape(_lowerCamelCase	)

    if shape_a[0] != shape_b[0]:
        A__    =      (
            "Expected the same number of rows for A and B. "
            F"Instead found A of size {shape_a} and B of size {shape_b}"
        )
        raise ValueError(_lowerCamelCase	)

    if shape_b[1] != shape_c[1]:
        A__    =      (
            "Expected the same number of columns for B and C. "
            F"Instead found B of size {shape_b} and C of size {shape_c}"
        )
        raise ValueError(_lowerCamelCase	)

    A__    =      pseudo_inv
    if a_inv is None:
        try:
            A__    =      np.linalg.inv(_lowerCamelCase	)
        except np.linalg.LinAlgError:
            raise ValueError(
                "Input matrix A is not invertible. Cannot compute Schur complement."	)

    return mat_c - mat_b.T @ a_inv @ mat_b






class        UpperCAmelCase     (	unittest.TestCase    ):
 def 					UpperCAmelCase_							(    self				:Any							)->							None:
     A__    =      np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]							)
     A__    =      np.array([[0, 3], [3, 0], [2, 3]]							)
     A__    =      np.array([[2, 1], [6, 3]]							)

     A__    =      schur_complement(lowercase_						,	lowercase_						,	lowercase_							)

     A__    =      np.block([[a, b], [b.T, c]]							)

     A__    =      np.linalg.det(lowercase_							)
     A__    =      np.linalg.det(lowercase_							)
     A__    =      np.linalg.det(lowercase_							)

     self.assertAlmostEqual(lowercase_						,	det_a * det_s							)
 def 					UpperCAmelCase_							(    self				:Dict							)->							None:
     A__    =      np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]							)
     A__    =      np.array([[0, 3], [3, 0], [2, 3]]							)
     A__    =      np.array([[2, 1], [6, 3]]							)

     with self.assertRaises(lowercase_							):
         schur_complement(lowercase_						,	lowercase_						,	lowercase_							)



 def 					UpperCAmelCase_							(    self				:Union[str, Any]							)->							None:
     A__    =      np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]							)
     A__    =      np.array([[0, 3], [3, 0], [2, 3]]							)
     A__    =      np.array([[2, 1, 3], [6, 3, 5]]							)

     with self.assertRaises(lowercase_							):
         schur_complement(lowercase_						,	lowercase_						,	lowercase_							)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  unittest.main()



