import timeit

import numpy as np

import datasets
from datasets.arrow_writer import ArrowWriter
from datasets.features.features import _ArrayXD





def 	__lowerCamelCase							(UpperCAmelCase__     :							int  ):
					def wrapper(*UpperCAmelCase__     :							int      , **UpperCAmelCase__     :							Optional[int]  ):
										SCREAMING_SNAKE_CASE    			=       timeit.default_timer()
										SCREAMING_SNAKE_CASE    			=       func(*UpperCAmelCase__      , **UpperCAmelCase__  )
										SCREAMING_SNAKE_CASE    			=       timeit.default_timer() - starttime
										return delta

					SCREAMING_SNAKE_CASE    			=       func.__name__

					return wrapper





def 	__lowerCamelCase							(UpperCAmelCase__     :							dict      , UpperCAmelCase__     :							List[Any]=1_0_0      , UpperCAmelCase__     :							Optional[Any]=None  ):
					SCREAMING_SNAKE_CASE    			=       []
					SCREAMING_SNAKE_CASE    			=       seq_shapes or {}
					for i in range(UpperCAmelCase__  ):
										SCREAMING_SNAKE_CASE    			=       {}
										for col_id, (k, v) in enumerate(features.items()  ):
															if isinstance(UpperCAmelCase__      , _ArrayXD  ):
																				SCREAMING_SNAKE_CASE    			=       np.random.rand(*v.shape  ).astype(v.dtype  )
															elif isinstance(UpperCAmelCase__      , datasets.Value  ):
																				if v.dtype == "string":
																									SCREAMING_SNAKE_CASE    			=       "The small grey turtle was surprisingly fast when challenged."
																				else:
																									SCREAMING_SNAKE_CASE    			=       np.random.randint(1_0      , size=1  ).astype(v.dtype  ).item()
															elif isinstance(UpperCAmelCase__      , datasets.Sequence  ):
																				while isinstance(UpperCAmelCase__      , datasets.Sequence  ):
																									SCREAMING_SNAKE_CASE    			=       v.feature
																				SCREAMING_SNAKE_CASE    			=       seq_shapes[k]
																				SCREAMING_SNAKE_CASE    			=       np.random.rand(*UpperCAmelCase__  ).astype(v.dtype  )
															SCREAMING_SNAKE_CASE    			=       data

										dummy_data.append((i, example)  )

					return dummy_data





def 	__lowerCamelCase							(UpperCAmelCase__     :							str      , UpperCAmelCase__     :							Any      , UpperCAmelCase__     :							Optional[Any]=1_0_0      , UpperCAmelCase__     :							str=None  ):
					SCREAMING_SNAKE_CASE    			=       generate_examples(UpperCAmelCase__      , num_examples=UpperCAmelCase__      , seq_shapes=UpperCAmelCase__  )

					with ArrowWriter(features=UpperCAmelCase__      , path=UpperCAmelCase__  ) as writer:
										for key, record in dummy_data:
															SCREAMING_SNAKE_CASE    			=       features.encode_example(UpperCAmelCase__  )
															writer.write(UpperCAmelCase__  )

										SCREAMING_SNAKE_CASE			,   SCREAMING_SNAKE_CASE    			=       writer.finalize()

					if not num_final_examples == num_examples:
										raise ValueError(
										    F"Error writing the dataset, wrote {num_final_examples} examples but should have written {num_examples}."  )

					SCREAMING_SNAKE_CASE    			=       datasets.Dataset.from_file(filename=UpperCAmelCase__      , info=datasets.DatasetInfo(features=UpperCAmelCase__  )  )

					return dataset





def 	__lowerCamelCase							(UpperCAmelCase__     :							list[int]  ):
					if not numbers:
										return 0

					if not isinstance(UpperCAmelCase__      , (list, tuple)  ) or not all(
					    isinstance(UpperCAmelCase__      , UpperCAmelCase__  ) for number in numbers  ):
										raise ValueError("numbers must be an iterable of integers"  )

					SCREAMING_SNAKE_CASE    			=       SCREAMING_SNAKE_CASE    			=       SCREAMING_SNAKE_CASE    			=       numbers[0]

					for i in range(1      , len(UpperCAmelCase__  )  ):
										# update the maximum and minimum subarray products
										SCREAMING_SNAKE_CASE    			=       numbers[i]
										if number < 0:
															SCREAMING_SNAKE_CASE			,   SCREAMING_SNAKE_CASE    			=       min_till_now, max_till_now
										SCREAMING_SNAKE_CASE    			=       max(UpperCAmelCase__      , max_till_now * number  )
										SCREAMING_SNAKE_CASE    			=       min(UpperCAmelCase__      , min_till_now * number  )

										# update the maximum product found till now
										SCREAMING_SNAKE_CASE    			=       max(UpperCAmelCase__      , UpperCAmelCase__  )

					return max_prod




