





import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image

		from transformers import EfficientNetImageProcessor






class 	UpperCamelCase_     (     unittest.TestCase       ):



					def __init__(		self    :    Tuple					,			lowerCamelCase    :    Dict					,			lowerCamelCase    :    Optional[int]=13					,			lowerCamelCase    :    int=3					,			lowerCamelCase    :    str=18					,			lowerCamelCase    :    Optional[int]=30					,			lowerCamelCase    :    Optional[int]=4_00					,			lowerCamelCase    :    Optional[Any]=True					,			lowerCamelCase    :    Tuple=None					,			lowerCamelCase    :    Dict=True					,			lowerCamelCase    :    List[Any]=[0.5, 0.5, 0.5]					,			lowerCamelCase    :    Tuple=[0.5, 0.5, 0.5]					,			):
							lowerCamelCase_  :    Dict   	=			size if size is not None else {'height': 18, 'width': 18}
							lowerCamelCase_  :    Any   	=			parent
							lowerCamelCase_  :    int   	=			batch_size
							lowerCamelCase_  :    List[str]   	=			num_channels
							lowerCamelCase_  :    Dict   	=			image_size
							lowerCamelCase_  :    Dict   	=			min_resolution
							lowerCamelCase_  :    List[Any]   	=			max_resolution
							lowerCamelCase_  :    str   	=			do_resize
							lowerCamelCase_  :    int   	=			size
							lowerCamelCase_  :    Optional[Any]   	=			do_normalize
							lowerCamelCase_  :    Tuple   	=			image_mean
							lowerCamelCase_  :    Optional[int]   	=			image_std





					def      __a    (		self    :    str	):
							return {
							    "image_mean": self.image_mean,
							    "image_std": self.image_std,
							    "do_normalize": self.do_normalize,
							    "do_resize": self.do_resize,
							    "size": self.size,
							}






@require_torch
@require_vision
class 	UpperCamelCase_     (     snake_case__     ,    unittest.TestCase       ):
					_a			:	List[str]							=				EfficientNetImageProcessor if is_vision_available() else None



					def      __a    (		self    :    Optional[int]	):
							lowerCamelCase_  :    Dict   	=			EfficientNetImageProcessorTester(self	)



					@property
					def      __a    (		self    :    Tuple	):
							return self.image_processor_tester.prepare_image_processor_dict()



					def      __a    (		self    :    str	):
							lowerCamelCase_  :    List[Any]   	=			self.image_processing_class(**self.image_processor_dict	)
							self.assertTrue(hasattr(lowerCamelCase					,			'image_mean'	)	)
							self.assertTrue(hasattr(lowerCamelCase					,			'image_std'	)	)
							self.assertTrue(hasattr(lowerCamelCase					,			'do_normalize'	)	)
							self.assertTrue(hasattr(lowerCamelCase					,			'do_resize'	)	)
							self.assertTrue(hasattr(lowerCamelCase					,			'size'	)	)



					def      __a    (		self    :    Union[str, Any]	):
							lowerCamelCase_  :    Optional[int]   	=			self.image_processing_class.from_dict(self.image_processor_dict	)
							self.assertEqual(image_processor.size					,			{'height': 18, 'width': 18}	)

							lowerCamelCase_  :    Dict   	=			self.image_processing_class.from_dict(self.image_processor_dict					,			size=42	)
							self.assertEqual(image_processor.size					,			{'height': 42, 'width': 42}	)



					def      __a    (		self    :    List[Any]	):
							# Initialize image_processing
							lowerCamelCase_  :    Union[str, Any]   	=			self.image_processing_class(**self.image_processor_dict	)
							# create random PIL images
							lowerCamelCase_  :    List[Any]   	=			prepare_image_inputs(self.image_processor_tester					,			equal_resolution=lowerCamelCase	)
							for image in image_inputs:
									self.assertIsInstance(lowerCamelCase					,			Image.Image	)

							# Test not batched input
							lowerCamelCase_  :    Any   	=			image_processing(image_inputs[0]					,			return_tensors='pt'	).pixel_values
							self.assertEqual(
							    encoded_images.shape					,			(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.size['height'],
							        self.image_processor_tester.size['width'],
							    )					,			)

							# Test batched
							lowerCamelCase_  :    List[str]   	=			image_processing(lowerCamelCase					,			return_tensors='pt'	).pixel_values
							self.assertEqual(
							    encoded_images.shape					,			(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.size['height'],
							        self.image_processor_tester.size['width'],
							    )					,			)



					def      __a    (		self    :    List[str]	):
							# Initialize image_processing
							lowerCamelCase_  :    Any   	=			self.image_processing_class(**self.image_processor_dict	)
							# create random numpy tensors
							lowerCamelCase_  :    int   	=			prepare_image_inputs(self.image_processor_tester					,			equal_resolution=lowerCamelCase					,			numpify=lowerCamelCase	)
							for image in image_inputs:
									self.assertIsInstance(lowerCamelCase					,			np.ndarray	)

							# Test not batched input
							lowerCamelCase_  :    Optional[Any]   	=			image_processing(image_inputs[0]					,			return_tensors='pt'	).pixel_values
							self.assertEqual(
							    encoded_images.shape					,			(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.size['height'],
							        self.image_processor_tester.size['width'],
							    )					,			)

							# Test batched
							lowerCamelCase_  :    Optional[int]   	=			image_processing(lowerCamelCase					,			return_tensors='pt'	).pixel_values
							self.assertEqual(
							    encoded_images.shape					,			(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.size['height'],
							        self.image_processor_tester.size['width'],
							    )					,			)





					def      __a    (		self    :    List[Any]	):
							# Initialize image_processing
							lowerCamelCase_  :    Union[str, Any]   	=			self.image_processing_class(**self.image_processor_dict	)
							# create random PyTorch tensors
							lowerCamelCase_  :    Union[str, Any]   	=			prepare_image_inputs(self.image_processor_tester					,			equal_resolution=lowerCamelCase					,			torchify=lowerCamelCase	)
							for image in image_inputs:
									self.assertIsInstance(lowerCamelCase					,			torch.Tensor	)

							# Test not batched input
							lowerCamelCase_  :    Union[str, Any]   	=			image_processing(image_inputs[0]					,			return_tensors='pt'	).pixel_values
							self.assertEqual(
							    encoded_images.shape					,			(
							        1,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.size['height'],
							        self.image_processor_tester.size['width'],
							    )					,			)

							# Test batched
							lowerCamelCase_  :    Union[str, Any]   	=			image_processing(lowerCamelCase					,			return_tensors='pt'	).pixel_values
							self.assertEqual(
							    encoded_images.shape					,			(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.size['height'],
							        self.image_processor_tester.size['width'],
							    )					,			)







from __future__ import annotations


def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__	):
		lowerCamelCase_  :    int
		lowerCamelCase_  :    list[str]   	=			list(lowerCAmelCase__	)
		lowerCamelCase_	,			lowerCamelCase_  :    List[str]   	=			_vector[:-1], int(_vector[-1]	)
		lowerCamelCase_  :    list[int]   	=			[int(lowerCAmelCase__	) for digit in __vector]

		vector.reverse()
		for i, digit in enumerate(lowerCAmelCase__	):
				if i & 1 == 0:
						lowerCamelCase_  :    int   	=			digit * 2
						if doubled > 9:
								doubled -= 9
						check_digit += doubled
				else:
						check_digit += digit

		return check_digit % 10 == 0


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		assert is_luhn("""79927398713""")
		assert not is_luhn("""79927398714""")
