




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

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

								__lowerCamelCase					:	List[Any]	       =				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_=__a						,	)

								return config, input_ids, attention_mask





					def     snake_case_				(    self     ):
								__lowerCamelCase					:	Tuple	       =				self.prepare_config_and_inputs()
								__lowerCamelCase       ,      __lowerCamelCase       ,      __lowerCamelCase					:	int	       =				config_and_inputs
								__lowerCamelCase					:	Tuple	       =				{'input_ids': input_ids, 'attention_mask': attention_mask}
								return config, inputs_dict



@require_flax
class __lowercase(      lowercase__	,	unittest.TestCase				):




					'''simple docstring'''


					__a						:						Tuple     		= (
					    (
					        FlaxDistilBertModel,
					        FlaxDistilBertForMaskedLM,
					        FlaxDistilBertForMultipleChoice,
					        FlaxDistilBertForQuestionAnswering,
					        FlaxDistilBertForSequenceClassification,
					        FlaxDistilBertForTokenClassification,
					        FlaxDistilBertForQuestionAnswering,
					    )
					    if is_flax_available()
					    else ()
					)
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	Tuple	       =				FlaxDistilBertModelTester(self     )





					@slow
					def     snake_case_				(    self     ):
								for model_class_name in self.all_model_classes:
											__lowerCamelCase					:	int	       =				model_class_name.from_pretrained('distilbert-base-uncased'     )
											__lowerCamelCase					:	Optional[Any]	       =				model(np.ones((1, 1)     )     )
											self.assertIsNotNone(__a     )



@require_flax
class __lowercase(      unittest.TestCase				):




					'''simple docstring'''


					@slow
					def     snake_case_				(    self     ):
								__lowerCamelCase					:	str	       =				FlaxDistilBertModel.from_pretrained('distilbert-base-uncased'     )
								__lowerCamelCase					:	Any	       =				np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]     )
								__lowerCamelCase					:	List[Any]	       =				np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
								__lowerCamelCase					:	int	       =				model(__a						,	attention_mask=__a     )[0]
								__lowerCamelCase					:	Optional[int]	       =				(1, 11, 768)
								self.assertEqual(output.shape						,	__a     )
								__lowerCamelCase					:	int	       =				np.array([[[-0.1_639, 0.3_299, 0.1_648], [-0.1_746, 0.3_289, 0.1_710], [-0.1_884, 0.3_357, 0.1_810]]]     )

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









"""simple docstring"""
from cva import destroyAllWindows, imread, imshow, waitKey





def 						UpperCAmelCase				(			A__:    Tuple     )  ->     Union[str, Any]:
			# getting number of pixels in the image
			__lowerCamelCase       ,      __lowerCamelCase					:	Optional[Any]	       =				img.shape[0], img.shape[1]

			# converting each pixel's color to its negative
			for i in range(A__     ):
						for j in range(A__     ):
									__lowerCamelCase					:	Optional[Any]	       =				[255, 255, 255] - img[i][j]

			return img


if __name__ == "__main__":
					# read original image
					a_				:    Dict										=     imread('''image_data/lena.jpg''', 1)

					# convert to its negative
					a_				:    str										=     convert_to_negative(img)

					# show result image
					imshow('''negative of original image''', img)
					waitKey(0)
					destroyAllWindows()



