def       _snake_case	(   lowerCAmelCase							:   int	):
		"""simple docstring"""







		SCREAMING_SNAKE_CASE_  :		List[str]				      =    generate_pascal_triangle(lowerCAmelCase	)
		for row_idx in range(lowerCAmelCase	):
				# Print left spaces
				for _ in range(num_rows - row_idx - 1	):
						print(end=" "	)
				# Print row values
				for col_idx in range(row_idx + 1	):
						if col_idx != row_idx:
								print(triangle[row_idx][col_idx]   , end=" "	)
						else:
								print(triangle[row_idx][col_idx]   , end=""	)
				print()




def       _snake_case	(   lowerCAmelCase							:   int	):
		"""simple docstring"""







		if not isinstance(lowerCAmelCase   , lowerCAmelCase	):
				raise TypeError("The input value of 'num_rows' should be 'int'"	)

		if num_rows == 0:
				return []
		elif num_rows < 0:
				raise ValueError(
				    "The input value of 'num_rows' should be greater than or equal to 0"	)

		SCREAMING_SNAKE_CASE_  :		list[list[int]]				      =    []
		for current_row_idx in range(lowerCAmelCase	):
				SCREAMING_SNAKE_CASE_  :		str				      =    populate_current_row(lowerCAmelCase   , lowerCAmelCase	)
				triangle.append(lowerCAmelCase	)
		return triangle




def       _snake_case	(   lowerCAmelCase							:   list[list[int]]   , lowerCAmelCase							:   int	):
		"""simple docstring"""







		SCREAMING_SNAKE_CASE_  :		str				      =    [-1] * (current_row_idx + 1)
		# first and last elements of current row are equal to 1
		SCREAMING_SNAKE_CASE_      ,    SCREAMING_SNAKE_CASE_  :		Tuple				      =    1, 1
		for current_col_idx in range(1   , lowerCAmelCase	):
				calculate_current_element(
				    lowerCAmelCase   , lowerCAmelCase   , lowerCAmelCase   , lowerCAmelCase	)
		return current_row




def       _snake_case	(   lowerCAmelCase							:   list[list[int]]   , lowerCAmelCase							:   list[int]   , lowerCAmelCase							:   int   , lowerCAmelCase							:   int   , ):
		"""simple docstring"""







		SCREAMING_SNAKE_CASE_  :		Any				      =    triangle[current_row_idx - 1][current_col_idx - 1]
		SCREAMING_SNAKE_CASE_  :		List[Any]				      =    triangle[current_row_idx - 1][current_col_idx]
		SCREAMING_SNAKE_CASE_  :		Union[str, Any]				      =    above_to_left_elt + above_to_right_elt




def       _snake_case	(   lowerCAmelCase							:   int	):
		"""simple docstring"""







		if not isinstance(lowerCAmelCase   , lowerCAmelCase	):
				raise TypeError("The input value of 'num_rows' should be 'int'"	)

		if num_rows == 0:
				return []
		elif num_rows < 0:
				raise ValueError(
				    "The input value of 'num_rows' should be greater than or equal to 0"	)

		SCREAMING_SNAKE_CASE_  :		list[list[int]]				      =    [[1]]

		for row_index in range(1   , lowerCAmelCase	):
				SCREAMING_SNAKE_CASE_  :		Tuple				      =    [0] + result[-1] + [0]
				SCREAMING_SNAKE_CASE_  :		List[str]				      =    row_index + 1
				# Calculate the number of distinct elements in a row
				SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    sum(divmod(lowerCAmelCase   , 2	)	)
				SCREAMING_SNAKE_CASE_  :		List[Any]				      =    [
				    temp_row[i - 1] + temp_row[i] for i in range(1   , distinct_elements + 1	)
				]
				SCREAMING_SNAKE_CASE_  :		Optional[Any]				      =    row_first_half[: (row_index + 1) // 2]
				row_second_half.reverse()
				SCREAMING_SNAKE_CASE_  :		Tuple				      =    row_first_half + row_second_half
				result.append(lowerCAmelCase	)

		return result




def       _snake_case	(   ):
		"""simple docstring"""







		from collections.abc import Callable
		from timeit import timeit

		def benchmark_a_function(lowerCAmelCase							:   Callable   , lowerCAmelCase							:   int	) -> None:
				SCREAMING_SNAKE_CASE_  :		Optional[int]				      =    f'{func.__name__}({value})'
				SCREAMING_SNAKE_CASE_  :		str				      =    timeit(f'__main__.{call}'   , setup="import __main__"	)
				# print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
				print(f'{call:38} -- {timing:.4f} seconds'	)

		for value in range(1_5	):  # (1, 7, 14):
				for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
						benchmark_a_function(lowerCAmelCase   , lowerCAmelCase	)
				print()


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		benchmark()

"""simple docstring"""




from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
				import numpy
				import tensorflow as tf

				from transformers import (
				    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
				    BertConfig,
				    DPRConfig,
				    TFDPRContextEncoder,
				    TFDPRQuestionEncoder,
				    TFDPRReader,
				)
class 			UpperCamelCase__:





						def __init__(				self						,__UpperCAmelCase						,__UpperCAmelCase=13						,__UpperCAmelCase=7						,__UpperCAmelCase=True						,__UpperCAmelCase=True						,__UpperCAmelCase=True						,__UpperCAmelCase=True						,__UpperCAmelCase=99						,__UpperCAmelCase=32						,__UpperCAmelCase=2						,__UpperCAmelCase=4						,__UpperCAmelCase=37						,__UpperCAmelCase="gelu"						,__UpperCAmelCase=0.1						,__UpperCAmelCase=0.1						,__UpperCAmelCase=5_12						,__UpperCAmelCase=16						,__UpperCAmelCase=2						,__UpperCAmelCase=0.0_2						,__UpperCAmelCase=3						,__UpperCAmelCase=4						,__UpperCAmelCase=None						,__UpperCAmelCase=0						,)    -> Dict:
													A__		   =							parent
													A__		   =							batch_size
													A__		   =							seq_length
													A__		   =							is_training
													A__		   =							use_input_mask
													A__		   =							use_token_type_ids
													A__		   =							use_labels
													A__		   =							vocab_size
													A__		   =							hidden_size
													A__		   =							num_hidden_layers
													A__		   =							num_attention_heads
													A__		   =							intermediate_size
													A__		   =							hidden_act
													A__		   =							hidden_dropout_prob
													A__		   =							attention_probs_dropout_prob
													A__		   =							max_position_embeddings
													A__		   =							type_vocab_size
													A__		   =							type_sequence_label_size
													A__		   =							initializer_range
													A__		   =							num_labels
													A__		   =							num_choices
													A__		   =							scope
													A__		   =							projection_dim





						def  snake_case__		(				self   )    -> Optional[Any]:
													A__		   =							ids_tensor([self.batch_size, self.seq_length]						,self.vocab_size   )

													A__		   =							None
													if self.use_input_mask:
																				# follow test_modeling_tf_ctrl.py
																				A__		   =							random_attention_mask([self.batch_size, self.seq_length]   )

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

													A__		   =							None
													A__		   =							None
													A__		   =							None
													if self.use_labels:
																				A__		   =							ids_tensor([self.batch_size]						,self.type_sequence_label_size   )
																				A__		   =							ids_tensor([self.batch_size, self.seq_length]						,self.num_labels   )
																				A__		   =							ids_tensor([self.batch_size]						,self.num_choices   )

													A__		   =							BertConfig(
													    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=__UpperCAmelCase						,initializer_range=self.initializer_range						,)
													A__		   =							DPRConfig(projection_dim=self.projection_dim						,**config.to_dict()   )

													return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase   )    -> Tuple:
													A__		   =							TFDPRContextEncoder(config=__UpperCAmelCase   )
													A__		   =							model(__UpperCAmelCase						,attention_mask=__UpperCAmelCase						,token_type_ids=__UpperCAmelCase   )
													A__		   =							model(__UpperCAmelCase						,token_type_ids=__UpperCAmelCase   )
													A__		   =							model(__UpperCAmelCase   )
													self.parent.assertEqual(result.pooler_output.shape						,(self.batch_size, self.projection_dim or self.hidden_size)   )





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase   )    -> Union[str, Any]:
													A__		   =							TFDPRQuestionEncoder(config=__UpperCAmelCase   )
													A__		   =							model(__UpperCAmelCase						,attention_mask=__UpperCAmelCase						,token_type_ids=__UpperCAmelCase   )
													A__		   =							model(__UpperCAmelCase						,token_type_ids=__UpperCAmelCase   )
													A__		   =							model(__UpperCAmelCase   )
													self.parent.assertEqual(result.pooler_output.shape						,(self.batch_size, self.projection_dim or self.hidden_size)   )





						def  snake_case__		(				self						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase						,__UpperCAmelCase   )    -> Optional[int]:
													A__		   =							TFDPRReader(config=__UpperCAmelCase   )
													A__		   =							model(__UpperCAmelCase						,attention_mask=__UpperCAmelCase   )

													self.parent.assertEqual(result.start_logits.shape						,(self.batch_size, self.seq_length)   )
													self.parent.assertEqual(result.end_logits.shape						,(self.batch_size, self.seq_length)   )
													self.parent.assertEqual(result.relevance_logits.shape						,(self.batch_size,)   )





						def  snake_case__		(				self   )    -> int:
													A__		   =							self.prepare_config_and_inputs()
													(
													    (
													    A__
													)   ,     (
													    A__
													)   ,     (
													    A__
													)   ,     (
													    A__
													)   ,     (
													    A__
													)   ,     (
													    A__
													)   ,     (
													    A__
													)   ,     
													)		   =							config_and_inputs
													A__		   =							{'input_ids': input_ids}
													return config, inputs_dict






@require_tf
class 			UpperCamelCase__(	__A						,  __A						,  unittest.TestCase       ):
						lowerCAmelCase__     :  Optional[int]  							=						(
						    (
						        TFDPRContextEncoder,
						        TFDPRQuestionEncoder,
						        TFDPRReader,
						    )
						    if is_tf_available()
						    else ()
						)
						lowerCAmelCase__     :  List[str]  							=						{'feature-extraction': TFDPRQuestionEncoder} if is_tf_available() else {}

						lowerCAmelCase__     :  Tuple  							=						False
						lowerCAmelCase__     :  Optional[int]  							=						False
						lowerCAmelCase__     :  List[str]  							=						False
						lowerCAmelCase__     :  int  							=						False
						lowerCAmelCase__     :  str  							=						False





						def  snake_case__		(				self   )    -> str:
													A__		   =							TFDPRModelTester(self   )
													A__		   =							ConfigTester(self						,config_class=__UpperCAmelCase						,hidden_size=37   )





						def  snake_case__		(				self   )    -> Optional[Any]:
													self.config_tester.run_common_tests()





						def  snake_case__		(				self   )    -> int:
													A__		   =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_dpr_context_encoder(*__UpperCAmelCase   )





						def  snake_case__		(				self   )    -> Optional[Any]:
													A__		   =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_dpr_question_encoder(*__UpperCAmelCase   )





						def  snake_case__		(				self   )    -> List[str]:
													A__		   =							self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_dpr_reader(*__UpperCAmelCase   )





						@slow
						def  snake_case__		(				self   )    -> int:
													for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																				A__		   =							TFDPRContextEncoder.from_pretrained(__UpperCAmelCase   )
																				self.assertIsNotNone(__UpperCAmelCase   )

													for model_name in TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																				A__		   =							TFDPRContextEncoder.from_pretrained(__UpperCAmelCase   )
																				self.assertIsNotNone(__UpperCAmelCase   )

													for model_name in TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																				A__		   =							TFDPRQuestionEncoder.from_pretrained(__UpperCAmelCase   )
																				self.assertIsNotNone(__UpperCAmelCase   )

													for model_name in TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																				A__		   =							TFDPRReader.from_pretrained(__UpperCAmelCase   )
																				self.assertIsNotNone(__UpperCAmelCase   )






@require_tf
class 			UpperCamelCase__(	unittest.TestCase       ):





						@slow
						def  snake_case__		(				self   )    -> Optional[Any]:
													A__		   =							TFDPRQuestionEncoder.from_pretrained('facebook/dpr-question_encoder-single-nq-base'   )

													A__		   =							tf.constant(
													    [[1_01, 75_92, 10_10, 20_03, 20_26, 38_99, 1_01_40, 10_29, 1_02]]   )  # [CLS] hello, is my dog cute? [SEP]
													A__		   =							model(__UpperCAmelCase   )[0]  # embedding shape = (1, 768)
													# compare the actual values for a slice.
													A__		   =							tf.constant(
													    [
													        [
													            0.0_3_2_3_6_2_5_3,
													            0.1_2_7_5_3_3_3_5,
													            0.1_6_8_1_8_5_0_9,
													            0.0_0_2_7_9_7_8_6,
													            0.3_8_9_6_9_3_3,
													            0.2_4_2_6_4_9_4_5,
													            0.2_1_7_8_9_7_1,
													            -0.0_2_3_3_5_2_2_7,
													            -0.0_8_4_8_1_9_5_9,
													            -0.1_4_3_2_4_1_1_7,
													        ]
													    ]   )
													self.assertTrue(numpy.allclose(output[:, :10].numpy()						,expected_slice.numpy()						,atol=1e-4   )   )





