
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 				lowercase		(					unittest.TestCase		):




							def  A__      (				self):
												lowercase							=						tempfile.mkdtemp()
												lowercase							=						SamImageProcessor()
												lowercase							=						SamProcessor(A__)
												processor.save_pretrained(self.tmpdirname)




							def  A__      (				self   ,**A__):
												return AutoProcessor.from_pretrained(self.tmpdirname   ,**A__).image_processor




							def  A__      (				self):
												shutil.rmtree(self.tmpdirname)




							def  A__      (				self):
												lowercase							=						[np.random.randint(2_5_5   ,size=(3, 3_0, 4_0_0)   ,dtype=np.uinta)]

												lowercase							=						[Image.fromarray(np.moveaxis(A__   ,0   ,-1)) for x in image_inputs]

												return image_inputs




							def  A__      (				self):
												lowercase							=						SamProcessor(image_processor=self.get_image_processor())
												processor.save_pretrained(self.tmpdirname)

												lowercase							=						self.get_image_processor(do_normalize=A__   ,padding_value=1.0)

												lowercase							=						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  A__      (				self):
												lowercase							=						self.get_image_processor()

												lowercase							=						SamProcessor(image_processor=A__)

												lowercase							=						self.prepare_image_inputs()

												lowercase							=						image_processor(A__   ,return_tensors='''np''')
												lowercase							=						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  A__      (				self):
												lowercase							=						self.get_image_processor()

												lowercase							=						SamProcessor(image_processor=A__)
												lowercase							=						[torch.ones((1, 3, 5, 5))]

												lowercase							=						[[1_7_6_4, 2_6_4_6]]

												lowercase							=						[[6_8_3, 1_0_2_4]]
												lowercase							=						processor.post_process_masks(A__   ,A__   ,A__)
												self.assertEqual(masks[0].shape   ,(1, 3, 1_7_6_4, 2_6_4_6))

												lowercase							=						processor.post_process_masks(
												    A__   ,torch.tensor(A__)   ,torch.tensor(A__))
												self.assertEqual(masks[0].shape   ,(1, 3, 1_7_6_4, 2_6_4_6))

												# should also work with np
												lowercase							=						[np.ones((1, 3, 5, 5))]
												lowercase							=						processor.post_process_masks(A__   ,np.array(A__)   ,np.array(A__))

												self.assertEqual(masks[0].shape   ,(1, 3, 1_7_6_4, 2_6_4_6))

												lowercase							=						[[1, 0], [0, 1]]
												with self.assertRaises(A__):
																	lowercase							=						processor.post_process_masks(A__   ,np.array(A__)   ,np.array(A__))







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




							def  A__      (				self):
												lowercase							=						tempfile.mkdtemp()
												lowercase							=						SamImageProcessor()
												lowercase							=						SamProcessor(A__)
												processor.save_pretrained(self.tmpdirname)




							def  A__      (				self   ,**A__):
												return AutoProcessor.from_pretrained(self.tmpdirname   ,**A__).image_processor




							def  A__      (				self):
												shutil.rmtree(self.tmpdirname)




							def  A__      (				self):
												lowercase							=						[np.random.randint(2_5_5   ,size=(3, 3_0, 4_0_0)   ,dtype=np.uinta)]

												lowercase							=						[Image.fromarray(np.moveaxis(A__   ,0   ,-1)) for x in image_inputs]

												return image_inputs




							def  A__      (				self):
												lowercase							=						SamProcessor(image_processor=self.get_image_processor())
												processor.save_pretrained(self.tmpdirname)

												lowercase							=						self.get_image_processor(do_normalize=A__   ,padding_value=1.0)

												lowercase							=						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  A__      (				self):
												lowercase							=						self.get_image_processor()

												lowercase							=						SamProcessor(image_processor=A__)

												lowercase							=						self.prepare_image_inputs()

												lowercase							=						image_processor(A__   ,return_tensors='''np''')
												lowercase							=						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  A__      (				self):
												lowercase							=						self.get_image_processor()

												lowercase							=						SamProcessor(image_processor=A__)
												lowercase							=						[tf.ones((1, 3, 5, 5))]

												lowercase							=						[[1_7_6_4, 2_6_4_6]]

												lowercase							=						[[6_8_3, 1_0_2_4]]
												lowercase							=						processor.post_process_masks(A__   ,A__   ,A__   ,return_tensors='''tf''')
												self.assertEqual(masks[0].shape   ,(1, 3, 1_7_6_4, 2_6_4_6))

												lowercase							=						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, 1_7_6_4, 2_6_4_6))

												# should also work with np
												lowercase							=						[np.ones((1, 3, 5, 5))]
												lowercase							=						processor.post_process_masks(
												    A__   ,np.array(A__)   ,np.array(A__)   ,return_tensors='''tf''')

												self.assertEqual(masks[0].shape   ,(1, 3, 1_7_6_4, 2_6_4_6))

												lowercase							=						[[1, 0], [0, 1]]
												with self.assertRaises(tf.errors.InvalidArgumentError):
																	lowercase							=						processor.post_process_masks(
																	    A__   ,np.array(A__)   ,np.array(A__)   ,return_tensors='''tf''')







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




							def  A__      (				self):
												lowercase							=						tempfile.mkdtemp()
												lowercase							=						SamImageProcessor()
												lowercase							=						SamProcessor(A__)
												processor.save_pretrained(self.tmpdirname)




							def  A__      (				self   ,**A__):
												return AutoProcessor.from_pretrained(self.tmpdirname   ,**A__).image_processor




							def  A__      (				self):
												shutil.rmtree(self.tmpdirname)




							def  A__      (				self):
												lowercase							=						[np.random.randint(2_5_5   ,size=(3, 3_0, 4_0_0)   ,dtype=np.uinta)]

												lowercase							=						[Image.fromarray(np.moveaxis(A__   ,0   ,-1)) for x in image_inputs]

												return image_inputs




							@is_pt_tf_cross_test
							def  A__      (				self):
												lowercase							=						self.get_image_processor()

												lowercase							=						SamProcessor(image_processor=A__)
												lowercase							=						np.random.randint(0   ,2   ,size=(1, 3, 5, 5)).astype(np.floataa)
												lowercase							=						[tf.convert_to_tensor(A__)]
												lowercase							=						[torch.tensor(A__)]

												lowercase							=						[[1_7_6_4, 2_6_4_6]]

												lowercase							=						[[6_8_3, 1_0_2_4]]
												lowercase							=						processor.post_process_masks(
												    A__   ,A__   ,A__   ,return_tensors='''tf''')
												lowercase							=						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  A__      (				self):
												lowercase							=						self.get_image_processor()

												lowercase							=						SamProcessor(image_processor=A__)

												lowercase							=						self.prepare_image_inputs()

												lowercase							=						image_processor(A__   ,return_tensors='''pt''')['''pixel_values'''].numpy()
												lowercase							=						processor(images=A__   ,return_tensors='''pt''')['''pixel_values'''].numpy()

												lowercase							=						image_processor(A__   ,return_tensors='''tf''')['''pixel_values'''].numpy()
												lowercase							=						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        UpperCamelCase    (							lowerCAmelCase__ ,			lowerCAmelCase__=1000		):
					'''simple docstring'''
					if n < 2:
										return False

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

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

					# n - 1=d*(2**exp)
					lowercase							=						0
					while count < prec:
										lowercase							=						random.randint(2 ,			n - 1		)
										lowercase							=						bin_exp_mod(lowerCAmelCase__ ,			lowerCAmelCase__ ,			lowerCAmelCase__		)
										if b != 1:
															lowercase							=						True
															for _ in range(lowerCAmelCase__		):
																				if b == n - 1:
																									lowercase							=						False
																									break
																				lowercase							=						b * b
																				b %= n
															if flag:
																				return False
															count += 1
					return True


if __name__ == "__main__":
							lowercase__		:Tuple   =    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)))




