





def    A__(		__lowerCAmelCase			):
				_snake_case			:      int	    = 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    A__(		__lowerCAmelCase			):

				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'			)

				_snake_case			:      list[list[int]]	    = []
				for current_row_idx in range(_lowerCAmelCase			):
								_snake_case			:      Union[str, Any]	    = populate_current_row(_lowerCAmelCase						,      _lowerCAmelCase			)
								triangle.append(_lowerCAmelCase			)
				return triangle

def    A__(		__lowerCAmelCase						,      __lowerCAmelCase			):
				_snake_case			:      List[str]	    = [-1] * (current_row_idx + 1)
				# first and last elements of current row are equal to 1
				_snake_case			:      Union[str, Any]	    = 1, 1
				for current_col_idx in range(1						,      _lowerCAmelCase			):
								calculate_current_element(
								    _lowerCAmelCase						,      _lowerCAmelCase						,      _lowerCAmelCase						,      _lowerCAmelCase			)
				return current_row

def    A__(		__lowerCAmelCase						,      __lowerCAmelCase						,      __lowerCAmelCase						,      __lowerCAmelCase						,      ):
				_snake_case			:      List[str]	    = triangle[current_row_idx - 1][current_col_idx - 1]
				_snake_case			:      Optional[int]	    = triangle[current_row_idx - 1][current_col_idx]
				_snake_case			:      Optional[Any]	    = above_to_left_elt + above_to_right_elt

def    A__(		__lowerCAmelCase			):

				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'			)

				_snake_case			:      list[list[int]]	    = [[1]]

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

				return result

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

				def benchmark_a_function(__lowerCAmelCase						,      __lowerCAmelCase			) -> None:
								_snake_case			:      Any	    = F'''{func.__name__}({value})'''
								_snake_case			:      Tuple	    = 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(_lowerCAmelCase						,      _lowerCAmelCase			)
								print()


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		benchmark()













import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


_lowerCAmelCase				:   Any						       =						argparse.ArgumentParser('''Stable Diffusion script with intel optimization''', add_help=False)
parser.add_argument('''--dpm''', action='''store_true''', help='''Enable DPMSolver or not''')
parser.add_argument('''--steps''', default=None, type=int, help='''Num inference steps''')
_lowerCAmelCase				:   Tuple						       =						parser.parse_args()


_lowerCAmelCase				:   Any						       =						'''cpu'''
_lowerCAmelCase				:   Dict						       =						'''a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings'''

_lowerCAmelCase				:   Union[str, Any]						       =						'''path-to-your-trained-model'''
_lowerCAmelCase				:   Tuple						       =						StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
 _lowerCAmelCase				:   List[str]						       =						DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
_lowerCAmelCase				:   List[Any]						       =						pipe.to(device)

# to channels last
_lowerCAmelCase				:   Any						       =						pipe.unet.to(memory_format=torch.channels_last)
_lowerCAmelCase				:   int						       =						pipe.vae.to(memory_format=torch.channels_last)
_lowerCAmelCase				:   Optional[Any]						       =						pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
 _lowerCAmelCase				:   Optional[int]						       =						pipe.safety_checker.to(memory_format=torch.channels_last)

# optimize with ipex
_lowerCAmelCase				:   Tuple						       =						torch.randn(2, 4, 64, 64)
_lowerCAmelCase				:   List[str]						       =						torch.rand(1) * 999
_lowerCAmelCase				:   List[Any]						       =						torch.randn(2, 77, 768)
_lowerCAmelCase				:   int						       =						(sample, timestep, encoder_hidden_status)
try:
 _lowerCAmelCase				:   Tuple						       =						ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
 _lowerCAmelCase				:   Optional[Any]						       =						ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
_lowerCAmelCase				:   Dict						       =						ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
_lowerCAmelCase				:   Dict						       =						ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
 _lowerCAmelCase				:   Tuple						       =						ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

# compute
_lowerCAmelCase				:   Dict						       =						666
_lowerCAmelCase				:   Tuple						       =						torch.Generator(device).manual_seed(seed)
_lowerCAmelCase				:   Tuple						       =						{'''generator''': generator}
if args.steps is not None:
 _lowerCAmelCase				:   Tuple						       =						args.steps

with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloataa):
 _lowerCAmelCase				:   int						       =						pipe(prompt, **generate_kwargs).images[0]

# save image
image.save('''generated.png''')
