




'''simple docstring'''





from typing import Optional

import pyspark

from .. import Features, NamedSplit
from ..download import DownloadMode
from ..packaged_modules.spark.spark import Spark
from .abc import AbstractDatasetReader

class        _a    (						__snake_case							):






     def __init__(			self ,_SCREAMING_SNAKE_CASE ,_SCREAMING_SNAKE_CASE = None ,_SCREAMING_SNAKE_CASE = None ,_SCREAMING_SNAKE_CASE = True ,_SCREAMING_SNAKE_CASE = None ,_SCREAMING_SNAKE_CASE = False ,_SCREAMING_SNAKE_CASE = None ,_SCREAMING_SNAKE_CASE = True ,_SCREAMING_SNAKE_CASE = "arrow" ,**_SCREAMING_SNAKE_CASE ,)							->      Dict:
          super().__init__(
              split=_SCREAMING_SNAKE_CASE ,features=_SCREAMING_SNAKE_CASE ,cache_dir=_SCREAMING_SNAKE_CASE ,keep_in_memory=_SCREAMING_SNAKE_CASE ,streaming=_SCREAMING_SNAKE_CASE ,**_SCREAMING_SNAKE_CASE ,)
          _snake_case							=				load_from_cache_file
          _snake_case							=				file_format
          _snake_case							=				Spark(
              df=_SCREAMING_SNAKE_CASE ,features=_SCREAMING_SNAKE_CASE ,cache_dir=_SCREAMING_SNAKE_CASE ,working_dir=_SCREAMING_SNAKE_CASE ,**_SCREAMING_SNAKE_CASE ,)






     def     _lowercase     (			self   )							->      List[Any]:
          if self.streaming:
               return self.builder.as_streaming_dataset(split=self.split   )
          _snake_case							=				None if self._load_from_cache_file else DownloadMode.FORCE_REDOWNLOAD
          self.builder.download_and_prepare(
              download_mode=_SCREAMING_SNAKE_CASE ,file_format=self._file_format ,)
          return self.builder.as_dataset(split=self.split   )








'''simple docstring'''





def      __a     (       _UpperCamelCase:   int   )						->			None:

     """simple docstring"""




     _snake_case							=				generate_pascal_triangle(_UpperCamelCase   )
     for row_idx in range(_UpperCamelCase   ):
          # 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     (       _UpperCamelCase:   int   )						->			list[list[int]]:

     """simple docstring"""




     if not isinstance(_UpperCamelCase ,						_UpperCamelCase   ):
          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							=				[]
     for current_row_idx in range(_UpperCamelCase   ):
          _snake_case							=				populate_current_row(_UpperCamelCase ,						_UpperCamelCase   )
          triangle.append(_UpperCamelCase   )
     return triangle





def      __a     (       _UpperCamelCase:   list[list[int]] ,						_UpperCamelCase:   int   )						->			list[int]:

     """simple docstring"""




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





def      __a     (       _UpperCamelCase:   list[list[int]] ,						_UpperCamelCase:   list[int] ,						_UpperCamelCase:   int ,						_UpperCamelCase:   int ,						)						->			None:

     """simple docstring"""




     _snake_case							=				triangle[current_row_idx - 1][current_col_idx - 1]
     _snake_case							=				triangle[current_row_idx - 1][current_col_idx]
     _snake_case							=				above_to_left_elt + above_to_right_elt





def      __a     (       _UpperCamelCase:   int   )						->			list[list[int]]:

     """simple docstring"""




     if not isinstance(_UpperCamelCase ,						_UpperCamelCase   ):
          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							=				[[1]]

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

     return result





def      __a     (       )						->			None:

     """simple docstring"""




     from collections.abc import Callable
     from timeit import timeit

     def benchmark_a_function(_UpperCamelCase:   Callable ,						_UpperCamelCase:   int   ) -> None:
          _snake_case							=				F"""{func.__name__}({value})"""
          _snake_case							=				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(_UpperCamelCase ,						_UpperCamelCase   )
          print()


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   benchmark()


