


from copy import deepcopy
from typing import Optional, Union

import numpy as np

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
from ...utils import TensorType, is_tf_available, is_torch_available


if is_torch_available():
    import torch

if is_tf_available():
    import tensorflow as tf



class 	__lowerCamelCase			(__UpperCamelCase						):
       _lowercase											=     ["image_processor"]
       _lowercase											=     "SamImageProcessor"







       def __init__(			self: Any,A_: Any					):






            '''simple docstring'''




            super().__init__(snake_case__					)
            __UpperCamelCase =			self.image_processor
            __UpperCamelCase =			-10
            __UpperCamelCase =			self.image_processor.size['longest_edge']







       def __call__(			self: List[str],A_: Tuple=None,A_: List[str]=None,A_: int=None,A_: Tuple=None,A_: Optional[Union[str, TensorType]] = None,**A_: Optional[Any],):






            '''simple docstring'''




            __UpperCamelCase =			self.image_processor(
                snake_case__,return_tensors=snake_case__,**snake_case__,)

            # pop arguments that are not used in the foward but used nevertheless
            __UpperCamelCase =			encoding_image_processor['original_sizes']

            if hasattr(snake_case__,'numpy'					):  # Checks if Torch or TF tensor
                 __UpperCamelCase =			original_sizes.numpy()

            __UpperCamelCase,    __UpperCamelCase,    __UpperCamelCase =			self._check_and_preprocess_points(
                input_points=snake_case__,input_labels=snake_case__,input_boxes=snake_case__,)

            __UpperCamelCase =			self._normalize_and_convert(
                snake_case__,snake_case__,input_points=snake_case__,input_labels=snake_case__,input_boxes=snake_case__,return_tensors=snake_case__,)

            return encoding_image_processor







       def 		snake_case_	(			self: List[Any],A_: Tuple,A_: Optional[Any],A_: Any=None,A_: Tuple=None,A_: Any=None,A_: Any="pt",):






            '''simple docstring'''




            if input_points is not None:
                 if len(snake_case__					) != len(snake_case__					):
                      __UpperCamelCase =			[
                          self._normalize_coordinates(self.target_size,snake_case__,original_sizes[0]					) for point in input_points
                      ]
                 else:
                      __UpperCamelCase =			[
                          self._normalize_coordinates(self.target_size,snake_case__,snake_case__					)
                          for point, original_size in zip(snake_case__,snake_case__					)
                      ]
                 # check that all arrays have the same shape
                 if not all(point.shape == input_points[0].shape for point in input_points					):
                      if input_labels is not None:
                           __UpperCamelCase,    __UpperCamelCase =			self._pad_points_and_labels(snake_case__,snake_case__					)

                 __UpperCamelCase =			np.array(snake_case__					)

            if input_labels is not None:
                 __UpperCamelCase =			np.array(snake_case__					)

            if input_boxes is not None:
                 if len(snake_case__					) != len(snake_case__					):
                      __UpperCamelCase =			[
                          self._normalize_coordinates(self.target_size,snake_case__,original_sizes[0],is_bounding_box=snake_case__					)
                          for box in input_boxes
                      ]
                 else:
                      __UpperCamelCase =			[
                          self._normalize_coordinates(self.target_size,snake_case__,snake_case__,is_bounding_box=snake_case__					)
                          for box, original_size in zip(snake_case__,snake_case__					)
                      ]
                 __UpperCamelCase =			np.array(snake_case__					)

            if input_boxes is not None:
                 if return_tensors == "pt":
                      __UpperCamelCase =			torch.from_numpy(snake_case__					)
                      # boxes batch size of 1 by default
                      __UpperCamelCase =			input_boxes.unsqueeze(1					) if len(input_boxes.shape					) != 3 else input_boxes
                 elif return_tensors == "tf":
                      __UpperCamelCase =			tf.convert_to_tensor(snake_case__					)
                      # boxes batch size of 1 by default
                      __UpperCamelCase =			tf.expand_dims(snake_case__,1					) if len(input_boxes.shape					) != 3 else input_boxes
                 encoding_image_processor.update({'input_boxes': input_boxes}					)
            if input_points is not None:
                 if return_tensors == "pt":
                      __UpperCamelCase =			torch.from_numpy(snake_case__					)
                      # point batch size of 1 by default
                      __UpperCamelCase =			input_points.unsqueeze(1					) if len(input_points.shape					) != 4 else input_points
                 elif return_tensors == "tf":
                      __UpperCamelCase =			tf.convert_to_tensor(snake_case__					)
                      # point batch size of 1 by default
                      __UpperCamelCase =			tf.expand_dims(snake_case__,1					) if len(input_points.shape					) != 4 else input_points
                 encoding_image_processor.update({'input_points': input_points}					)
            if input_labels is not None:
                 if return_tensors == "pt":
                      __UpperCamelCase =			torch.from_numpy(snake_case__					)
                      # point batch size of 1 by default
                      __UpperCamelCase =			input_labels.unsqueeze(1					) if len(input_labels.shape					) != 3 else input_labels
                 elif return_tensors == "tf":
                      __UpperCamelCase =			tf.convert_to_tensor(snake_case__					)
                      # point batch size of 1 by default
                      __UpperCamelCase =			tf.expand_dims(snake_case__,1					) if len(input_labels.shape					) != 3 else input_labels
                 encoding_image_processor.update({'input_labels': input_labels}					)

            return encoding_image_processor







       def 		snake_case_	(			self: str,A_: Any,A_: str					):






            '''simple docstring'''




            __UpperCamelCase =			max([point.shape[0] for point in input_points]					)
            __UpperCamelCase =			[]
            for i, point in enumerate(snake_case__					):
                 if point.shape[0] != expected_nb_points:
                      __UpperCamelCase =			np.concatenate(
                          [point, np.zeros((expected_nb_points - point.shape[0], 2)					) + self.point_pad_value],axis=0					)
                      __UpperCamelCase =			np.append(input_labels[i],[self.point_pad_value]					)
                 processed_input_points.append(snake_case__					)
            __UpperCamelCase =			processed_input_points
            return input_points, input_labels







       def 		snake_case_	(			self: Tuple,A_: int,A_: np.ndarray,A_: Dict,A_: Any=False					):






            '''simple docstring'''




            __UpperCamelCase,    __UpperCamelCase =			original_size
            __UpperCamelCase,    __UpperCamelCase =			self.image_processor._get_preprocess_shape(snake_case__,longest_edge=snake_case__					)
            __UpperCamelCase =			deepcopy(snake_case__					).astype(snake_case__					)

            if is_bounding_box:
                 __UpperCamelCase =			coords.reshape(-1,2,2					)

            __UpperCamelCase =			coords[..., 0] * (new_w / old_w)
            __UpperCamelCase =			coords[..., 1] * (new_h / old_h)

            if is_bounding_box:
                 __UpperCamelCase =			coords.reshape(-1,4					)

            return coords







       def 		snake_case_	(			self: str,A_: int=None,A_: Union[str, Any]=None,A_: Union[str, Any]=None,):






            '''simple docstring'''




            if input_points is not None:
                 if hasattr(snake_case__,'numpy'					):  # Checks for TF or Torch tensor
                      __UpperCamelCase =			input_points.numpy().tolist()

                 if not isinstance(snake_case__,snake_case__					) or not isinstance(input_points[0],snake_case__					):
                      raise ValueError('Input points must be a list of list of floating points.'					)
                 __UpperCamelCase =			[np.array(snake_case__					) for input_point in input_points]
            else:
                 __UpperCamelCase =			None

            if input_labels is not None:
                 if hasattr(snake_case__,'numpy'					):
                      __UpperCamelCase =			input_labels.numpy().tolist()

                 if not isinstance(snake_case__,snake_case__					) or not isinstance(input_labels[0],snake_case__					):
                      raise ValueError('Input labels must be a list of list integers.'					)
                 __UpperCamelCase =			[np.array(snake_case__					) for label in input_labels]
            else:
                 __UpperCamelCase =			None

            if input_boxes is not None:
                 if hasattr(snake_case__,'numpy'					):
                      __UpperCamelCase =			input_boxes.numpy().tolist()

                 if (
                     not isinstance(snake_case__,snake_case__					)
                     or not isinstance(input_boxes[0],snake_case__					)
                     or not isinstance(input_boxes[0][0],snake_case__					)
                 ):
                      raise ValueError('Input boxes must be a list of list of list of floating points.'					)
                 __UpperCamelCase =			[np.array(snake_case__					).astype(np.floataa					) for box in input_boxes]
            else:
                 __UpperCamelCase =			None

            return input_points, input_labels, input_boxes







       @property
       def 		snake_case_	(			self: Optional[int]					):






            '''simple docstring'''




            __UpperCamelCase =			self.image_processor.model_input_names
            return list(dict.fromkeys(snake_case__					)					)







       def 		snake_case_	(			self: List[str],*A_: str,**A_: List[Any]					):






            '''simple docstring'''




            return self.image_processor.post_process_masks(*snake_case__,**snake_case__					)



"""simple docstring"""




def 				_UpperCAmelCase		(							lowerCamelCase__      ,	lowerCamelCase__  ):





		"""simple docstring"""




		return abs(lowerCamelCase__  ) if a == 0 else greatest_common_divisor(b % a      ,	lowerCamelCase__  )







def 				_UpperCAmelCase		(							lowerCamelCase__      ,	lowerCamelCase__  ):





		"""simple docstring"""




		while y:  # --> when y=0 then loop will terminate and return x as final GCD.
				lowerCAmelCase__ ,       lowerCAmelCase__   = y, x % y
		return abs(lowerCamelCase__  )







def 				_UpperCAmelCase		(							):





		"""simple docstring"""




		try:
				lowerCAmelCase__   = input("""Enter two integers separated by comma (,): """  ).split(""","""  )
				lowerCAmelCase__   = int(nums[0]  )
				lowerCAmelCase__   = int(nums[1]  )
				print(
				    f"""greatest_common_divisor({num_a}, {num_a}) = """
				    f"""{greatest_common_divisor(lowerCamelCase__      ,	lowerCamelCase__  )}"""  )
				print(f"""By iterative gcd({num_a}, {num_a}) = {gcd_by_iterative(lowerCamelCase__      ,	lowerCamelCase__  )}"""  )
		except (IndexError, UnboundLocalError, ValueError):
				print("""Wrong input"""  )


if __name__ == "__main__":
			main()




