





import timeit

import numpy as np

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





def __UpperCAmelCase       (		__A			)						->					int:



       '''simple docstring'''





       def wrapper(*__A ,						**__A			):
              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 __UpperCAmelCase       (		__A ,						__A=1_0_0 ,						__A=None			)						->					int:



       '''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(1_0 ,						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 __UpperCAmelCase       (		__A ,						__A ,						__A=1_0_0 ,						__A=None			)						->					List[Any]:



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









class     lowercase__  :






  def __init__(					self      :					List[str]		,						_lowercase      :					list ):




         """simple docstring"""







         UpperCAmelCase__										=     set_counts
         UpperCAmelCase__										=     max(_lowercase )
         UpperCAmelCase__										=     len(_lowercase )
         UpperCAmelCase__										=     [1] * num_sets
         UpperCAmelCase__										=     list(range(_lowercase ) )






  def 			_UpperCAmelCase  (					self      :					Dict		,						_lowercase      :					int		,						_lowercase      :					int ):




         """simple docstring"""







         UpperCAmelCase__										=     self.get_parent(_lowercase )
         UpperCAmelCase__										=     self.get_parent(_lowercase )

         if src_parent == dst_parent:
                return False

         if self.ranks[dst_parent] >= self.ranks[src_parent]:
                self.set_counts[dst_parent] += self.set_counts[src_parent]
                UpperCAmelCase__										=     0
                UpperCAmelCase__										=     dst_parent
                if self.ranks[dst_parent] == self.ranks[src_parent]:
                       self.ranks[dst_parent] += 1
                UpperCAmelCase__										=     self.set_counts[dst_parent]
         else:
                self.set_counts[src_parent] += self.set_counts[dst_parent]
                UpperCAmelCase__										=     0
                UpperCAmelCase__										=     src_parent
                UpperCAmelCase__										=     self.set_counts[src_parent]

         UpperCAmelCase__										=     max(self.max_set		,						_lowercase )
         return True






  def 			_UpperCAmelCase  (					self      :					Optional[Any]		,						_lowercase      :					int ):




         """simple docstring"""







         if self.parents[disj_set] == disj_set:
                return disj_set
         UpperCAmelCase__										=     self.get_parent(self.parents[disj_set] )
         return self.parents[disj_set]





