

'''simple docstring'''





import unittest

import numpy as np

from transformers import DistilBertConfig, 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.distilbert.modeling_flax_distilbert import (
							    FlaxDistilBertForMaskedLM,
							    FlaxDistilBertForMultipleChoice,
							    FlaxDistilBertForQuestionAnswering,
							    FlaxDistilBertForSequenceClassification,
							    FlaxDistilBertForTokenClassification,
							    FlaxDistilBertModel,
							)







class 	lowercase    (				unittest.TestCase							):


		"""simple docstring"""




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


		def 		A__					(				self):
			_UpperCamelCase   :		List[Any]			=						ids_tensor([self.batch_size, self.seq_length]	,       self.vocab_size)

			_UpperCamelCase   :		Dict			=						None
			if self.use_attention_mask:
				_UpperCamelCase   :		Optional[int]			=						random_attention_mask([self.batch_size, self.seq_length])

			_UpperCamelCase   :		Dict			=						DistilBertConfig(
			    vocab_size=self.vocab_size	,       dim=self.hidden_size	,       n_layers=self.num_hidden_layers	,       n_heads=self.num_attention_heads	,       hidden_dim=self.intermediate_size	,       hidden_act=self.hidden_act	,       dropout=self.hidden_dropout_prob	,       attention_dropout=self.attention_probs_dropout_prob	,       max_position_embeddings=self.max_position_embeddings	,       initializer_range=self.initializer_range	,       tie_weights_=_lowerCAmelCase	,       )

			return config, input_ids, attention_mask






		def 		A__					(				self):
			_UpperCamelCase   :		List[str]			=						self.prepare_config_and_inputs()
			_UpperCamelCase	,		_UpperCamelCase	,		_UpperCamelCase   :		Optional[int]			=						config_and_inputs
			_UpperCamelCase   :		Tuple			=						{'input_ids': input_ids, 'attention_mask': attention_mask}
			return config, inputs_dict







@require_flax
class 	lowercase    (				_lowerCAmelCase    ,							unittest.TestCase							):


		"""simple docstring"""




		a__					       =  (
		    (
		        FlaxDistilBertModel,
		        FlaxDistilBertForMaskedLM,
		        FlaxDistilBertForMultipleChoice,
		        FlaxDistilBertForQuestionAnswering,
		        FlaxDistilBertForSequenceClassification,
		        FlaxDistilBertForTokenClassification,
		        FlaxDistilBertForQuestionAnswering,
		    )
		    if is_flax_available()
		    else ()
		)


		def 		A__					(				self):
			_UpperCamelCase   :		Dict			=						FlaxDistilBertModelTester(self)






		@slow
		def 		A__					(				self):







			for model_class_name in self.all_model_classes:
				_UpperCamelCase   :		Any			=						model_class_name.from_pretrained('distilbert-base-uncased')
				_UpperCamelCase   :		Optional[int]			=						model(np.ones((1, 1)))
				self.assertIsNotNone(_lowerCAmelCase)







@require_flax
class 	lowercase    (				unittest.TestCase							):


		"""simple docstring"""




		@slow
		def 		A__					(				self):
			_UpperCamelCase   :		List[Any]			=						FlaxDistilBertModel.from_pretrained('distilbert-base-uncased')
			_UpperCamelCase   :		str			=						np.array([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]])
			_UpperCamelCase   :		str			=						np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
			_UpperCamelCase   :		List[str]			=						model(_lowerCAmelCase	,       attention_mask=_lowerCAmelCase)[0]
			_UpperCamelCase   :		Dict			=						(1, 11, 7_68)
			self.assertEqual(output.shape	,       _lowerCAmelCase)
			_UpperCamelCase   :		Dict			=						np.array([[[-0.1_6_3_9, 0.3_2_9_9, 0.1_6_4_8], [-0.1_7_4_6, 0.3_2_8_9, 0.1_7_1_0], [-0.1_8_8_4, 0.3_3_5_7, 0.1_8_1_0]]])

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







from __future__ import annotations

import matplotlib.pyplot as plt  # type: ignore
import numpy

# initial triangle of Koch snowflake
lowerCAmelCase__								=		numpy.array([0, 0])
lowerCAmelCase__								=		numpy.array([0.5, 0.8_66_02_54])
lowerCAmelCase__								=		numpy.array([1, 0])
lowerCAmelCase__								=		[VECTOR_1, VECTOR_2, VECTOR_3, VECTOR_1]






def 					lowerCamelCase_     (							UpperCAmelCase_							:     list[numpy.ndarray]							,       UpperCAmelCase_							:     int	)						->				list[numpy.ndarray]:




	'''simple docstring'''




	_UpperCamelCase   :		Tuple			=						initial_vectors
	for _ in range(UpperCAmelCase_	):
		_UpperCamelCase   :		str			=						iteration_step(UpperCAmelCase_	)
	return vectors






def 					lowerCamelCase_     (							UpperCAmelCase_							:     list[numpy.ndarray]	)						->				list[numpy.ndarray]:




	'''simple docstring'''




	_UpperCamelCase   :		int			=						[]
	for i, start_vector in enumerate(vectors[:-1]	):
		_UpperCamelCase   :		Union[str, Any]			=						vectors[i + 1]
		new_vectors.append(UpperCAmelCase_	)
		_UpperCamelCase   :		Tuple			=						end_vector - start_vector
		new_vectors.append(start_vector + difference_vector / 3	)
		new_vectors.append(
		    start_vector + difference_vector / 3 + rotate(difference_vector / 3							,       6_0	)	)
		new_vectors.append(start_vector + difference_vector * 2 / 3	)
	new_vectors.append(vectors[-1]	)
	return new_vectors






def 					lowerCamelCase_     (							UpperCAmelCase_							:     numpy.ndarray							,       UpperCAmelCase_							:     float	)						->				numpy.ndarray:




	'''simple docstring'''




	_UpperCamelCase   :		str			=						numpy.radians(UpperCAmelCase_	)
	_UpperCamelCase	,		_UpperCamelCase   :		Optional[Any]			=						numpy.cos(UpperCAmelCase_	), numpy.sin(UpperCAmelCase_	)
	_UpperCamelCase   :		Any			=						numpy.array(((c, -s), (s, c))	)
	return numpy.dot(UpperCAmelCase_							,       UpperCAmelCase_	)






def 					lowerCamelCase_     (							UpperCAmelCase_							:     list[numpy.ndarray]	)						->				None:




	'''simple docstring'''




	_UpperCamelCase   :		str			=						plt.gca()
	axes.set_aspect('equal'	)

	# matplotlib.pyplot.plot takes a list of all x-coordinates and a list of all
	# y-coordinates as inputs, which are constructed from the vector-list using
	# zip()
	_UpperCamelCase	,		_UpperCamelCase   :		Dict			=						zip(*UpperCAmelCase_	)
	plt.plot(UpperCAmelCase_							,       UpperCAmelCase_	)
	plt.show()


if __name__ == "__main__":
							import doctest

							doctest.testmod()

							lowerCAmelCase__								=		iterate(INITIAL_VECTORS, 5)
							plot(processed_vectors)




