code: 
  
  import numpy as np
  
  def 			snake_case__    (					SCREAMING_SNAKE_CASE_	:					List[Any]			,  SCREAMING_SNAKE_CASE_	:					Optional[Any]			,  SCREAMING_SNAKE_CASE_	:					Tuple    ):
  
  
  
       '''simple docstring'''
  
  
  
  
  
       lowercase__					:     Any   = n_draws * class_counts / class_counts.sum()
       # floored means we don't overshoot n_samples, but probably undershoot
       lowercase__					:     Tuple   = np.floor(SCREAMING_SNAKE_CASE_    )
       # we add samples according to how much "left over" probability
       # they had, until we arrive at n_samples
       lowercase__					:     str   = int(n_draws - floored.sum()    )
       if need_to_add > 0:
            lowercase__					:     Dict   = continuous - floored
            lowercase__					:     Tuple   = np.sort(np.unique(SCREAMING_SNAKE_CASE_    )    )[::-1]
            # add according to remainder, but break ties
            # randomly to avoid biases
            for value in values:
                 ((lowercase__)   ,				)					:     Tuple   = np.where(remainder == value    )
                 # if we need_to_add less than what's in inds
                 # we draw randomly from them.
                 # if we need to add more, we add them all and
                 # go to the next value
                 lowercase__					:     Union[str, Any]   = min(len(SCREAMING_SNAKE_CASE_    )			,  SCREAMING_SNAKE_CASE_    )
                 lowercase__					:     Union[str, Any]   = rng.choice(SCREAMING_SNAKE_CASE_			,  size=SCREAMING_SNAKE_CASE_			,  replace=SCREAMING_SNAKE_CASE_    )
                 floored[inds] += 1
                 need_to_add -= add_now
                 if need_to_add == 0:
                      break
       return floored.astype(np.intaa    )
  
  def 			snake_case__    (					SCREAMING_SNAKE_CASE_	:					Optional[Any]			,  SCREAMING_SNAKE_CASE_	:					Any			,  SCREAMING_SNAKE_CASE_	:					int			,  SCREAMING_SNAKE_CASE_	:					Optional[int]			,  SCREAMING_SNAKE_CASE_	:					Union[str, Any]=10    ):
  
  
  
       '''simple docstring'''
  
  
  
  
  
       lowercase__   ,				lowercase__					:     List[Any]   = np.unique(SCREAMING_SNAKE_CASE_			,  return_inverse=SCREAMING_SNAKE_CASE_    )
       lowercase__					:     Any   = classes.shape[0]
       lowercase__					:     List[Any]   = np.bincount(SCREAMING_SNAKE_CASE_    )
       if np.min(SCREAMING_SNAKE_CASE_    ) < 2:
            raise ValueError('Minimum class count error'    )
       if n_train < n_classes:
            raise ValueError(
                'The train_size = %d should be greater or ' 'equal to the number of classes = %d' % (n_train, n_classes)    )
       if n_test < n_classes:
            raise ValueError(
                'The test_size = %d should be greater or ' 'equal to the number of classes = %d' % (n_test, n_classes)    )
       lowercase__					:     str   = np.split(np.argsort(SCREAMING_SNAKE_CASE_			,  kind='mergesort'    )			,  np.cumsum(SCREAMING_SNAKE_CASE_    )[:-1]    )
       for _ in range(SCREAMING_SNAKE_CASE_    ):
            lowercase__					:     Optional[int]   = approximate_mode(SCREAMING_SNAKE_CASE_			,  SCREAMING_SNAKE_CASE_			,  SCREAMING_SNAKE_CASE_    )
            lowercase__					:     Tuple   = class_counts - n_i
            lowercase__					:     str   = approximate_mode(SCREAMING_SNAKE_CASE_			,  SCREAMING_SNAKE_CASE_			,  SCREAMING_SNAKE_CASE_    )
  
            lowercase__					:     Dict   = []
            lowercase__					:     Dict   = []
  
            for i in range(SCREAMING_SNAKE_CASE_    ):
                 lowercase__					:     Any   = rng.permutation(class_counts[i]    )
                 lowercase__					:     Any   = class_indices[i].take(SCREAMING_SNAKE_CASE_			,  mode='clip'    )
                 train.extend(perm_indices_class_i[: n_i[i]]    )
                 test.extend(perm_indices_class_i[n_i[i] : n_i[i] + t_i[i]]    )
            lowercase__					:     Dict   = rng.permutation(SCREAMING_SNAKE_CASE_    )
            lowercase__					:     Optional[int]   = rng.permutation(SCREAMING_SNAKE_CASE_    )
  
            yield train, test
  
  
style_context: 
  
  from typing import TYPE_CHECKING
  
  from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available
  
  
  snake_case_    						=				{
      '''configuration_donut_swin''': ['''DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DonutSwinConfig'''],
      '''processing_donut''': ['''DonutProcessor'''],
  }
  
  try:
         if not is_torch_available():
                raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
         pass
  else:
         snake_case_    						=				[
             '''DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST''',
             '''DonutSwinModel''',
             '''DonutSwinPreTrainedModel''',
         ]
  
  try:
         if not is_vision_available():
                raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
         pass
  else:
         snake_case_    						=				['''DonutFeatureExtractor''']
         snake_case_    						=				['''DonutImageProcessor''']
  
  
  if TYPE_CHECKING:
         from .configuration_donut_swin import DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP, DonutSwinConfig
         from .processing_donut import DonutProcessor
  
         try:
                if not is_torch_available():
                       raise OptionalDependencyNotAvailable()
         except OptionalDependencyNotAvailable:
                pass
         else:
                from .modeling_donut_swin import (
                    DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
                    DonutSwinModel,
                    DonutSwinPreTrainedModel,
                )
  
         try:
                if not is_vision_available():
                       raise OptionalDependencyNotAvailable()
         except OptionalDependencyNotAvailable:
                pass
         else:
                from .feature_extraction_donut import DonutFeatureExtractor
                from .image_processing_donut import DonutImageProcessor
  
  else:
         import sys
  
         snake_case_    						=				_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
  
  