

import unittest

import numpy as np

from transformers import AlbertConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
							import jax.numpy as jnp

							from transformers.models.albert.modeling_flax_albert import (
							    FlaxAlbertForMaskedLM,
							    FlaxAlbertForMultipleChoice,
							    FlaxAlbertForPreTraining,
							    FlaxAlbertForQuestionAnswering,
							    FlaxAlbertForSequenceClassification,
							    FlaxAlbertForTokenClassification,
							    FlaxAlbertModel,
							)






class  UpperCAmelCase__	( unittest.TestCase ):






		"""simple docstring"""


		def __init__(							self		:	str			,     __lowerCamelCase		:	Optional[Any]			,     __lowerCamelCase		:	List[Any]=13			,     __lowerCamelCase		:	Optional[int]=7			,     __lowerCamelCase		:	Tuple=True			,     __lowerCamelCase		:	Any=True			,     __lowerCamelCase		:	Union[str, Any]=True			,     __lowerCamelCase		:	Union[str, Any]=True			,     __lowerCamelCase		:	Tuple=99			,     __lowerCamelCase		:	List[str]=32			,     __lowerCamelCase		:	int=5			,     __lowerCamelCase		:	Tuple=4			,     __lowerCamelCase		:	str=37			,     __lowerCamelCase		:	List[Any]="gelu"			,     __lowerCamelCase		:	int=0.1			,     __lowerCamelCase		:	Optional[int]=0.1			,     __lowerCamelCase		:	Dict=512			,     __lowerCamelCase		:	List[str]=16			,     __lowerCamelCase		:	Optional[int]=2			,     __lowerCamelCase		:	List[str]=0.02			,     __lowerCamelCase		:	List[Any]=4			,     )	->							Optional[Any]:
							SCREAMING_SNAKE_CASE__					=					parent
							SCREAMING_SNAKE_CASE__					=					batch_size
							SCREAMING_SNAKE_CASE__					=					seq_length
							SCREAMING_SNAKE_CASE__					=					is_training
							SCREAMING_SNAKE_CASE__					=					use_attention_mask
							SCREAMING_SNAKE_CASE__					=					use_token_type_ids
							SCREAMING_SNAKE_CASE__					=					use_labels
							SCREAMING_SNAKE_CASE__					=					vocab_size
							SCREAMING_SNAKE_CASE__					=					hidden_size
							SCREAMING_SNAKE_CASE__					=					num_hidden_layers
							SCREAMING_SNAKE_CASE__					=					num_attention_heads
							SCREAMING_SNAKE_CASE__					=					intermediate_size
							SCREAMING_SNAKE_CASE__					=					hidden_act
							SCREAMING_SNAKE_CASE__					=					hidden_dropout_prob
							SCREAMING_SNAKE_CASE__					=					attention_probs_dropout_prob
							SCREAMING_SNAKE_CASE__					=					max_position_embeddings
							SCREAMING_SNAKE_CASE__					=					type_vocab_size
							SCREAMING_SNAKE_CASE__					=					type_sequence_label_size
							SCREAMING_SNAKE_CASE__					=					initializer_range
							SCREAMING_SNAKE_CASE__					=					num_choices






		def    lowercase_	(							self		:	Optional[Any]      )	->							int:
							SCREAMING_SNAKE_CASE__					=					ids_tensor([self.batch_size, self.seq_length]			,     self.vocab_size      )

							SCREAMING_SNAKE_CASE__					=					None
							if self.use_attention_mask:
												SCREAMING_SNAKE_CASE__					=					random_attention_mask([self.batch_size, self.seq_length]      )

							SCREAMING_SNAKE_CASE__					=					None
							if self.use_token_type_ids:
												SCREAMING_SNAKE_CASE__					=					ids_tensor([self.batch_size, self.seq_length]			,     self.type_vocab_size      )

							SCREAMING_SNAKE_CASE__					=					AlbertConfig(
							    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			,     is_decoder=__lowerCamelCase			,     initializer_range=self.initializer_range			,     )

							return config, input_ids, token_type_ids, attention_mask







		def    lowercase_	(							self		:	int      )	->							List[Any]:
							SCREAMING_SNAKE_CASE__					=					self.prepare_config_and_inputs()
							SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__,SCREAMING_SNAKE_CASE__					=					config_and_inputs
							SCREAMING_SNAKE_CASE__					=					{'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': attention_mask}
							return config, inputs_dict






@require_flax
class  UpperCAmelCase__	( A__		,  unittest.TestCase ):






		"""simple docstring"""


		a     =      (
		    (
		        FlaxAlbertModel,
		        FlaxAlbertForPreTraining,
		        FlaxAlbertForMaskedLM,
		        FlaxAlbertForMultipleChoice,
		        FlaxAlbertForQuestionAnswering,
		        FlaxAlbertForSequenceClassification,
		        FlaxAlbertForTokenClassification,
		        FlaxAlbertForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)






		def    lowercase_	(							self		:	Tuple      )	->							Tuple:
							SCREAMING_SNAKE_CASE__					=					FlaxAlbertModelTester(self      )







		@slow
		def    lowercase_	(							self		:	str      )	->							Optional[Any]:
							for model_class_name in self.all_model_classes:
												SCREAMING_SNAKE_CASE__					=					model_class_name.from_pretrained('''albert-base-v2'''      )
												SCREAMING_SNAKE_CASE__					=					model(np.ones((1, 1)      )      )
												self.assertIsNotNone(__lowerCamelCase      )






@require_flax
class  UpperCAmelCase__	( unittest.TestCase ):






		"""simple docstring"""


		@slow
		def    lowercase_	(							self		:	Any      )	->							Dict:
							SCREAMING_SNAKE_CASE__					=					FlaxAlbertModel.from_pretrained('''albert-base-v2'''      )
							SCREAMING_SNAKE_CASE__					=					np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]      )
							SCREAMING_SNAKE_CASE__					=					np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
							SCREAMING_SNAKE_CASE__					=					model(__lowerCamelCase			,     attention_mask=__lowerCamelCase      )[0]
							SCREAMING_SNAKE_CASE__					=					(1, 11, 768)
							self.assertEqual(output.shape			,     __lowerCamelCase      )
							SCREAMING_SNAKE_CASE__					=					np.array(
							    [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]      )

							self.assertTrue(jnp.allclose(output[:, 1:4, 1:4]			,     __lowerCamelCase			,     atol=1e-4      )      )





import doctest
from collections import deque

import numpy as np






class  UpperCAmelCase__	:






  """simple docstring"""


  def __init__(							self		:	Optional[Any]      )	->							None:
       SCREAMING_SNAKE_CASE__					=					[2, 1, 2, -1]
       SCREAMING_SNAKE_CASE__					=					[1, 2, 3, 4]







  def    lowercase_	(							self		:	List[str]      )	->							list[float]:
       SCREAMING_SNAKE_CASE__					=					len(self.first_signal      )
       SCREAMING_SNAKE_CASE__					=					len(self.second_signal      )

       SCREAMING_SNAKE_CASE__					=					max(__lowerCamelCase			,     __lowerCamelCase      )

       # create a zero matrix of max_length x max_length
       SCREAMING_SNAKE_CASE__					=					[[0] * max_length for i in range(__lowerCamelCase      )]

       # fills the smaller signal with zeros to make both signals of same length
       if length_first_signal < length_second_signal:
            self.first_signal += [0] * (max_length - length_first_signal)
       elif length_first_signal > length_second_signal:
            self.second_signal += [0] * (max_length - length_second_signal)
       for i in range(__lowerCamelCase      ):
            SCREAMING_SNAKE_CASE__					=					deque(self.second_signal      )
            rotated_signal.rotate(__lowerCamelCase      )
            for j, item in enumerate(__lowerCamelCase      ):
                 matrix[i][j] += item

        # multiply the matrix with the first signal
       SCREAMING_SNAKE_CASE__					=					np.matmul(np.transpose(__lowerCamelCase      )			,     np.transpose(self.first_signal      )      )

       # rounding-off to two decimal places
       return [round(__lowerCamelCase			,     2      ) for i in final_signal]


if __name__ == "__main__":
       doctest.testmod()


