


'''simple docstring'''




import unittest

import numpy as np

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


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import BlipImageProcessor



class 			lowerCAmelCase					(					unittest.TestCase				):



	def __init__(       self			,       snake_case__			,       snake_case__=7			,       snake_case__=3			,       snake_case__=18			,       snake_case__=30			,       snake_case__=400			,       snake_case__=True			,       snake_case__=None			,       snake_case__=True			,       snake_case__=False			,       snake_case__=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]			,       snake_case__=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]			,       snake_case__=True			,       ):
		lowerCAmelCase       :     List[str]   				=			size if size is not None else {'height': 20, 'width': 20}
		lowerCAmelCase       :     Dict   				=			parent
		lowerCAmelCase       :     List[str]   				=			batch_size
		lowerCAmelCase       :     Optional[Any]   				=			num_channels
		lowerCAmelCase       :     Dict   				=			image_size
		lowerCAmelCase       :     Dict   				=			min_resolution
		lowerCAmelCase       :     Optional[int]   				=			max_resolution
		lowerCAmelCase       :     Optional[Any]   				=			do_resize
		lowerCAmelCase       :     Union[str, Any]   				=			size
		lowerCAmelCase       :     Optional[Any]   				=			do_normalize
		lowerCAmelCase       :     Union[str, Any]   				=			image_mean
		lowerCAmelCase       :     Optional[Any]   				=			image_std
		lowerCAmelCase       :     List[str]   				=			do_pad
		lowerCAmelCase       :     Optional[int]   				=			do_convert_rgb



	def 					lowercase  (       self     ):
		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_convert_rgb": self.do_convert_rgb,
		    "do_pad": self.do_pad,
		}



	def 					lowercase  (       self			,       snake_case__=False			,       snake_case__=False			,       snake_case__=False     ):
		assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

		if equal_resolution:
			lowerCAmelCase       :     int   				=			[]
			for i in range(self.batch_size     ):
				image_inputs.append(
				    np.random.randint(
				        255			,       size=(self.num_channels, self.max_resolution, self.max_resolution)			,       dtype=np.uinta     )     )
		else:
			lowerCAmelCase       :     List[str]   				=			[]
			for i in range(self.batch_size     ):
				lowerCAmelCase				, lowerCAmelCase       :     Union[str, Any]   				=			np.random.choice(np.arange(self.min_resolution			,       self.max_resolution     )			,       2     )
				image_inputs.append(np.random.randint(255			,       size=(self.num_channels, width, height)			,       dtype=np.uinta     )     )

		if not numpify and not torchify:
			# PIL expects the channel dimension as last dimension
			lowerCAmelCase       :     List[str]   				=			[Image.fromarray(np.moveaxis(snake_case__			,       0			,       -1     )     ) for x in image_inputs]

		if torchify:
			lowerCAmelCase       :     Union[str, Any]   				=			[torch.from_numpy(snake_case__     ) for x in image_inputs]

		return image_inputs



@require_torch
@require_vision
class 			lowerCAmelCase					(					a   ,					unittest.TestCase				):
	_lowerCamelCase :       Optional[Any]         =			BlipImageProcessor if is_vision_available() else None



	def 					lowercase  (       self     ):
		lowerCAmelCase       :     Any   				=			BlipImageProcessingTester(self     )



	@property
	def 					lowercase  (       self     ):
		return self.image_processor_tester.prepare_image_processor_dict()



	def 					lowercase  (       self     ):
		lowerCAmelCase       :     List[Any]   				=			self.image_processing_class(**self.image_processor_dict     )
		self.assertTrue(hasattr(snake_case__			,       'do_resize'     )     )
		self.assertTrue(hasattr(snake_case__			,       'size'     )     )
		self.assertTrue(hasattr(snake_case__			,       'do_normalize'     )     )
		self.assertTrue(hasattr(snake_case__			,       'image_mean'     )     )
		self.assertTrue(hasattr(snake_case__			,       'image_std'     )     )
		self.assertTrue(hasattr(snake_case__			,       'do_convert_rgb'     )     )



	def 					lowercase  (       self     ):
		pass



	def 					lowercase  (       self     ):
		# Initialize image_processor
		lowerCAmelCase       :     Optional[int]   				=			self.image_processing_class(**self.image_processor_dict     )
		# create random PIL images
		lowerCAmelCase       :     str   				=			self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__     )
		for image in image_inputs:
			self.assertIsInstance(snake_case__			,       Image.Image     )

		# Test not batched input
		lowerCAmelCase       :     Dict   				=			image_processor(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
		lowerCAmelCase       :     Optional[Any]   				=			image_processor(snake_case__			,       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 					lowercase  (       self     ):
		# Initialize image_processor
		lowerCAmelCase       :     Optional[Any]   				=			self.image_processing_class(**self.image_processor_dict     )
		# create random numpy tensors
		lowerCAmelCase       :     Optional[Any]   				=			self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__			,       numpify=snake_case__     )
		for image in image_inputs:
			self.assertIsInstance(snake_case__			,       np.ndarray     )

		# Test not batched input
		lowerCAmelCase       :     Optional[Any]   				=			image_processor(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
		lowerCAmelCase       :     Optional[int]   				=			image_processor(snake_case__			,       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 					lowercase  (       self     ):
		# Initialize image_processor
		lowerCAmelCase       :     Any   				=			self.image_processing_class(**self.image_processor_dict     )
		# create random PyTorch tensors
		lowerCAmelCase       :     List[str]   				=			self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__			,       torchify=snake_case__     )
		for image in image_inputs:
			self.assertIsInstance(snake_case__			,       torch.Tensor     )

		# Test not batched input
		lowerCAmelCase       :     Tuple   				=			image_processor(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
		lowerCAmelCase       :     List[Any]   				=			image_processor(snake_case__			,       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'],
		    )			,       )



@require_torch
@require_vision
class 			lowerCAmelCase					(					a   ,					unittest.TestCase				):
	_lowerCamelCase :       Any         =			BlipImageProcessor if is_vision_available() else None



	def 					lowercase  (       self     ):
		lowerCAmelCase       :     Optional[Any]   				=			BlipImageProcessingTester(self			,       num_channels=4     )
		lowerCAmelCase       :     Any   				=			3



	@property
	def 					lowercase  (       self     ):
		return self.image_processor_tester.prepare_image_processor_dict()



	def 					lowercase  (       self     ):
		lowerCAmelCase       :     Union[str, Any]   				=			self.image_processing_class(**self.image_processor_dict     )
		self.assertTrue(hasattr(snake_case__			,       'do_resize'     )     )
		self.assertTrue(hasattr(snake_case__			,       'size'     )     )
		self.assertTrue(hasattr(snake_case__			,       'do_normalize'     )     )
		self.assertTrue(hasattr(snake_case__			,       'image_mean'     )     )
		self.assertTrue(hasattr(snake_case__			,       'image_std'     )     )
		self.assertTrue(hasattr(snake_case__			,       'do_convert_rgb'     )     )



	def 					lowercase  (       self     ):
		pass



	def 					lowercase  (       self     ):
		# Initialize image_processor
		lowerCAmelCase       :     int   				=			self.image_processing_class(**self.image_processor_dict     )
		# create random PIL images
		lowerCAmelCase       :     List[Any]   				=			self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__     )
		for image in image_inputs:
			self.assertIsInstance(snake_case__			,       Image.Image     )

		# Test not batched input
		lowerCAmelCase       :     Dict   				=			image_processor(image_inputs[0]			,       return_tensors='pt'     ).pixel_values
		self.assertEqual(
		    encoded_images.shape			,       (
		        1,
		        self.expected_encoded_image_num_channels,
		        self.image_processor_tester.size['height'],
		        self.image_processor_tester.size['width'],
		    )			,       )

		# Test batched
		lowerCAmelCase       :     Dict   				=			image_processor(snake_case__			,       return_tensors='pt'     ).pixel_values
		self.assertEqual(
		    encoded_images.shape			,       (
		        self.image_processor_tester.batch_size,
		        self.expected_encoded_image_num_channels,
		        self.image_processor_tester.size['height'],
		        self.image_processor_tester.size['width'],
		    )			,       )




'''simple docstring'''




class 			lowerCAmelCase					:



	def __init__(       self			,       snake_case__     ):
		lowerCAmelCase       :     Dict   				=			data
		lowerCAmelCase       :     Dict   				=			None
		lowerCAmelCase       :     Optional[int]   				=			None



	def __str__(       self     ):
		return f"{self.data}"



class 			lowerCAmelCase					:



	def __init__(       self     ):
		lowerCAmelCase       :     int   				=			None
		lowerCAmelCase       :     Dict   				=			None



	def __iter__(       self     ):
		lowerCAmelCase       :     Any   				=			self.head
		while node:
			yield node.data
			lowerCAmelCase       :     Tuple   				=			node.next



	def __str__(       self     ):
		return "->".join([str(snake_case__     ) for item in self]     )



	def __len__(       self     ):
		return sum(1 for _ in self     )



	def 					lowercase  (       self			,       snake_case__     ):
		self.insert_at_nth(0			,       snake_case__     )



	def 					lowercase  (       self			,       snake_case__     ):
		self.insert_at_nth(len(self     )			,       snake_case__     )



	def 					lowercase  (       self			,       snake_case__			,       snake_case__     ):
		lowerCAmelCase       :     Dict   				=			len(self     )

		if not 0 <= index <= length:
			raise IndexError('list index out of range'     )
		lowerCAmelCase       :     Dict   				=			Node(snake_case__     )
		if self.head is None:
			lowerCAmelCase       :     Any   				=			new_node
		elif index == 0:
			lowerCAmelCase       :     Dict   				=			new_node
			lowerCAmelCase       :     List[str]   				=			self.head
			lowerCAmelCase       :     Any   				=			new_node
		elif index == length:
			lowerCAmelCase       :     List[str]   				=			new_node
			lowerCAmelCase       :     int   				=			self.tail
			lowerCAmelCase       :     List[str]   				=			new_node
		else:
			lowerCAmelCase       :     Optional[Any]   				=			self.head
			for _ in range(0			,       snake_case__     ):
				lowerCAmelCase       :     Dict   				=			temp.next
			lowerCAmelCase       :     Tuple   				=			new_node
			lowerCAmelCase       :     Union[str, Any]   				=			temp.previous
			lowerCAmelCase       :     int   				=			temp
			lowerCAmelCase       :     Optional[int]   				=			new_node



	def 					lowercase  (       self     ):
		return self.delete_at_nth(0     )



	def 					lowercase  (       self     ):
		return self.delete_at_nth(len(self     ) - 1     )



	def 					lowercase  (       self			,       snake_case__     ):
		lowerCAmelCase       :     Optional[Any]   				=			len(self     )

		if not 0 <= index <= length - 1:
			raise IndexError('list index out of range'     )
		lowerCAmelCase       :     List[Any]   				=			self.head  # default first node
		if length == 1:
			lowerCAmelCase       :     int   				=			None
		elif index == 0:
			lowerCAmelCase       :     str   				=			self.head.next
			lowerCAmelCase       :     Dict   				=			None
		elif index == length - 1:
			lowerCAmelCase       :     int   				=			self.tail
			lowerCAmelCase       :     Dict   				=			self.tail.previous
			lowerCAmelCase       :     str   				=			None
		else:
			lowerCAmelCase       :     str   				=			self.head
			for _ in range(0			,       snake_case__     ):
				lowerCAmelCase       :     Dict   				=			temp.next
			lowerCAmelCase       :     Tuple   				=			temp
			lowerCAmelCase       :     List[str]   				=			temp.previous
			lowerCAmelCase       :     Tuple   				=			temp.next
		return delete_node.data



	def 					lowercase  (       self			,       snake_case__     ):
		lowerCAmelCase       :     Dict   				=			self.head

		while current.data != data:  # Find the position to delete
			if current.next:
				lowerCAmelCase       :     str   				=			current.next
			else:  # We have reached the end an no value matches
				raise ValueError('No data matching given value'     )

		if current == self.head:
			self.delete_head()

		elif current == self.tail:
			self.delete_tail()

		else:  # Before: 1 <--> 2(current) <--> 3
			lowerCAmelCase       :     Optional[Any]   				=			current.next  # 1 --> 3
			lowerCAmelCase       :     str   				=			current.previous  # 1 <--> 3
		return data



	def 					lowercase  (       self     ):
		return len(self     ) == 0


def       __UpperCamelCase     (     )     ->   None:




	"""simple docstring"""





	lowerCAmelCase       :     str   				=			DoublyLinkedList()
	assert linked_list.is_empty() is True
	assert str(_A					) == ""

	try:
		linked_list.delete_head()
		raise AssertionError  # This should not happen.
	except IndexError:
		assert True  # This should happen.

	try:
		linked_list.delete_tail()
		raise AssertionError  # This should not happen.
	except IndexError:
		assert True  # This should happen.

	for i in range(10					):
		assert len(_A					) == i
		linked_list.insert_at_nth(_A       , i + 1					)
	assert str(_A					) == "->".join(str(_A					) for i in range(1       , 11					)					)

	linked_list.insert_at_head(0					)
	linked_list.insert_at_tail(11					)
	assert str(_A					) == "->".join(str(_A					) for i in range(0       , 12					)					)

	assert linked_list.delete_head() == 0
	assert linked_list.delete_at_nth(9					) == 10
	assert linked_list.delete_tail() == 11
	assert len(_A					) == 9
	assert str(_A					) == "->".join(str(_A					) for i in range(1       , 10					)					)


if __name__ == "__main__":
				from doctest import testmod

				testmod()
