





import shutil
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import (
    is_pt_tf_cross_test,
    require_tf,
    require_torch,
    require_torchvision,
    require_vision,
)
from transformers.utils import is_tf_available, is_torch_available, is_vision_available


if is_vision_available():
		from PIL import Image

		from transformers import AutoProcessor, SamImageProcessor, SamProcessor

if is_torch_available():
		import torch

if is_tf_available():
		import tensorflow as tf





@require_vision
@require_torchvision
class  _a							(    unittest.TestCase):




	def 							UpperCAmelCase__( self						:		Any		)->	Dict:
			lowerCAmelCase__       :      Dict   					= tempfile.mkdtemp()
			lowerCAmelCase__       :      int   					= SamImageProcessor()
			lowerCAmelCase__       :      Union[str, Any]   					= SamProcessor(_a		)
			processor.save_pretrained(self.tmpdirname		)




	def 							UpperCAmelCase__( self						:		List[Any]		, **_SCREAMING_SNAKE_CASE						:		Any		)->	str:
			return AutoProcessor.from_pretrained(self.tmpdirname		, **_a		).image_processor




	def 							UpperCAmelCase__( self						:		List[Any]		)->	Tuple:
			shutil.rmtree(self.tmpdirname		)




	def 							UpperCAmelCase__( self						:		Dict		)->	Optional[int]:
			lowerCAmelCase__       :      int   					= [np.random.randint(255		, size=(3, 30, 400)		, dtype=np.uinta		)]

			lowerCAmelCase__       :      int   					= [Image.fromarray(np.moveaxis(_a		, 0		, -1		)		) for x in image_inputs]

			return image_inputs




	def 							UpperCAmelCase__( self						:		int		)->	List[str]:
			lowerCAmelCase__       :      int   					= SamProcessor(image_processor=self.get_image_processor()		)
			processor.save_pretrained(self.tmpdirname		)

			lowerCAmelCase__       :      int   					= self.get_image_processor(do_normalize=_a		, padding_value=1.0		)

			lowerCAmelCase__       :      Optional[Any]   					= SamProcessor.from_pretrained(self.tmpdirname		, do_normalize=_a		, padding_value=1.0		)

			self.assertEqual(processor.image_processor.to_json_string()		, image_processor_add_kwargs.to_json_string()		)
			self.assertIsInstance(processor.image_processor		, _a		)




	def 							UpperCAmelCase__( self						:		Optional[Any]		)->	Any:
			lowerCAmelCase__       :      Any   					= self.get_image_processor()

			lowerCAmelCase__       :      List[str]   					= SamProcessor(image_processor=_a		)

			lowerCAmelCase__       :      Tuple   					= self.prepare_image_inputs()

			lowerCAmelCase__       :      Optional[Any]   					= image_processor(_a		, return_tensors='''np'''		)
			lowerCAmelCase__       :      Optional[int]   					= processor(images=_a		, return_tensors='''np'''		)

			input_feat_extract.pop('''original_sizes'''		)  # pop original_sizes as it is popped in the processor
			input_feat_extract.pop('''reshaped_input_sizes'''		)  # pop original_sizes as it is popped in the processor

			for key in input_feat_extract.keys():
					self.assertAlmostEqual(input_feat_extract[key].sum()		, input_processor[key].sum()		, delta=1E-2		)




	@require_torch
	def 							UpperCAmelCase__( self						:		Optional[Any]		)->	Union[str, Any]:
			lowerCAmelCase__       :      Tuple   					= self.get_image_processor()

			lowerCAmelCase__       :      List[Any]   					= SamProcessor(image_processor=_a		)
			lowerCAmelCase__       :      List[str]   					= [torch.ones((1, 3, 5, 5)		)]

			lowerCAmelCase__       :      str   					= [[1764, 2646]]

			lowerCAmelCase__       :      Dict   					= [[683, 1024]]
			lowerCAmelCase__       :      List[str]   					= processor.post_process_masks(_a		, _a		, _a		)
			self.assertEqual(masks[0].shape		, (1, 3, 1764, 2646)		)

			lowerCAmelCase__       :      Optional[int]   					= processor.post_process_masks(
			    _a		, torch.tensor(_a		)		, torch.tensor(_a		)		)
			self.assertEqual(masks[0].shape		, (1, 3, 1764, 2646)		)

			# should also work with np
			lowerCAmelCase__       :      str   					= [np.ones((1, 3, 5, 5)		)]
			lowerCAmelCase__       :      int   					= processor.post_process_masks(_a		, np.array(_a		)		, np.array(_a		)		)

			self.assertEqual(masks[0].shape		, (1, 3, 1764, 2646)		)

			lowerCAmelCase__       :      Union[str, Any]   					= [[1, 0], [0, 1]]
			with self.assertRaises(_a		):
					lowerCAmelCase__       :      Union[str, Any]   					= processor.post_process_masks(_a		, np.array(_a		)		, np.array(_a		)		)





@require_vision
@require_tf
class  _a							(    unittest.TestCase):




	def 							UpperCAmelCase__( self						:		int		)->	str:
			lowerCAmelCase__       :      Optional[int]   					= tempfile.mkdtemp()
			lowerCAmelCase__       :      Dict   					= SamImageProcessor()
			lowerCAmelCase__       :      Any   					= SamProcessor(_a		)
			processor.save_pretrained(self.tmpdirname		)




	def 							UpperCAmelCase__( self						:		str		, **_SCREAMING_SNAKE_CASE						:		Optional[Any]		)->	Dict:
			return AutoProcessor.from_pretrained(self.tmpdirname		, **_a		).image_processor




	def 							UpperCAmelCase__( self						:		Union[str, Any]		)->	Tuple:
			shutil.rmtree(self.tmpdirname		)




	def 							UpperCAmelCase__( self						:		Any		)->	int:
			lowerCAmelCase__       :      Tuple   					= [np.random.randint(255		, size=(3, 30, 400)		, dtype=np.uinta		)]

			lowerCAmelCase__       :      List[Any]   					= [Image.fromarray(np.moveaxis(_a		, 0		, -1		)		) for x in image_inputs]

			return image_inputs




	def 							UpperCAmelCase__( self						:		List[str]		)->	Union[str, Any]:
			lowerCAmelCase__       :      Union[str, Any]   					= SamProcessor(image_processor=self.get_image_processor()		)
			processor.save_pretrained(self.tmpdirname		)

			lowerCAmelCase__       :      Optional[int]   					= self.get_image_processor(do_normalize=_a		, padding_value=1.0		)

			lowerCAmelCase__       :      Union[str, Any]   					= SamProcessor.from_pretrained(self.tmpdirname		, do_normalize=_a		, padding_value=1.0		)

			self.assertEqual(processor.image_processor.to_json_string()		, image_processor_add_kwargs.to_json_string()		)
			self.assertIsInstance(processor.image_processor		, _a		)




	def 							UpperCAmelCase__( self						:		List[Any]		)->	Optional[int]:
			lowerCAmelCase__       :      Optional[Any]   					= self.get_image_processor()

			lowerCAmelCase__       :      List[str]   					= SamProcessor(image_processor=_a		)

			lowerCAmelCase__       :      str   					= self.prepare_image_inputs()

			lowerCAmelCase__       :      int   					= image_processor(_a		, return_tensors='''np'''		)
			lowerCAmelCase__       :      Any   					= processor(images=_a		, return_tensors='''np'''		)

			input_feat_extract.pop('''original_sizes'''		)  # pop original_sizes as it is popped in the processor
			input_feat_extract.pop('''reshaped_input_sizes'''		)  # pop reshaped_input_sizes as it is popped in the processor

			for key in input_feat_extract.keys():
					self.assertAlmostEqual(input_feat_extract[key].sum()		, input_processor[key].sum()		, delta=1E-2		)




	@require_tf
	def 							UpperCAmelCase__( self						:		Dict		)->	Any:
			lowerCAmelCase__       :      List[str]   					= self.get_image_processor()

			lowerCAmelCase__       :      str   					= SamProcessor(image_processor=_a		)
			lowerCAmelCase__       :      Tuple   					= [tf.ones((1, 3, 5, 5)		)]

			lowerCAmelCase__       :      List[Any]   					= [[1764, 2646]]

			lowerCAmelCase__       :      Union[str, Any]   					= [[683, 1024]]
			lowerCAmelCase__       :      List[Any]   					= processor.post_process_masks(_a		, _a		, _a		, return_tensors='''tf'''		)
			self.assertEqual(masks[0].shape		, (1, 3, 1764, 2646)		)

			lowerCAmelCase__       :      int   					= processor.post_process_masks(
			    _a		, tf.convert_to_tensor(_a		)		, tf.convert_to_tensor(_a		)		, return_tensors='''tf'''		, )
			self.assertEqual(masks[0].shape		, (1, 3, 1764, 2646)		)

			# should also work with np
			lowerCAmelCase__       :      Any   					= [np.ones((1, 3, 5, 5)		)]
			lowerCAmelCase__       :      List[Any]   					= processor.post_process_masks(
			    _a		, np.array(_a		)		, np.array(_a		)		, return_tensors='''tf'''		)

			self.assertEqual(masks[0].shape		, (1, 3, 1764, 2646)		)

			lowerCAmelCase__       :      List[Any]   					= [[1, 0], [0, 1]]
			with self.assertRaises(tf.errors.InvalidArgumentError		):
					lowerCAmelCase__       :      Optional[int]   					= processor.post_process_masks(
					    _a		, np.array(_a		)		, np.array(_a		)		, return_tensors='''tf'''		)





@require_vision
@require_torchvision
class  _a							(    unittest.TestCase):




	def 							UpperCAmelCase__( self						:		Any		)->	Tuple:
			lowerCAmelCase__       :      List[str]   					= tempfile.mkdtemp()
			lowerCAmelCase__       :      int   					= SamImageProcessor()
			lowerCAmelCase__       :      str   					= SamProcessor(_a		)
			processor.save_pretrained(self.tmpdirname		)




	def 							UpperCAmelCase__( self						:		Optional[int]		, **_SCREAMING_SNAKE_CASE						:		Any		)->	str:
			return AutoProcessor.from_pretrained(self.tmpdirname		, **_a		).image_processor




	def 							UpperCAmelCase__( self						:		Any		)->	List[Any]:
			shutil.rmtree(self.tmpdirname		)




	def 							UpperCAmelCase__( self						:		Union[str, Any]		)->	Union[str, Any]:
			lowerCAmelCase__       :      Any   					= [np.random.randint(255		, size=(3, 30, 400)		, dtype=np.uinta		)]

			lowerCAmelCase__       :      Tuple   					= [Image.fromarray(np.moveaxis(_a		, 0		, -1		)		) for x in image_inputs]

			return image_inputs




	@is_pt_tf_cross_test
	def 							UpperCAmelCase__( self						:		Union[str, Any]		)->	str:
			lowerCAmelCase__       :      Union[str, Any]   					= self.get_image_processor()

			lowerCAmelCase__       :      Optional[Any]   					= SamProcessor(image_processor=_a		)
			lowerCAmelCase__       :      str   					= np.random.randint(0		, 2		, size=(1, 3, 5, 5)		).astype(np.floataa		)
			lowerCAmelCase__       :      Any   					= [tf.convert_to_tensor(_a		)]
			lowerCAmelCase__       :      Optional[Any]   					= [torch.tensor(_a		)]

			lowerCAmelCase__       :      Any   					= [[1764, 2646]]

			lowerCAmelCase__       :      List[str]   					= [[683, 1024]]
			lowerCAmelCase__       :      Dict   					= processor.post_process_masks(
			    _a		, _a		, _a		, return_tensors='''tf'''		)
			lowerCAmelCase__       :      List[Any]   					= processor.post_process_masks(
			    _a		, _a		, _a		, return_tensors='''pt'''		)

			self.assertTrue(np.all(tf_masks[0].numpy() == pt_masks[0].numpy()		)		)




	@is_pt_tf_cross_test
	def 							UpperCAmelCase__( self						:		str		)->	Tuple:
			lowerCAmelCase__       :      Optional[Any]   					= self.get_image_processor()

			lowerCAmelCase__       :      Any   					= SamProcessor(image_processor=_a		)

			lowerCAmelCase__       :      Optional[Any]   					= self.prepare_image_inputs()

			lowerCAmelCase__       :      int   					= image_processor(_a		, return_tensors='''pt'''		)["pixel_values"].numpy()
			lowerCAmelCase__       :      str   					= processor(images=_a		, return_tensors='''pt'''		)["pixel_values"].numpy()

			lowerCAmelCase__       :      Optional[Any]   					= image_processor(_a		, return_tensors='''tf'''		)["pixel_values"].numpy()
			lowerCAmelCase__       :      Any   					= processor(images=_a		, return_tensors='''tf'''		)["pixel_values"].numpy()

			self.assertTrue(np.allclose(_a		, _a		)		)
			self.assertTrue(np.allclose(_a		, _a		)		)
			self.assertTrue(np.allclose(_a		, _a		)		)








import random

from .binary_exp_mod import bin_exp_mod






def 					lowerCamelCase_   (	_a     ,       _a=1_000	):




		"""simple docstring"""






		if n < 2:
				return False

		if n % 2 == 0:
				return n == 2

		# this means n is odd
		lowerCAmelCase__       :      int   					= n - 1
		lowerCAmelCase__       :      Any   					= 0
		while d % 2 == 0:
				d /= 2
				exp += 1

		# n - 1=d*(2**exp)
		lowerCAmelCase__       :      Optional[Any]   					= 0
		while count < prec:
				lowerCAmelCase__       :      Optional[Any]   					= random.randint(2     ,       n - 1	)
				lowerCAmelCase__       :      List[Any]   					= bin_exp_mod(_a     ,       _a     ,       _a	)
				if b != 1:
						lowerCAmelCase__       :      Dict   					= True
						for _ in range(_a	):
								if b == n - 1:
										lowerCAmelCase__       :      Union[str, Any]   					= False
										break
								lowerCAmelCase__       :      Tuple   					= b * b
								b %= n
						if flag:
								return False
						count += 1
		return True


if __name__ == "__main__":
		lowerCamelCase						=		abs(int(input('''Enter bound : ''').strip()))
		print('''Here\'s the list of primes:''')
		print(''', '''.join(str(i) for i in range(n + 1) if is_prime_big(i)))




