






"""simple docstring"""







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	,  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__=512	,  snake_case__=16	,  snake_case__=2	,  snake_case__=0.02	,  snake_case__=4	,  ):
												'''simple docstring'''
												lowercase__    :				Any=	parent
												lowercase__    :				Tuple=	batch_size
												lowercase__    :				str=	seq_length
												lowercase__    :				Tuple=	is_training
												lowercase__    :				Dict=	use_attention_mask
												lowercase__    :				str=	use_token_type_ids
												lowercase__    :				Optional[Any]=	use_labels
												lowercase__    :				List[str]=	vocab_size
												lowercase__    :				Dict=	hidden_size
												lowercase__    :				Any=	num_hidden_layers
												lowercase__    :				Optional[int]=	num_attention_heads
												lowercase__    :				str=	intermediate_size
												lowercase__    :				Any=	hidden_act
												lowercase__    :				Dict=	hidden_dropout_prob
												lowercase__    :				Dict=	attention_probs_dropout_prob
												lowercase__    :				str=	max_position_embeddings
												lowercase__    :				Union[str, Any]=	type_vocab_size
												lowercase__    :				Optional[Any]=	type_sequence_label_size
												lowercase__    :				str=	initializer_range
												lowercase__    :				int=	num_choices




						def 		UpperCAmelCase_	(       self      ):
												'''simple docstring'''
												lowercase__    :				Any=	ids_tensor([self.batch_size, self.seq_length]	,  self.vocab_size      )

												lowercase__    :				List[str]=	None
												if self.use_attention_mask:
																		lowercase__    :				Optional[int]=	random_attention_mask([self.batch_size, self.seq_length]      )

												lowercase__    :				List[Any]=	None
												if self.use_token_type_ids:
																		lowercase__    :				Optional[int]=	ids_tensor([self.batch_size, self.seq_length]	,  self.type_vocab_size      )

												lowercase__    :				Any=	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=snake_case__	,  initializer_range=self.initializer_range	,  )

												return config, input_ids, token_type_ids, attention_mask




						def 		UpperCAmelCase_	(       self      ):
												'''simple docstring'''
												lowercase__    :				Dict=	self.prepare_config_and_inputs()
												lowercase__,     lowercase__,     lowercase__,     lowercase__    :				int=	config_and_inputs
												lowercase__    :				List[str]=	{"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": attention_mask}
												return config, inputs_dict


@require_flax
class    __UpperCAmelCase(       SCREAMING_SNAKE_CASE__  ,  unittest.TestCase							):




						"""simple docstring"""




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




						def 		UpperCAmelCase_	(       self      ):
												'''simple docstring'''
												lowercase__    :				Any=	FlaxAlbertModelTester(self      )




						@slow
						def 		UpperCAmelCase_	(       self      ):
												'''simple docstring'''
												for model_class_name in self.all_model_classes:
																		lowercase__    :				Dict=	model_class_name.from_pretrained("albert-base-v2"      )
																		lowercase__    :				Tuple=	model(np.ones((1, 1)      )      )
																		self.assertIsNotNone(snake_case__      )


@require_flax
class    __UpperCAmelCase(       unittest.TestCase							):




						"""simple docstring"""




						@slow
						def 		UpperCAmelCase_	(       self      ):
												'''simple docstring'''
												lowercase__    :				Any=	FlaxAlbertModel.from_pretrained("albert-base-v2"      )
												lowercase__    :				List[str]=	np.array([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]      )
												lowercase__    :				Any=	np.array([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]      )
												lowercase__    :				Any=	model(snake_case__	,  attention_mask=snake_case__      )[0]
												lowercase__    :				str=	(1, 11, 768)
												self.assertEqual(output.shape	,  snake_case__      )
												lowercase__    :				Any=	np.array(
												    [[[-0.65_13, 1.50_35, -0.27_66], [-0.65_15, 1.50_46, -0.27_80], [-0.65_12, 1.50_49, -0.27_84]]]      )

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














"""simple docstring"""







from __future__ import annotations


class    __UpperCAmelCase:




						"""simple docstring"""




						def __init__(       self	,  snake_case__      ):
												'''simple docstring'''
												lowercase__    :				List[Any]=	data
												lowercase__    :				Node | None=	None
												lowercase__    :				Node | None=	None





def 						lowercase__(A						)    ->None:  # In Order traversal of the tree




						"""simple docstring"""



						if tree:
												display(tree.left						)
												print(tree.data						)
												display(tree.right						)





def 						lowercase__(A						)    ->int:




						"""simple docstring"""



						return 1 + max(depth_of_tree(tree.left						) ,		depth_of_tree(tree.right						)						) if tree else 0





def 						lowercase__(A						)    ->bool:




						"""simple docstring"""



						if not tree:
												return True
						if tree.left and tree.right:
												return is_full_binary_tree(tree.left						) and is_full_binary_tree(tree.right						)
						else:
												return not tree.left and not tree.right





def 						lowercase__()    ->None:  # Main function for testing.




						"""simple docstring"""



						lowercase__    :				Tuple=	Node(1						)
						lowercase__    :				Optional[int]=	Node(2						)
						lowercase__    :				List[str]=	Node(3						)
						lowercase__    :				Tuple=	Node(4						)
						lowercase__    :				Optional[int]=	Node(5						)
						lowercase__    :				Any=	Node(6						)
						lowercase__    :				Optional[Any]=	Node(7						)
						lowercase__    :				Optional[int]=	Node(8						)
						lowercase__    :				List[str]=	Node(9						)

						print(is_full_binary_tree(A						)						)
						print(depth_of_tree(A						)						)
						print("Tree is: "						)
						display(A						)


if __name__ == "__main__":
			main()






