
'''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 ChineseCLIPImageProcessor




class   UpperCAmelCase_					(		unittest.TestCase			):






						'''simple docstring'''






						def __init__( self   ,       _lowercase   ,       _lowercase=7   ,       _lowercase=3   ,       _lowercase=18   ,       _lowercase=30   ,       _lowercase=400   ,       _lowercase=True   ,       _lowercase=None   ,       _lowercase=True   ,       _lowercase=None   ,       _lowercase=True   ,       _lowercase=[0.4814_5466, 0.457_8275, 0.4082_1073]   ,       _lowercase=[0.2686_2954, 0.2613_0258, 0.2757_7711]   ,       _lowercase=True   ,       ):

												"""simple docstring"""



												_lowerCAmelCase  						=			size if size is not None else {"""height""": 224, """width""": 224}
												_lowerCAmelCase  						=			crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
												_lowerCAmelCase  						=			parent
												_lowerCAmelCase  						=			batch_size
												_lowerCAmelCase  						=			num_channels
												_lowerCAmelCase  						=			image_size
												_lowerCAmelCase  						=			min_resolution
												_lowerCAmelCase  						=			max_resolution
												_lowerCAmelCase  						=			do_resize
												_lowerCAmelCase  						=			size
												_lowerCAmelCase  						=			do_center_crop
												_lowerCAmelCase  						=			crop_size
												_lowerCAmelCase  						=			do_normalize
												_lowerCAmelCase  						=			image_mean
												_lowerCAmelCase  						=			image_std
												_lowerCAmelCase  						=			do_convert_rgb




						def  _lowercase     ( self				):

												"""simple docstring"""



												return {
												    "do_resize": self.do_resize,
												    "size": self.size,
												    "do_center_crop": self.do_center_crop,
												    "crop_size": self.crop_size,
												    "do_normalize": self.do_normalize,
												    "image_mean": self.image_mean,
												    "image_std": self.image_std,
												    "do_convert_rgb": self.do_convert_rgb,
												}




						def  _lowercase     ( self   ,       _lowercase=False   ,       _lowercase=False   ,       _lowercase=False				):

												"""simple docstring"""



												assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

												if equal_resolution:
																		_lowerCAmelCase  						=			[]
																		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  						=			[]
																		for i in range(self.batch_size				):
																								_lowerCAmelCase						,   _lowerCAmelCase  						=			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  						=			[Image.fromarray(np.moveaxis(_lowercase   ,       0   ,       -1				)				) for x in image_inputs]

												if torchify:
																		_lowerCAmelCase  						=			[torch.from_numpy(_lowercase				) for x in image_inputs]

												return image_inputs






@require_torch
@require_vision
class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE	,							unittest.TestCase			):






						'''simple docstring'''






						_lowercase		:				Optional[int]									=       ChineseCLIPImageProcessor if is_vision_available() else None




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			ChineseCLIPImageProcessingTester(self   ,       do_center_crop=_lowercase				)




						@property
						def  _lowercase     ( self				):

												"""simple docstring"""



												return self.image_processor_tester.prepare_image_processor_dict()




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.image_processing_class(**self.image_processor_dict				)
												self.assertTrue(hasattr(_lowercase   ,       """do_resize"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """size"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """do_center_crop"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """center_crop"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """do_normalize"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """image_mean"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """image_std"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """do_convert_rgb"""				)				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.image_processing_class.from_dict(self.image_processor_dict				)
												self.assertEqual(image_processor.size   ,       {"""height""": 224, """width""": 224}				)
												self.assertEqual(image_processor.crop_size   ,       {"""height""": 18, """width""": 18}				)

												_lowerCAmelCase  						=			self.image_processing_class.from_dict(self.image_processor_dict   ,       size=42   ,       crop_size=84				)
												self.assertEqual(image_processor.size   ,       {"""shortest_edge""": 42}				)
												self.assertEqual(image_processor.crop_size   ,       {"""height""": 84, """width""": 84}				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												pass




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.image_processing_class(**self.image_processor_dict				)
												# create random PIL images
												_lowerCAmelCase  						=			self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase				)
												for image in image_inputs:
																		self.assertIsInstance(_lowercase   ,       Image.Image				)

												# Test not batched input
												_lowerCAmelCase  						=			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.crop_size["""height"""],
												        self.image_processor_tester.crop_size["""width"""],
												    )   ,       )

												# Test batched
												_lowerCAmelCase  						=			image_processing(_lowercase   ,       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.crop_size["""height"""],
												        self.image_processor_tester.crop_size["""width"""],
												    )   ,       )




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.image_processing_class(**self.image_processor_dict				)
												# create random numpy tensors
												_lowerCAmelCase  						=			self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase   ,       numpify=_lowercase				)
												for image in image_inputs:
																		self.assertIsInstance(_lowercase   ,       np.ndarray				)

												# Test not batched input
												_lowerCAmelCase  						=			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.crop_size["""height"""],
												        self.image_processor_tester.crop_size["""width"""],
												    )   ,       )

												# Test batched
												_lowerCAmelCase  						=			image_processing(_lowercase   ,       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.crop_size["""height"""],
												        self.image_processor_tester.crop_size["""width"""],
												    )   ,       )




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.image_processing_class(**self.image_processor_dict				)
												# create random PyTorch tensors
												_lowerCAmelCase  						=			self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase   ,       torchify=_lowercase				)
												for image in image_inputs:
																		self.assertIsInstance(_lowercase   ,       torch.Tensor				)

												# Test not batched input
												_lowerCAmelCase  						=			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.crop_size["""height"""],
												        self.image_processor_tester.crop_size["""width"""],
												    )   ,       )

												# Test batched
												_lowerCAmelCase  						=			image_processing(_lowercase   ,       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.crop_size["""height"""],
												        self.image_processor_tester.crop_size["""width"""],
												    )   ,       )






@require_torch
@require_vision
class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE	,							unittest.TestCase			):






						'''simple docstring'''






						_lowercase		:				Union[str, Any]									=       ChineseCLIPImageProcessor if is_vision_available() else None




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			ChineseCLIPImageProcessingTester(self   ,       num_channels=4   ,       do_center_crop=_lowercase				)
												_lowerCAmelCase  						=			3




						@property
						def  _lowercase     ( self				):

												"""simple docstring"""



												return self.image_processor_tester.prepare_image_processor_dict()




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.image_processing_class(**self.image_processor_dict				)
												self.assertTrue(hasattr(_lowercase   ,       """do_resize"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """size"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """do_center_crop"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """center_crop"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """do_normalize"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """image_mean"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """image_std"""				)				)
												self.assertTrue(hasattr(_lowercase   ,       """do_convert_rgb"""				)				)




						def  _lowercase     ( self				):

												"""simple docstring"""



												pass




						def  _lowercase     ( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self.image_processing_class(**self.image_processor_dict				)
												# create random PIL images
												_lowerCAmelCase  						=			self.image_processor_tester.prepare_inputs(equal_resolution=_lowercase				)
												for image in image_inputs:
																		self.assertIsInstance(_lowercase   ,       Image.Image				)

												# Test not batched input
												_lowerCAmelCase  						=			image_processing(image_inputs[0]   ,       return_tensors="""pt"""				).pixel_values
												self.assertEqual(
												    encoded_images.shape   ,       (
												        1,
												        self.expected_encoded_image_num_channels,
												        self.image_processor_tester.crop_size["""height"""],
												        self.image_processor_tester.crop_size["""width"""],
												    )   ,       )

												# Test batched
												_lowerCAmelCase  						=			image_processing(_lowercase   ,       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.crop_size["""height"""],
												        self.image_processor_tester.crop_size["""width"""],
												    )   ,       )


'''simple docstring'''



from __future__ import annotations

from typing import Any




class   UpperCAmelCase_					(		_SCREAMING_SNAKE_CASE			):






						'''simple docstring'''






						pass






class   UpperCAmelCase_					:






						'''simple docstring'''






						def __init__( self   ,       _lowercase				):

												"""simple docstring"""



												_lowerCAmelCase  						=			data
												_lowerCAmelCase  						=			None




						def __iter__( self				):

												"""simple docstring"""



												_lowerCAmelCase  						=			self
												_lowerCAmelCase  						=			[]
												while node:
																		if node in visited:
																								raise ContainsLoopError
																		visited.append(_lowercase				)
																		yield node.data
																		_lowerCAmelCase  						=			node.next_node




						@property
						def  _lowercase     ( self				):

												"""simple docstring"""



												try:
																		list(self				)
																		return False
												except ContainsLoopError:
																		return True


if __name__ == "__main__":
						_lowercase    =		Node(1)
						_lowercase    =		Node(2)
						_lowercase    =		Node(3)
						_lowercase    =		Node(4)
						print(root_node.has_loop)  # False
						_lowercase    =		root_node.next_node
						print(root_node.has_loop)  # True

						_lowercase    =		Node(5)
						_lowercase    =		Node(6)
						_lowercase    =		Node(5)
						_lowercase    =		Node(6)
						print(root_node.has_loop)  # False

						_lowercase    =		Node(1)
						print(root_node.has_loop)  # False
