

from __future__ import annotations

import collections
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import is_tf_available, is_vision_available

from ...test_modeling_tf_common import floats_tensor, ids_tensor, random_attention_mask
from ..bert.test_modeling_tf_bert import TFBertModelTester
from ..clip.test_modeling_tf_clip import TFCLIPVisionModelTester
from ..deit.test_modeling_tf_deit import TFDeiTModelTester
from ..roberta.test_modeling_tf_roberta import TFRobertaModelTester
from ..vit.test_modeling_tf_vit import TFViTModelTester


if is_tf_available():
				from transformers import (
				    TFBertModel,
				    TFCLIPVisionModel,
				    TFDeiTModel,
				    TFRobertaModel,
				    TFVisionTextDualEncoderModel,
				    TFViTModel,
				    VisionTextDualEncoderConfig,
				)

if is_vision_available():
				from PIL import Image

				from transformers import VisionTextDualEncoderProcessor



def       __lowerCAmelCase      (						A    ):







	if isinstance(A       ,     collections.abc.Iterable    ):
		return x
	return (x, x)

@require_tf
class 						__UpperCamelCase    :




	def       __A					(		self	:						List[Any]		,	lowerCAmelCase	:						str		,	lowerCAmelCase	:						Optional[Any]							):


		'''simple docstring'''







		pass




	def       __A					(		self	:						Dict							):


		'''simple docstring'''







		pass




	def       __A					(		self	:						Any							):


		'''simple docstring'''







		pass




	def       __A					(		self	:						int		,	lowerCAmelCase	:						Optional[int]		,	lowerCAmelCase	:						Any		,	lowerCAmelCase	:						Any		,	lowerCAmelCase	:						Optional[Any]		,	lowerCAmelCase	:						Dict=None		,	**lowerCAmelCase	:						int							):


		'''simple docstring'''







		UpperCAmelCase_       				=			VisionTextDualEncoderConfig.from_vision_text_configs(_lowerCAmelCase		,	_lowerCAmelCase							)

		UpperCAmelCase_       				=			TFVisionTextDualEncoderModel(_lowerCAmelCase							)

		UpperCAmelCase_       				=			model(input_ids=_lowerCAmelCase		,	pixel_values=_lowerCAmelCase		,	attention_mask=_lowerCAmelCase							)

		self.assertEqual(output["text_embeds"].shape		,	(input_ids.shape[0], config.projection_dim)							)
		self.assertEqual(output["image_embeds"].shape		,	(pixel_values.shape[0], config.projection_dim)							)




	def       __A					(		self	:						str		,	lowerCAmelCase	:						Tuple		,	lowerCAmelCase	:						str		,	lowerCAmelCase	:						List[Any]		,	lowerCAmelCase	:						List[str]		,	lowerCAmelCase	:						int=None		,	**lowerCAmelCase	:						Dict							):


		'''simple docstring'''







		UpperCAmelCase_				,   UpperCAmelCase_       				=			self.get_vision_text_model(_lowerCAmelCase		,	_lowerCAmelCase							)
		UpperCAmelCase_       				=			TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase		,	text_model=_lowerCAmelCase							)

		UpperCAmelCase_       				=			model(input_ids=_lowerCAmelCase		,	pixel_values=_lowerCAmelCase		,	attention_mask=_lowerCAmelCase							)

		self.assertEqual(output["text_embeds"].shape		,	(input_ids.shape[0], model.config.projection_dim)							)
		self.assertEqual(output["image_embeds"].shape		,	(pixel_values.shape[0], model.config.projection_dim)							)




	def       __A					(		self	:						Optional[Any]		,	lowerCAmelCase	:						List[Any]		,	lowerCAmelCase	:						Any		,	lowerCAmelCase	:						Dict		,	lowerCAmelCase	:						str		,	lowerCAmelCase	:						Any=None		,	**lowerCAmelCase	:						str							):


		'''simple docstring'''







		UpperCAmelCase_				,   UpperCAmelCase_       				=			self.get_vision_text_model(_lowerCAmelCase		,	_lowerCAmelCase							)
		UpperCAmelCase_       				=			{"vision_model": vision_model, "text_model": text_model}
		UpperCAmelCase_       				=			TFVisionTextDualEncoderModel.from_vision_text_pretrained(**_lowerCAmelCase							)

		UpperCAmelCase_       				=			model(input_ids=_lowerCAmelCase		,	pixel_values=_lowerCAmelCase		,	attention_mask=_lowerCAmelCase							)

		self.assertEqual(output["text_embeds"].shape		,	(input_ids.shape[0], model.config.projection_dim)							)
		self.assertEqual(output["image_embeds"].shape		,	(pixel_values.shape[0], model.config.projection_dim)							)




	def       __A					(		self	:						Dict		,	lowerCAmelCase	:						Union[str, Any]		,	lowerCAmelCase	:						List[str]		,	lowerCAmelCase	:						Tuple		,	lowerCAmelCase	:						Optional[int]		,	lowerCAmelCase	:						List[Any]=None		,	**lowerCAmelCase	:						Any							):


		'''simple docstring'''







		UpperCAmelCase_				,   UpperCAmelCase_       				=			self.get_vision_text_model(_lowerCAmelCase		,	_lowerCAmelCase							)
		UpperCAmelCase_       				=			TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase		,	text_model=_lowerCAmelCase							)

		UpperCAmelCase_       				=			model(input_ids=_lowerCAmelCase		,	pixel_values=_lowerCAmelCase		,	attention_mask=_lowerCAmelCase							)
		UpperCAmelCase_       				=			output[0].numpy()

		with tempfile.TemporaryDirectory() as tmpdirname:
			model.save_pretrained(_lowerCAmelCase							)
			UpperCAmelCase_       				=			TFVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase							)

			UpperCAmelCase_       				=			model(input_ids=_lowerCAmelCase		,	pixel_values=_lowerCAmelCase		,	attention_mask=_lowerCAmelCase							)
			UpperCAmelCase_       				=			after_output[0].numpy()
			UpperCAmelCase_       				=			np.amax(np.abs(out_a - out_a							)							)
			self.assertLessEqual(_lowerCAmelCase		,	1e-5							)




	def       __A					(		self	:						int		,	lowerCAmelCase	:						Any		,	lowerCAmelCase	:						Optional[int]		,	lowerCAmelCase	:						str		,	lowerCAmelCase	:						Optional[int]		,	lowerCAmelCase	:						Optional[int]=None		,	**lowerCAmelCase	:						Optional[int]							):


		'''simple docstring'''







		UpperCAmelCase_				,   UpperCAmelCase_       				=			self.get_vision_text_model(_lowerCAmelCase		,	_lowerCAmelCase							)
		UpperCAmelCase_       				=			TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase		,	text_model=_lowerCAmelCase							)

		UpperCAmelCase_       				=			model(
		    input_ids=_lowerCAmelCase		,	pixel_values=_lowerCAmelCase		,	attention_mask=_lowerCAmelCase		,	output_attentions=_lowerCAmelCase							)

		UpperCAmelCase_       				=			output.vision_model_output.attentions
		self.assertEqual(len(_lowerCAmelCase							)		,	vision_config.num_hidden_layers							)

		# in ViT, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
		UpperCAmelCase_       				=			to_atuple(vision_model.config.image_size							)
		UpperCAmelCase_       				=			to_atuple(vision_model.config.patch_size							)
		UpperCAmelCase_       				=			(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
		UpperCAmelCase_       				=			num_patches + 1
		self.assertEqual(vision_attentions[0].shape[-3:]		,	(vision_config.num_attention_heads, seq_len, seq_len)							)

		UpperCAmelCase_       				=			output.text_model_output.attentions
		self.assertEqual(len(_lowerCAmelCase							)		,	text_config.num_hidden_layers							)

		self.assertEqual(
		    text_attentions[0].shape[-3:]		,	(text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])		,	)




	def       __A					(		self	:						List[Any]		,	lowerCAmelCase	:						np.ndarray		,	lowerCAmelCase	:						np.ndarray		,	lowerCAmelCase	:						float							):


		'''simple docstring'''







		UpperCAmelCase_       				=			np.abs((a - b)							).max()
		self.assertLessEqual(_lowerCAmelCase		,	_lowerCAmelCase		,	F"Difference between torch and flax is {diff} (>= {tol})."							)




	def       __A					(		self	:						List[Any]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.prepare_config_and_inputs()
		self.check_vision_text_dual_encoder_model(**_lowerCAmelCase							)




	def       __A					(		self	:						int							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.prepare_config_and_inputs()
		self.check_model_from_pretrained_configs(**_lowerCAmelCase							)




	def       __A					(		self	:						Union[str, Any]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.prepare_config_and_inputs()
		self.check_vision_text_dual_encoder_from_pretrained(**_lowerCAmelCase							)




	def       __A					(		self	:						List[str]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.prepare_config_and_inputs()
		self.check_save_load(**_lowerCAmelCase							)




	def       __A					(		self	:						Dict							):


		'''simple docstring'''







		UpperCAmelCase_       				=			self.prepare_config_and_inputs()
		self.check_vision_text_output_attention(**_lowerCAmelCase							)




	@slow
	def       __A					(		self	:						Optional[int]							):


		'''simple docstring'''







		UpperCAmelCase_				,   UpperCAmelCase_       				=			self.get_pretrained_model_and_inputs()

		UpperCAmelCase_       				=			model_a(**_lowerCAmelCase							)
		UpperCAmelCase_       				=			outputs[0].numpy()

		with tempfile.TemporaryDirectory() as tmp_dirname:
			model_a.save_pretrained(_lowerCAmelCase							)
			UpperCAmelCase_       				=			TFVisionTextDualEncoderModel.from_pretrained(_lowerCAmelCase							)

			UpperCAmelCase_       				=			model_a(**_lowerCAmelCase							)
			UpperCAmelCase_       				=			after_outputs[0].numpy()
			UpperCAmelCase_       				=			np.amax(np.abs(out_a - out_a							)							)
			self.assertLessEqual(_lowerCAmelCase		,	1e-5							)


@require_tf
class 						__UpperCamelCase    (					_lowerCAmelCase     ,     unittest.TestCase						):




	def       __A					(		self	:						Optional[int]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			TFVisionTextDualEncoderModel.from_vision_text_pretrained(
		    "hf-internal-testing/tiny-random-vit"		,	"hf-internal-testing/tiny-random-bert"							)
		UpperCAmelCase_       				=			13
		UpperCAmelCase_       				=			floats_tensor(
		    [
		        batch_size,
		        model.vision_model.config.num_channels,
		        model.vision_model.config.image_size,
		        model.vision_model.config.image_size,
		    ]							)
		UpperCAmelCase_       				=			ids_tensor([batch_size, 4]		,	model.text_model.config.vocab_size							)
		UpperCAmelCase_       				=			random_attention_mask([batch_size, 4]							)
		UpperCAmelCase_       				=			{"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

		return model, inputs




	def       __A					(		self	:						Tuple		,	lowerCAmelCase	:						Tuple		,	lowerCAmelCase	:						List[str]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			TFViTModel(_lowerCAmelCase		,	name="vision_model"							)
		UpperCAmelCase_       				=			TFBertModel(_lowerCAmelCase		,	name="text_model"							)
		return vision_model, text_model




	def       __A					(		self	:						Dict							):


		'''simple docstring'''







		UpperCAmelCase_       				=			TFViTModelTester(self							)
		UpperCAmelCase_       				=			TFBertModelTester(self							)
		UpperCAmelCase_       				=			vit_model_tester.prepare_config_and_inputs()
		UpperCAmelCase_       				=			bert_model_tester.prepare_config_and_inputs()

		UpperCAmelCase_				,   UpperCAmelCase_				,   UpperCAmelCase_       				=			vision_config_and_inputs

		(
		    (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   						
		)       				=			text_config_and_inputs

		return {
		    "text_config": text_config,
		    "vision_config": vision_config,
		    "pixel_values": pixel_values,
		    "attention_mask": input_mask,
		    "input_ids": input_ids,
		    "text_token_type_ids": token_type_ids,
		    "text_sequence_labels": sequence_labels,
		    "text_token_labels": token_labels,
		    "text_choice_labels": choice_labels,
		}


@require_tf
class 						__UpperCamelCase    (					_lowerCAmelCase     ,     unittest.TestCase						):




	def       __A					(		self	:						Tuple							):


		'''simple docstring'''







		UpperCAmelCase_       				=			TFVisionTextDualEncoderModel.from_vision_text_pretrained(
		    "Rocketknight1/tiny-random-deit-tf"		,	"hf-internal-testing/tiny-random-roberta"							)
		UpperCAmelCase_       				=			13
		UpperCAmelCase_       				=			floats_tensor(
		    [
		        batch_size,
		        model.vision_model.config.num_channels,
		        model.vision_model.config.image_size,
		        model.vision_model.config.image_size,
		    ]							)
		UpperCAmelCase_       				=			ids_tensor([batch_size, 4]		,	model.text_model.config.vocab_size							)
		UpperCAmelCase_       				=			random_attention_mask([batch_size, 4]							)
		UpperCAmelCase_       				=			{"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

		return model, inputs




	def       __A					(		self	:						Optional[Any]		,	lowerCAmelCase	:						Union[str, Any]		,	lowerCAmelCase	:						str		,	lowerCAmelCase	:						int		,	lowerCAmelCase	:						Tuple		,	lowerCAmelCase	:						int=None		,	**lowerCAmelCase	:						Tuple							):


		'''simple docstring'''







		UpperCAmelCase_				,   UpperCAmelCase_       				=			self.get_vision_text_model(_lowerCAmelCase		,	_lowerCAmelCase							)
		UpperCAmelCase_       				=			TFVisionTextDualEncoderModel(vision_model=_lowerCAmelCase		,	text_model=_lowerCAmelCase							)

		UpperCAmelCase_       				=			model(
		    input_ids=_lowerCAmelCase		,	pixel_values=_lowerCAmelCase		,	attention_mask=_lowerCAmelCase		,	output_attentions=_lowerCAmelCase							)

		UpperCAmelCase_       				=			output.vision_model_output.attentions
		self.assertEqual(len(_lowerCAmelCase							)		,	vision_config.num_hidden_layers							)

		# in DEiT, the seq_len equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
		UpperCAmelCase_       				=			to_atuple(vision_model.config.image_size							)
		UpperCAmelCase_       				=			to_atuple(vision_model.config.patch_size							)
		UpperCAmelCase_       				=			(image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])
		UpperCAmelCase_       				=			num_patches + 2
		self.assertEqual(vision_attentions[0].shape[-3:]		,	(vision_config.num_attention_heads, seq_len, seq_len)							)

		UpperCAmelCase_       				=			output.text_model_output.attentions
		self.assertEqual(len(_lowerCAmelCase							)		,	text_config.num_hidden_layers							)

		self.assertEqual(
		    text_attentions[0].shape[-3:]		,	(text_config.num_attention_heads, input_ids.shape[-1], input_ids.shape[-1])		,	)




	def       __A					(		self	:						Tuple		,	lowerCAmelCase	:						List[str]		,	lowerCAmelCase	:						Dict							):


		'''simple docstring'''







		UpperCAmelCase_       				=			TFDeiTModel(_lowerCAmelCase		,	name="vision_model"							)
		UpperCAmelCase_       				=			TFRobertaModel(_lowerCAmelCase		,	name="text_model"							)
		return vision_model, text_model




	def       __A					(		self	:						Tuple							):


		'''simple docstring'''







		UpperCAmelCase_       				=			TFDeiTModelTester(self							)
		UpperCAmelCase_       				=			TFRobertaModelTester(self							)
		UpperCAmelCase_       				=			vit_model_tester.prepare_config_and_inputs()
		UpperCAmelCase_       				=			bert_model_tester.prepare_config_and_inputs()

		UpperCAmelCase_				,   UpperCAmelCase_				,   UpperCAmelCase_       				=			vision_config_and_inputs

		(
		    (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   						
		)       				=			text_config_and_inputs

		return {
		    "text_config": text_config,
		    "vision_config": vision_config,
		    "pixel_values": pixel_values,
		    "attention_mask": input_mask,
		    "input_ids": input_ids,
		    "text_token_type_ids": token_type_ids,
		    "text_sequence_labels": sequence_labels,
		    "text_token_labels": token_labels,
		    "text_choice_labels": choice_labels,
		}


@require_tf
class 						__UpperCamelCase    (					_lowerCAmelCase     ,     unittest.TestCase						):




	def       __A					(		self	:						int							):


		'''simple docstring'''







		UpperCAmelCase_       				=			TFVisionTextDualEncoderModel.from_vision_text_pretrained(
		    "Rocketknight1/tiny-random-clip-tf"		,	"hf-internal-testing/tiny-random-bert"							)
		UpperCAmelCase_       				=			13
		UpperCAmelCase_       				=			floats_tensor(
		    [
		        batch_size,
		        model.vision_model.config.num_channels,
		        model.vision_model.config.image_size,
		        model.vision_model.config.image_size,
		    ]							)
		UpperCAmelCase_       				=			ids_tensor([batch_size, 4]		,	model.text_model.config.vocab_size							)
		UpperCAmelCase_       				=			random_attention_mask([batch_size, 4]							)
		UpperCAmelCase_       				=			{"pixel_values": pixel_values, "input_ids": input_ids, "attention_mask": attention_mask}

		return model, inputs




	def       __A					(		self	:						Optional[int]		,	lowerCAmelCase	:						Dict		,	lowerCAmelCase	:						Union[str, Any]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			TFCLIPVisionModel(_lowerCAmelCase		,	name="vision_model"							)
		UpperCAmelCase_       				=			TFBertModel(_lowerCAmelCase		,	name="text_model"							)
		return vision_model, text_model




	def       __A					(		self	:						Union[str, Any]							):


		'''simple docstring'''







		UpperCAmelCase_       				=			TFCLIPVisionModelTester(self							)
		UpperCAmelCase_       				=			TFBertModelTester(self							)
		UpperCAmelCase_       				=			clip_model_tester.prepare_config_and_inputs()
		UpperCAmelCase_       				=			bert_model_tester.prepare_config_and_inputs()

		UpperCAmelCase_				,   UpperCAmelCase_       				=			vision_config_and_inputs

		(
		    (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   (
		    UpperCAmelCase_						
		)				,   						
		)       				=			text_config_and_inputs

		return {
		    "text_config": text_config,
		    "vision_config": vision_config,
		    "pixel_values": pixel_values,
		    "attention_mask": input_mask,
		    "input_ids": input_ids,
		    "text_token_type_ids": token_type_ids,
		    "text_sequence_labels": sequence_labels,
		    "text_token_labels": token_labels,
		    "text_choice_labels": choice_labels,
		}


@require_vision
@require_tf
class 						__UpperCamelCase    (					unittest.TestCase						):




	@slow
	def       __A					(		self	:						int							):


		'''simple docstring'''







		UpperCAmelCase_       				=			TFVisionTextDualEncoderModel.from_pretrained(
		    "clip-italian/clip-italian"		,	logit_scale_init_value=1.0		,	from_pt=_lowerCAmelCase							)
		UpperCAmelCase_       				=			VisionTextDualEncoderProcessor.from_pretrained("clip-italian/clip-italian"							)

		UpperCAmelCase_       				=			Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"							)
		UpperCAmelCase_       				=			processor(
		    text=["una foto di un gatto", "una foto di un cane"]		,	images=_lowerCAmelCase		,	padding=_lowerCAmelCase		,	return_tensors="np"							)

		UpperCAmelCase_       				=			model(**_lowerCAmelCase							)

		# verify the logits
		self.assertEqual(outputs.logits_per_image.shape		,	(inputs.pixel_values.shape[0], inputs.input_ids.shape[0])							)
		self.assertEqual(
		    outputs.logits_per_text.shape		,	(inputs.input_ids.shape[0], inputs.pixel_values.shape[0])		,	)

		UpperCAmelCase_       				=			np.array([[1.2_284_727, 0.3_104_122]]							)

		self.assertTrue(np.allclose(outputs.logits_per_image.numpy()		,	_lowerCAmelCase		,	atol=1e-3							)							)







def       __lowerCAmelCase      (						A    ):
	UpperCAmelCase_       				=			generate_pascal_triangle(A    )
	for row_idx in range(A    ):
		# 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       __lowerCAmelCase      (						A    ):

	if not isinstance(A       ,     A    ):
		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"    )

	UpperCAmelCase_       				=			[]
	for current_row_idx in range(A    ):
		UpperCAmelCase_       				=			populate_current_row(A       ,     A    )
		triangle.append(A    )
	return triangle



def       __lowerCAmelCase      (						A       ,     A    ):
	UpperCAmelCase_       				=			[-1] * (current_row_idx + 1)
	# first and last elements of current row are equal to 1
	UpperCAmelCase_				,   UpperCAmelCase_       				=			1, 1
	for current_col_idx in range(1       ,     A    ):
		calculate_current_element(
		    A       ,     A       ,     A       ,     A    )
	return current_row



def       __lowerCAmelCase      (						A       ,     A       ,     A       ,     A       ,     ):
	UpperCAmelCase_       				=			triangle[current_row_idx - 1][current_col_idx - 1]
	UpperCAmelCase_       				=			triangle[current_row_idx - 1][current_col_idx]
	UpperCAmelCase_       				=			above_to_left_elt + above_to_right_elt



def       __lowerCAmelCase      (						A    ):

	if not isinstance(A       ,     A    ):
		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"    )

	UpperCAmelCase_       				=			[[1]]

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

	return result



def       __lowerCAmelCase      (						):
	from collections.abc import Callable
	from timeit import timeit

	def benchmark_a_function(A       ,     A    ) -> None:
		UpperCAmelCase_       				=			F"{func.__name__}({value})"
		UpperCAmelCase_       				=			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(15    ):  # (1, 7, 14):
		for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
			benchmark_a_function(A       ,     A    )
		print()


if __name__ == "__main__":
				import doctest

				doctest.testmod()
				benchmark()