



"""simple docstring"""







import numpy as np

def 							UpperCamelCase_       (       lowerCAmelCase__ :							Union[str, Any]       ,  lowerCAmelCase__ :							Optional[int]       ,  lowerCAmelCase__ :							Optional[Any]		)		->  Optional[int]:

  """simple docstring"""




  lowerCAmelCase_  :							Union[str, Any]								=					n_draws * class_counts / class_counts.sum()
  # floored means we don't overshoot n_samples, but probably undershoot
  lowerCAmelCase_  :							Optional[int]								=					np.floor(lowerCAmelCase__		)
  # we add samples according to how much "left over" probability
  # they had, until we arrive at n_samples
  lowerCAmelCase_  :							List[Any]								=					int(n_draws - floored.sum()		)
  if need_to_add > 0:
    lowerCAmelCase_  :							int								=					continuous - floored
    lowerCAmelCase_  :							Optional[Any]								=					np.sort(np.unique(lowerCAmelCase__		)		)[::-1]
    # add according to remainder, but break ties
    # randomly to avoid biases
    for value in values:
      ((lowerCAmelCase_)		,)  :							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
      lowerCAmelCase_  :							str								=					min(len(lowerCAmelCase__		)       ,  lowerCAmelCase__		)
      lowerCAmelCase_  :							Optional[Any]								=					rng.choice(lowerCAmelCase__       ,  size=lowerCAmelCase__       ,  replace=lowerCAmelCase__		)
      floored[inds] += 1
      need_to_add -= add_now
      if need_to_add == 0:
        break
  return floored.astype(np.intaa		)

def 							UpperCamelCase_       (       lowerCAmelCase__ :							int       ,  lowerCAmelCase__ :							Tuple       ,  lowerCAmelCase__ :							List[Any]       ,  lowerCAmelCase__ :							int       ,  lowerCAmelCase__ :							Union[str, Any]=10		)		->  List[Any]:

  """simple docstring"""




  lowerCAmelCase_		,lowerCAmelCase_  :							Any								=					np.unique(lowerCAmelCase__       ,  return_inverse=lowerCAmelCase__		)
  lowerCAmelCase_  :							List[Any]								=					classes.shape[0]
  lowerCAmelCase_  :							str								=					np.bincount(lowerCAmelCase__		)
  if np.min(lowerCAmelCase__		) < 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)		)
  lowerCAmelCase_  :							Any								=					np.split(np.argsort(lowerCAmelCase__       ,  kind='mergesort'		)       ,  np.cumsum(lowerCAmelCase__		)[:-1]		)
  for _ in range(lowerCAmelCase__		):
    lowerCAmelCase_  :							Any								=					approximate_mode(lowerCAmelCase__       ,  lowerCAmelCase__       ,  lowerCAmelCase__		)
    lowerCAmelCase_  :							List[str]								=					class_counts - n_i
    lowerCAmelCase_  :							Tuple								=					approximate_mode(lowerCAmelCase__       ,  lowerCAmelCase__       ,  lowerCAmelCase__		)

    lowerCAmelCase_  :							Any								=					[]
    lowerCAmelCase_  :							Any								=					[]

    for i in range(lowerCAmelCase__		):
      lowerCAmelCase_  :							List[str]								=					rng.permutation(class_counts[i]		)
      lowerCAmelCase_  :							List[str]								=					class_indices[i].take(lowerCAmelCase__       ,  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]]		)
    lowerCAmelCase_  :							List[str]								=					rng.permutation(lowerCAmelCase__		)
    lowerCAmelCase_  :							Optional[Any]								=					rng.permutation(lowerCAmelCase__		)

    yield train, test










"""simple docstring"""







import unittest
from timeit import timeit

def 							UpperCamelCase_       (       lowerCAmelCase__ :							int       ,  lowerCAmelCase__ :							int		)		->  int:

  """simple docstring"""




  lowerCAmelCase_  :							Any								=					first_num if first_num >= second_num else second_num
  lowerCAmelCase_  :							Union[str, Any]								=					max_num
  while (common_mult % first_num > 0) or (common_mult % second_num > 0):
    common_mult += max_num
  return common_mult

def 							UpperCamelCase_       (       lowerCAmelCase__ :							int       ,  lowerCAmelCase__ :							int		)		->  int:

  """simple docstring"""




  return b if a == 0 else greatest_common_divisor(b % a       ,  lowerCAmelCase__		)

def 							UpperCamelCase_       (       lowerCAmelCase__ :							int       ,  lowerCAmelCase__ :							int		)		->  int:

  """simple docstring"""




  return first_num // greatest_common_divisor(lowerCAmelCase__       ,  lowerCAmelCase__		) * second_num

def 							UpperCamelCase_       (       )		->  Dict:

  """simple docstring"""




  lowerCAmelCase_  :							str								=					(
      'from __main__ import least_common_multiple_slow, least_common_multiple_fast'
  )
  print(
      'least_common_multiple_slow():'       ,  timeit('least_common_multiple_slow(1000, 999)'       ,  setup=lowerCAmelCase__		)       ,  )
  print(
      'least_common_multiple_fast():'       ,  timeit('least_common_multiple_fast(1000, 999)'       ,  setup=lowerCAmelCase__		)       ,  )







class  UpperCamelCase__  (      unittest.TestCase    ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE    							=	(
          (10, 20),
          (13, 15),
          (4, 31),
          (10, 42),
          (43, 34),
          (5, 12),
          (12, 25),
          (10, 25),
          (6, 9),
      )
      _SCREAMING_SNAKE_CASE    							=	(20, 195, 124, 210, 1462, 60, 300, 50, 18)



      def 	SCREAMING_SNAKE_CASE__					( self							: List[str]			):
        for i, (first_num, second_num) in enumerate(self.test_inputs			):
          lowerCAmelCase_  :							Union[str, Any]								=					least_common_multiple_slow(SCREAMING_SNAKE_CASE_       ,     SCREAMING_SNAKE_CASE_			)
          lowerCAmelCase_  :							Any								=					least_common_multiple_fast(SCREAMING_SNAKE_CASE_       ,     SCREAMING_SNAKE_CASE_			)
          with self.subTest(i=SCREAMING_SNAKE_CASE_			):
            self.assertEqual(SCREAMING_SNAKE_CASE_       ,     self.expected_results[i]			)
            self.assertEqual(SCREAMING_SNAKE_CASE_       ,     self.expected_results[i]			)


if __name__ == "__main__":
     benchmark()
     unittest.main()





