



"""simple docstring"""


import timeit

import numpy as np

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







def  lowercase	(      _SCREAMING_SNAKE_CASE   :						Dict				):






				'''simple docstring'''



				def wrapper(*_SCREAMING_SNAKE_CASE   :						Union[str, Any]					,     **_SCREAMING_SNAKE_CASE   :						Any				):
								_UpperCAmelCase					=    timeit.default_timer()
								_UpperCAmelCase					=    func(*_SCREAMING_SNAKE_CASE					,     **_SCREAMING_SNAKE_CASE				)
								_UpperCAmelCase					=    timeit.default_timer() - starttime
								return delta

				_UpperCAmelCase					=    func.__name__

				return wrapper







def  lowercase	(      _SCREAMING_SNAKE_CASE   :						dict					,     _SCREAMING_SNAKE_CASE   :						Optional[int]=100					,     _SCREAMING_SNAKE_CASE   :						Optional[Any]=None				):






				'''simple docstring'''



				_UpperCAmelCase					=    []
				_UpperCAmelCase					=    seq_shapes or {}
				for i in range(_SCREAMING_SNAKE_CASE				):
								_UpperCAmelCase					=    {}
								for col_id, (k, v) in enumerate(features.items()				):
												if isinstance(_SCREAMING_SNAKE_CASE					,     _ArrayXD				):
																_UpperCAmelCase					=    np.random.rand(*v.shape				).astype(v.dtype				)
												elif isinstance(_SCREAMING_SNAKE_CASE					,     datasets.Value				):
																if v.dtype == "string":
																				_UpperCAmelCase					=    '''The small grey turtle was surprisingly fast when challenged.'''
																else:
																				_UpperCAmelCase					=    np.random.randint(10					,     size=1				).astype(v.dtype				).item()
												elif isinstance(_SCREAMING_SNAKE_CASE					,     datasets.Sequence				):
																while isinstance(_SCREAMING_SNAKE_CASE					,     datasets.Sequence				):
																				_UpperCAmelCase					=    v.feature
																_UpperCAmelCase					=    seq_shapes[k]
																_UpperCAmelCase					=    np.random.rand(*_SCREAMING_SNAKE_CASE				).astype(v.dtype				)
												_UpperCAmelCase					=    data

								dummy_data.append((i, example)				)

				return dummy_data







def  lowercase	(      _SCREAMING_SNAKE_CASE   :						List[Any]					,     _SCREAMING_SNAKE_CASE   :						Optional[Any]					,     _SCREAMING_SNAKE_CASE   :						Union[str, Any]=100					,     _SCREAMING_SNAKE_CASE   :						Optional[Any]=None				):






				'''simple docstring'''



				_UpperCAmelCase					=    generate_examples(_SCREAMING_SNAKE_CASE					,     num_examples=_SCREAMING_SNAKE_CASE					,     seq_shapes=_SCREAMING_SNAKE_CASE				)

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

								_UpperCAmelCase		,						_UpperCAmelCase					=    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}.'				)

				_UpperCAmelCase					=    datasets.Dataset.from_file(filename=_SCREAMING_SNAKE_CASE					,     info=datasets.DatasetInfo(features=_SCREAMING_SNAKE_CASE				)				)

				return dataset








"""simple docstring"""


import operator







def  lowercase	(      _SCREAMING_SNAKE_CASE   :						list					,     _SCREAMING_SNAKE_CASE   :						bool = False					,     _SCREAMING_SNAKE_CASE   :						list | None = None				):






				'''simple docstring'''



				_UpperCAmelCase					=    operator.lt if reverse else operator.gt
				_UpperCAmelCase					=    solution or []

				if not arr:
								return solution

				_UpperCAmelCase					=    [arr.pop(0				)]
				for i, item in enumerate(_SCREAMING_SNAKE_CASE				):
								if _operator(_SCREAMING_SNAKE_CASE					,     sublist[-1]				):
												sublist.append(_SCREAMING_SNAKE_CASE				)
												arr.pop(_SCREAMING_SNAKE_CASE				)

    #  merging sublist into solution list
				if not solution:
								solution.extend(_SCREAMING_SNAKE_CASE				)
				else:
								while sublist:
												_UpperCAmelCase					=    sublist.pop(0				)
												for i, xx in enumerate(_SCREAMING_SNAKE_CASE				):
																if not _operator(_SCREAMING_SNAKE_CASE					,     _SCREAMING_SNAKE_CASE				):
																				solution.insert(_SCREAMING_SNAKE_CASE					,     _SCREAMING_SNAKE_CASE				)
																				break
												else:
																solution.append(_SCREAMING_SNAKE_CASE				)

				strand_sort(_SCREAMING_SNAKE_CASE					,     _SCREAMING_SNAKE_CASE					,     _SCREAMING_SNAKE_CASE				)
				return solution


if __name__ == "__main__":
					assert strand_sort([4, 3, 5, 1, 2]) == [1, 2, 3, 4, 5]
					assert strand_sort([4, 3, 5, 1, 2], reverse=True) == [5, 4, 3, 2, 1]



