





from __future__ import annotations





def 		__SCREAMING_SNAKE_CASE						(       UpperCamelCase__				)						->       list[int]:







			'''simple docstring'''

			assert (
			    isinstance(UpperCamelCase__    ,    UpperCamelCase__				) and mask > 0
			), F"""mask needs to be positive integer, your input {mask}"""
			UpperCAmelCase     	=       []
			UpperCAmelCase     	=       mask

			while submask:
						all_submasks.append(UpperCamelCase__				)
						UpperCAmelCase     	=       (submask - 1) & mask

			return all_submasks


if __name__ == "__main__":
				import doctest

				doctest.testmod()










import numpy as np





def 		__SCREAMING_SNAKE_CASE						(       UpperCamelCase__    ,    UpperCamelCase__    ,    UpperCamelCase__				)						->       int:







			'''simple docstring'''

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






def 		__SCREAMING_SNAKE_CASE						(       UpperCamelCase__    ,    UpperCamelCase__    ,    UpperCamelCase__    ,    UpperCamelCase__    ,    UpperCamelCase__=10				)						->       Any:







			'''simple docstring'''

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

						UpperCAmelCase     	=       []
						UpperCAmelCase     	=       []

						for i in range(UpperCamelCase__				):
									UpperCAmelCase     	=       rng.permutation(class_counts[i]				)
									UpperCAmelCase     	=       class_indices[i].take(UpperCamelCase__    ,    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]]				)
						UpperCAmelCase     	=       rng.permutation(UpperCamelCase__				)
						UpperCAmelCase     	=       rng.permutation(UpperCamelCase__				)

						yield train, test



