"""simple docstring"""




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 					__A						(	self						):
       _lowerCAmelCase		: Dict						    =  tempfile.mkdtemp()
       _lowerCAmelCase		: Tuple						    =  SamImageProcessor()
       _lowerCAmelCase		: Tuple						    =  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						):
       _lowerCAmelCase		: Any						    =  [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 					__A						(	self						):
       _lowerCAmelCase		: str						    =  SamProcessor(image_processor=self.get_image_processor()						)
       processor.save_pretrained(self.tmpdirname						)

       _lowerCAmelCase		: Dict						    =  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 					__A						(	self						):
       _lowerCAmelCase		: Dict						    =  self.get_image_processor()

       _lowerCAmelCase		: List[Any]						    =  SamProcessor(image_processor=a__						)

       _lowerCAmelCase		: Optional[int]						    =  self.prepare_image_inputs()

       _lowerCAmelCase		: List[Any]						    =  image_processor(a__       ,  return_tensors="""np"""						)
       _lowerCAmelCase		: Union[str, 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 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						):
       _lowerCAmelCase		: Optional[Any]						    =  self.get_image_processor()

       _lowerCAmelCase		: str						    =  SamProcessor(image_processor=a__						)
       _lowerCAmelCase		: Optional[int]						    =  [torch.ones((1, 3, 5, 5)						)]

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

       _lowerCAmelCase		: str						    =  [[683, 1024]]
       _lowerCAmelCase		: int						    =  processor.post_process_masks(a__       ,  a__       ,  a__						)
       self.assertEqual(masks[0].shape       ,  (1, 3, 1764, 2646)						)

       _lowerCAmelCase		: Optional[Any]						    =  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		: List[Any]						    =  [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		: Dict						    =  [[1, 0], [0, 1]]
       with self.assertRaises(a__						):
         _lowerCAmelCase		: Tuple						    =  processor.post_process_masks(a__       ,  np.array(a__						)       ,  np.array(a__						)						)







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






     def 					__A						(	self						):
       _lowerCAmelCase		: List[str]						    =  tempfile.mkdtemp()
       _lowerCAmelCase		: List[str]						    =  SamImageProcessor()
       _lowerCAmelCase		: Optional[Any]						    =  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						):
       _lowerCAmelCase		: int						    =  [np.random.randint(255       ,  size=(3, 30, 400)       ,  dtype=np.uinta						)]

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

       return image_inputs






     def 					__A						(	self						):
       _lowerCAmelCase		: List[str]						    =  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		: Optional[int]						    =  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						):
       _lowerCAmelCase		: Tuple						    =  self.get_image_processor()

       _lowerCAmelCase		: str						    =  SamProcessor(image_processor=a__						)

       _lowerCAmelCase		: List[str]						    =  self.prepare_image_inputs()

       _lowerCAmelCase		: List[str]						    =  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 					__A						(	self						):
       _lowerCAmelCase		: List[Any]						    =  self.get_image_processor()

       _lowerCAmelCase		: Dict						    =  SamProcessor(image_processor=a__						)
       _lowerCAmelCase		: Dict						    =  [tf.ones((1, 3, 5, 5)						)]

       _lowerCAmelCase		: List[str]						    =  [[1764, 2646]]

       _lowerCAmelCase		: List[str]						    =  [[683, 1024]]
       _lowerCAmelCase		: Optional[Any]						    =  processor.post_process_masks(a__       ,  a__       ,  a__       ,  return_tensors="""tf"""						)
       self.assertEqual(masks[0].shape       ,  (1, 3, 1764, 2646)						)

       _lowerCAmelCase		: Dict						    =  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		: List[str]						    =  [np.ones((1, 3, 5, 5)						)]
       _lowerCAmelCase		: List[str]						    =  processor.post_process_masks(
           a__       ,  np.array(a__						)       ,  np.array(a__						)       ,  return_tensors="""tf"""						)

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

       _lowerCAmelCase		: Any						    =  [[1, 0], [0, 1]]
       with self.assertRaises(tf.errors.InvalidArgumentError						):
         _lowerCAmelCase		: Tuple						    =  processor.post_process_masks(
             a__       ,  np.array(a__						)       ,  np.array(a__						)       ,  return_tensors="""tf"""						)







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






     def 					__A						(	self						):
       _lowerCAmelCase		: Union[str, Any]						    =  tempfile.mkdtemp()
       _lowerCAmelCase		: int						    =  SamImageProcessor()
       _lowerCAmelCase		: str						    =  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						):
       _lowerCAmelCase		: str						    =  [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 					__A						(	self						):
       _lowerCAmelCase		: Optional[int]						    =  self.get_image_processor()

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

       _lowerCAmelCase		: Tuple						    =  [[1764, 2646]]

       _lowerCAmelCase		: Dict						    =  [[683, 1024]]
       _lowerCAmelCase		: Optional[int]						    =  processor.post_process_masks(
           a__       ,  a__       ,  a__       ,  return_tensors="""tf"""						)
       _lowerCAmelCase		: Dict						    =  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						):
       _lowerCAmelCase		: Tuple						    =  self.get_image_processor()

       _lowerCAmelCase		: Any						    =  SamProcessor(image_processor=a__						)

       _lowerCAmelCase		: List[str]						    =  self.prepare_image_inputs()

       _lowerCAmelCase		: Any						    =  image_processor(a__       ,  return_tensors="""pt"""						)["""pixel_values"""].numpy()
       _lowerCAmelCase		: Optional[int]						    =  processor(images=a__       ,  return_tensors="""pt"""						)["""pixel_values"""].numpy()

       _lowerCAmelCase		: Optional[Any]						    =  image_processor(a__       ,  return_tensors="""tf"""						)["""pixel_values"""].numpy()
       _lowerCAmelCase		: Optional[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__						)						)





"""simple docstring"""




def 							SCREAMING_SNAKE_CASE  (    _lowerCamelCase		: int			) ->   bool:
  return sum(i for i in range(1    ,number // 2 + 1			) if number % i == 0			) == number


if __name__ == "__main__":
     print('Program to check whether a number is a Perfect number or not...')
     _a   :	int 					=     int(input('Enter number: ').strip())
     print(F"""{number} is {"" if perfect(number) else "not "}a Perfect Number.""")




