


import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


UpperCAmelCase_      : Tuple  					=       5_0000
UpperCAmelCase_      : str  					=       5000

UpperCAmelCase_					,   UpperCAmelCase_      : List[Any]  					=       os.path.split(__file__)
UpperCAmelCase_      : Any  					=       os.path.join(RESULTS_BASEPATH, 'results', RESULTS_FILENAME.replace('.py', '.json'))







@get_duration
def        SCREAMING_SNAKE_CASE_						(			__A :			datasets.Dataset  ,    __A :			Any				)	->		Optional[Any]:

       """simple docstring"""

       for i in range(__A				):
              a_					:		List[Any]							=  dataset[i]







@get_duration
def        SCREAMING_SNAKE_CASE_						(			__A :			datasets.Dataset  ,    __A :			Tuple  ,    __A :			List[Any]				)	->		str:

       """simple docstring"""

       for i in range(0  ,    len(__A				)  ,    __A				):
              a_					:		Tuple							=  dataset[i : i + batch_size]







@get_duration
def        SCREAMING_SNAKE_CASE_						(			__A :			datasets.Dataset  ,    __A :			int  ,    __A :			Optional[Any]				)	->		Optional[int]:

       """simple docstring"""

       with dataset.formatted_as(type=__A				):
              for i in range(__A				):
                     a_					:		int							=  dataset[i]







@get_duration
def        SCREAMING_SNAKE_CASE_						(			__A :			datasets.Dataset  ,    __A :			Tuple  ,    __A :			Any  ,    __A :			Optional[Any]				)	->		int:

       """simple docstring"""

       with dataset.formatted_as(type=__A				):
              for i in range(0  ,    __A  ,    __A				):
                     a_					:		str							=  dataset[i : i + batch_size]







def        SCREAMING_SNAKE_CASE_						(			)	->		List[str]:

       """simple docstring"""

       a_					:		Any							=  {'num examples': SPEED_TEST_N_EXAMPLES}
       a_					:		Optional[int]							=  [
           (read, {'length': SMALL_TEST}),
           (read, {'length': SPEED_TEST_N_EXAMPLES}),
           (read_batch, {'length': SPEED_TEST_N_EXAMPLES, 'batch_size': 10}),
           (read_batch, {'length': SPEED_TEST_N_EXAMPLES, 'batch_size': 1_00}),
           (read_batch, {'length': SPEED_TEST_N_EXAMPLES, 'batch_size': 10_00}),
           (read_formatted, {'type': 'numpy', 'length': SMALL_TEST}),
           (read_formatted, {'type': 'pandas', 'length': SMALL_TEST}),
           (read_formatted, {'type': 'torch', 'length': SMALL_TEST}),
           (read_formatted, {'type': 'tensorflow', 'length': SMALL_TEST}),
           (read_formatted_batch, {'type': 'numpy', 'length': SMALL_TEST, 'batch_size': 10}),
           (read_formatted_batch, {'type': 'numpy', 'length': SMALL_TEST, 'batch_size': 10_00}),
       ]

       a_					:		Dict							=  [
           (read, {'length': SMALL_TEST}),
           (read, {'length': SPEED_TEST_N_EXAMPLES}),
           (read_batch, {'length': SPEED_TEST_N_EXAMPLES, 'batch_size': 10}),
           (read_batch, {'length': SPEED_TEST_N_EXAMPLES, 'batch_size': 1_00}),
           (read_batch, {'length': SPEED_TEST_N_EXAMPLES, 'batch_size': 10_00}),
           (read_formatted, {'type': 'numpy', 'length': SMALL_TEST}),
           (read_formatted_batch, {'type': 'numpy', 'length': SMALL_TEST, 'batch_size': 10}),
           (read_formatted_batch, {'type': 'numpy', 'length': SMALL_TEST, 'batch_size': 10_00}),
       ]
       with tempfile.TemporaryDirectory() as tmp_dir:
              print('generating dataset'				)
              a_					:		Optional[int]							=  datasets.Features(
                  {'list': datasets.Sequence(datasets.Value('float32'				)				), 'numbers': datasets.Value('float32'				)}				)
              a_					:		str							=  generate_example_dataset(
                  os.path.join(__A  ,    'dataset.arrow'				)  ,    __A  ,    num_examples=__A  ,    seq_shapes={'list': (1_00,)}  ,    )
              print('first set of iterations'				)
              for func, kwargs in functions:
                     print(func.__name__  ,    str(__A				)				)
                     a_					:		Any							=  func(__A  ,    **__A				)

              print('shuffling dataset'				)
              a_					:		int							=  dataset.shuffle()
              print('Second set of iterations (after shuffling'				)
              for func, kwargs in functions_shuffled:
                     print('shuffled '  ,    func.__name__  ,    str(__A				)				)
                     a_					:		Any							=  func(
                         __A  ,    **__A				)

       with open(__A  ,    'wb'				) as f:
              f.write(json.dumps(__A				).encode('utf-8'				)				)


if __name__ == "__main__":  # useful to run the profiler
   benchmark_iterating()






def 			_a (      SCREAMING_SNAKE_CASE     ):


		"""simple docstring"""




		return credit_card_number.startswith(('''34''', '''35''', '''37''', '''4''', '''5''', '''6''')     )
def 			_a (      SCREAMING_SNAKE_CASE     ):


		"""simple docstring"""




		lowercase__            =      credit_card_number
		lowercase__            =      0
		lowercase__            =      len(SCREAMING_SNAKE_CASE     ) - 2
		for i in range(SCREAMING_SNAKE_CASE						,				-1						,				-2     ):
				#  double the value of every second digit
				lowercase__            =      int(cc_number[i]     )
				digit *= 2
				# If doubling of a number results in a two digit number
				# i.e greater than 9(e.g., 6 × 2 = 12),
				# then add the digits of the product (e.g., 12: 1 + 2 = 3, 15: 1 + 5 = 6),
				# to get a single digit number.
				if digit > 9:
						digit %= 10
						digit += 1
				lowercase__            =      cc_number[:i] + str(SCREAMING_SNAKE_CASE     ) + cc_number[i + 1 :]
				total += digit

		# Sum up the remaining digits
		for i in range(len(SCREAMING_SNAKE_CASE     ) - 1						,				-1						,				-2     ):
				total += int(cc_number[i]     )

		return total % 10 == 0
def 			_a (      SCREAMING_SNAKE_CASE     ):


		"""simple docstring"""




		lowercase__            =      f'{credit_card_number} is an invalid credit card number because'
		if not credit_card_number.isdigit():
				print(f'{error_message} it has nonnumerical characters.'     )
				return False

		if not 13 <= len(SCREAMING_SNAKE_CASE     ) <= 16:
				print(f'{error_message} of its length.'     )
				return False

		if not validate_initial_digits(SCREAMING_SNAKE_CASE     ):
				print(f'{error_message} of its first two digits.'     )
				return False

		if not luhn_validation(SCREAMING_SNAKE_CASE     ):
				print(f'{error_message} it fails the Luhn check.'     )
				return False

		print(f'{credit_card_number} is a valid credit card number.'     )
		return True


if __name__ == "__main__":
			import doctest

			doctest.testmod()
			validate_credit_card_number('4111111111111111')
			validate_credit_card_number('32323')


