





'''simple docstring'''







import unittest

import numpy as np
from datasets import load_dataset

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 SegformerImageProcessor


class        __a   (unittest.TestCase  ):

							def __init__(				self				:  List[Any]							,  __magic_name__				:  int							,  __magic_name__				:  Dict=7							,  __magic_name__				:  List[Any]=3							,  __magic_name__				:  int=30							,  __magic_name__				:  Dict=4_00							,  __magic_name__				:  Union[str, Any]=True							,  __magic_name__				:  List[str]=None							,  __magic_name__				:  str=True							,  __magic_name__				:  Dict=[0.5, 0.5, 0.5]							,  __magic_name__				:  Optional[Any]=[0.5, 0.5, 0.5]							,  __magic_name__				:  List[str]=False							,  )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   str      =	size if size is not None else {'''height''': 30, '''width''': 30}
													UpperCAmelCase_      :   List[Any]      =	parent
													UpperCAmelCase_      :   str      =	batch_size
													UpperCAmelCase_      :   int      =	num_channels
													UpperCAmelCase_      :   List[str]      =	min_resolution
													UpperCAmelCase_      :   Any      =	max_resolution
													UpperCAmelCase_      :   Any      =	do_resize
													UpperCAmelCase_      :   List[str]      =	size
													UpperCAmelCase_      :   Optional[Any]      =	do_normalize
													UpperCAmelCase_      :   List[str]      =	image_mean
													UpperCAmelCase_      :   Optional[Any]      =	image_std
													UpperCAmelCase_      :   Any      =	do_reduce_labels



							def      UpperCAmelCase__						(				self				:  int )       ->							str:







													"""simple docstring"""
													return {
													    "do_resize": self.do_resize,
													    "size": self.size,
													    "do_normalize": self.do_normalize,
													    "image_mean": self.image_mean,
													    "image_std": self.image_std,
													    "do_reduce_labels": self.do_reduce_labels,
													}





def 							lowerCamelCase_   (	)			->						str:
						UpperCAmelCase_      :   str      =	load_dataset('''hf-internal-testing/fixtures_ade20k''',      split='''test''' )

						UpperCAmelCase_      :   int      =	Image.open(dataset[0]['''file'''] )
						UpperCAmelCase_      :   List[str]      =	Image.open(dataset[1]['''file'''] )

						return image, map





def 							lowerCamelCase_   (	)			->						Dict:
						UpperCAmelCase_      :   List[Any]      =	load_dataset('''hf-internal-testing/fixtures_ade20k''',      split='''test''' )

						UpperCAmelCase_      :   str      =	Image.open(dataset[0]['''file'''] )
						UpperCAmelCase_      :   List[str]      =	Image.open(dataset[1]['''file'''] )
						UpperCAmelCase_      :   Optional[Any]      =	Image.open(dataset[2]['''file'''] )
						UpperCAmelCase_      :   Optional[int]      =	Image.open(dataset[3]['''file'''] )

						return [imagea, imagea], [mapa, mapa]


@require_torch
@require_vision
class        __a   (lowerCamelCase							,		unittest.TestCase  ):
							__a       : Dict          =							SegformerImageProcessor if is_vision_available() else None

							def      UpperCAmelCase__						(				self				:  int )       ->							Tuple:







													"""simple docstring"""
													UpperCAmelCase_      :   Any      =	SegformerImageProcessingTester(self )

							@property
							def      UpperCAmelCase__						(				self				:  Optional[int] )       ->							List[Any]:







													"""simple docstring"""
													return self.image_processor_tester.prepare_image_processor_dict()

							def      UpperCAmelCase__						(				self				:  Union[str, Any] )       ->							Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   List[Any]      =	self.image_processing_class(**self.image_processor_dict )
													self.assertTrue(hasattr(__magic_name__							,  '''do_resize''' ) )
													self.assertTrue(hasattr(__magic_name__							,  '''size''' ) )
													self.assertTrue(hasattr(__magic_name__							,  '''do_normalize''' ) )
													self.assertTrue(hasattr(__magic_name__							,  '''image_mean''' ) )
													self.assertTrue(hasattr(__magic_name__							,  '''image_std''' ) )
													self.assertTrue(hasattr(__magic_name__							,  '''do_reduce_labels''' ) )

							def      UpperCAmelCase__						(				self				:  str )       ->							Any:







													"""simple docstring"""
													UpperCAmelCase_      :   Tuple      =	self.image_processing_class.from_dict(self.image_processor_dict )
													self.assertEqual(image_processor.size							,  {'''height''': 30, '''width''': 30} )
													self.assertEqual(image_processor.do_reduce_labels							,  __magic_name__ )

													UpperCAmelCase_      :   Optional[Any]      =	self.image_processing_class.from_dict(self.image_processor_dict							,  size=42							,  reduce_labels=__magic_name__ )
													self.assertEqual(image_processor.size							,  {'''height''': 42, '''width''': 42} )
													self.assertEqual(image_processor.do_reduce_labels							,  __magic_name__ )

							def      UpperCAmelCase__						(				self				:  List[Any] )       ->							Any:







													"""simple docstring"""
													pass

							def      UpperCAmelCase__						(				self				:  Union[str, Any] )       ->							Tuple:







													"""simple docstring"""
													# Initialize image_processing
													UpperCAmelCase_      :   Dict      =	self.image_processing_class(**self.image_processor_dict )
													# create random PIL images
													UpperCAmelCase_      :   List[str]      =	prepare_image_inputs(self.image_processor_tester							,  equal_resolution=__magic_name__ )
													for image in image_inputs:
																			self.assertIsInstance(__magic_name__							,  Image.Image )

													# Test not batched input
													UpperCAmelCase_      :   int      =	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
													UpperCAmelCase_      :   Union[str, Any]      =	image_processing(__magic_name__							,  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      UpperCAmelCase__						(				self				:  Any )       ->							str:







													"""simple docstring"""
													# Initialize image_processing
													UpperCAmelCase_      :   List[Any]      =	self.image_processing_class(**self.image_processor_dict )
													# create random numpy tensors
													UpperCAmelCase_      :   Optional[int]      =	prepare_image_inputs(self.image_processor_tester							,  equal_resolution=__magic_name__							,  numpify=__magic_name__ )
													for image in image_inputs:
																			self.assertIsInstance(__magic_name__							,  np.ndarray )

													# Test not batched input
													UpperCAmelCase_      :   str      =	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
													UpperCAmelCase_      :   Dict      =	image_processing(__magic_name__							,  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      UpperCAmelCase__						(				self				:  Any )       ->							List[Any]:







													"""simple docstring"""
													# Initialize image_processing
													UpperCAmelCase_      :   Any      =	self.image_processing_class(**self.image_processor_dict )
													# create random PyTorch tensors
													UpperCAmelCase_      :   str      =	prepare_image_inputs(self.image_processor_tester							,  equal_resolution=__magic_name__							,  torchify=__magic_name__ )
													for image in image_inputs:
																			self.assertIsInstance(__magic_name__							,  torch.Tensor )

													# Test not batched input
													UpperCAmelCase_      :   int      =	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
													UpperCAmelCase_      :   Any      =	image_processing(__magic_name__							,  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      UpperCAmelCase__						(				self				:  Optional[Any] )       ->							Optional[Any]:







													"""simple docstring"""
													# Initialize image_processing
													UpperCAmelCase_      :   int      =	self.image_processing_class(**self.image_processor_dict )
													# create random PyTorch tensors
													UpperCAmelCase_      :   int      =	prepare_image_inputs(self.image_processor_tester							,  equal_resolution=__magic_name__							,  torchify=__magic_name__ )
													UpperCAmelCase_      :   Tuple      =	[]
													for image in image_inputs:
																			self.assertIsInstance(__magic_name__							,  torch.Tensor )
																			maps.append(torch.zeros(image.shape[-2:] ).long() )

													# Test not batched input
													UpperCAmelCase_      :   List[str]      =	image_processing(image_inputs[0]							,  maps[0]							,  return_tensors='''pt''' )
													self.assertEqual(
													    encoding['''pixel_values'''].shape							,  (
													        1,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )							,  )
													self.assertEqual(
													    encoding['''labels'''].shape							,  (
													        1,
													        self.image_processor_tester.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )							,  )
													self.assertEqual(encoding['''labels'''].dtype							,  torch.long )
													self.assertTrue(encoding['''labels'''].min().item() >= 0 )
													self.assertTrue(encoding['''labels'''].max().item() <= 2_55 )

													# Test batched
													UpperCAmelCase_      :   int      =	image_processing(__magic_name__							,  __magic_name__							,  return_tensors='''pt''' )
													self.assertEqual(
													    encoding['''pixel_values'''].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'''],
													    )							,  )
													self.assertEqual(
													    encoding['''labels'''].shape							,  (
													        self.image_processor_tester.batch_size,
													        self.image_processor_tester.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )							,  )
													self.assertEqual(encoding['''labels'''].dtype							,  torch.long )
													self.assertTrue(encoding['''labels'''].min().item() >= 0 )
													self.assertTrue(encoding['''labels'''].max().item() <= 2_55 )

													# Test not batched input (PIL images)
													UpperCAmelCase_    ,							UpperCAmelCase_      :   Optional[int]      =	prepare_semantic_single_inputs()

													UpperCAmelCase_      :   Tuple      =	image_processing(__magic_name__							,  __magic_name__							,  return_tensors='''pt''' )
													self.assertEqual(
													    encoding['''pixel_values'''].shape							,  (
													        1,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )							,  )
													self.assertEqual(
													    encoding['''labels'''].shape							,  (
													        1,
													        self.image_processor_tester.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )							,  )
													self.assertEqual(encoding['''labels'''].dtype							,  torch.long )
													self.assertTrue(encoding['''labels'''].min().item() >= 0 )
													self.assertTrue(encoding['''labels'''].max().item() <= 2_55 )

													# Test batched input (PIL images)
													UpperCAmelCase_    ,							UpperCAmelCase_      :   str      =	prepare_semantic_batch_inputs()

													UpperCAmelCase_      :   Any      =	image_processing(__magic_name__							,  __magic_name__							,  return_tensors='''pt''' )
													self.assertEqual(
													    encoding['''pixel_values'''].shape							,  (
													        2,
													        self.image_processor_tester.num_channels,
													        self.image_processor_tester.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )							,  )
													self.assertEqual(
													    encoding['''labels'''].shape							,  (
													        2,
													        self.image_processor_tester.size['''height'''],
													        self.image_processor_tester.size['''width'''],
													    )							,  )
													self.assertEqual(encoding['''labels'''].dtype							,  torch.long )
													self.assertTrue(encoding['''labels'''].min().item() >= 0 )
													self.assertTrue(encoding['''labels'''].max().item() <= 2_55 )



							def      UpperCAmelCase__						(				self				:  Any )       ->							Tuple:







													"""simple docstring"""
													# Initialize image_processing
													UpperCAmelCase_      :   Any      =	self.image_processing_class(**self.image_processor_dict )

													# ADE20k has 150 classes, and the background is included, so labels should be between 0 and 150
													UpperCAmelCase_    ,							UpperCAmelCase_      :   Dict      =	prepare_semantic_single_inputs()
													UpperCAmelCase_      :   Tuple      =	image_processing(__magic_name__							,  __magic_name__							,  return_tensors='''pt''' )
													self.assertTrue(encoding['''labels'''].min().item() >= 0 )
													self.assertTrue(encoding['''labels'''].max().item() <= 1_50 )

													UpperCAmelCase_      :   Any      =	True
													UpperCAmelCase_      :   str      =	image_processing(__magic_name__							,  __magic_name__							,  return_tensors='''pt''' )
													self.assertTrue(encoding['''labels'''].min().item() >= 0 )
													self.assertTrue(encoding['''labels'''].max().item() <= 2_55 )










"""simple docstring"""
import doctest

import projectq
from projectq.ops import H, Measure
def   A_    (     _lowercase      ):







						'''simple docstring'''


						snake_case_					:Union[str, Any]		=     quantum_engine.allocate_qubit()
						H | qubit
						Measure | qubit
						return int(_lowercase      )


if __name__ == "__main__":
						doctest.testmod()

						# initialises a new quantum backend
						__a           =							projectq.MainEngine()

						# Generate a list of 10 random numbers
						__a           =							[get_random_number(quantum_engine) for _ in range(10)]

						# Flushes the quantum engine from memory
						quantum_engine.flush()

						print("Random numbers", random_numbers_list)
