
'''simple docstring'''







import unittest

import numpy as np

from transformers.testing_utils import require_flax, require_tf, require_torch
from transformers.utils import (
    expand_dims,
    flatten_dict,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    reshape,
    squeeze,
    transpose,
)


if is_flax_available():
					import jax.numpy as jnp

if is_tf_available():
					import tensorflow as tf

if is_torch_available():
					import torch


class 		__UpperCAmelCase   (      unittest.TestCase		):


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	{
								    'task_specific_params': {
								        'summarization': {'length_penalty': 1.0, 'max_length': 1_28, 'min_length': 12, 'num_beams': 4},
								        'summarization_cnn': {'length_penalty': 2.0, 'max_length': 1_42, 'min_length': 56, 'num_beams': 4},
								        'summarization_xsum': {'length_penalty': 1.0, 'max_length': 62, 'min_length': 11, 'num_beams': 6},
								    }
								}
								_snake_case     		=	{
								    'task_specific_params.summarization.length_penalty': 1.0,
								    'task_specific_params.summarization.max_length': 1_28,
								    'task_specific_params.summarization.min_length': 12,
								    'task_specific_params.summarization.num_beams': 4,
								    'task_specific_params.summarization_cnn.length_penalty': 2.0,
								    'task_specific_params.summarization_cnn.max_length': 1_42,
								    'task_specific_params.summarization_cnn.min_length': 56,
								    'task_specific_params.summarization_cnn.num_beams': 4,
								    'task_specific_params.summarization_xsum.length_penalty': 1.0,
								    'task_specific_params.summarization_xsum.max_length': 62,
								    'task_specific_params.summarization_xsum.min_length': 11,
								    'task_specific_params.summarization_xsum.num_beams': 6,
								}

								self.assertEqual(flatten_dict(lowerCAmelCase_						)					,     lowerCAmelCase_						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								self.assertTrue(np.allclose(transpose(lowerCAmelCase_						)					,     x.transpose()						)						)

								_snake_case     		=	np.random.randn(3					,     4					,     5						)
								self.assertTrue(np.allclose(transpose(lowerCAmelCase_					,     axes=(1, 2, 0)						)					,     x.transpose((1, 2, 0)						)						)						)


							@require_torch
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								_snake_case     		=	torch.tensor(lowerCAmelCase_						)
								self.assertTrue(np.allclose(transpose(lowerCAmelCase_						)					,     transpose(lowerCAmelCase_						).numpy()						)						)

								_snake_case     		=	np.random.randn(3					,     4					,     5						)
								_snake_case     		=	torch.tensor(lowerCAmelCase_						)
								self.assertTrue(np.allclose(transpose(lowerCAmelCase_					,     axes=(1, 2, 0)						)					,     transpose(lowerCAmelCase_					,     axes=(1, 2, 0)						).numpy()						)						)


							@require_tf
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								_snake_case     		=	tf.constant(lowerCAmelCase_						)
								self.assertTrue(np.allclose(transpose(lowerCAmelCase_						)					,     transpose(lowerCAmelCase_						).numpy()						)						)

								_snake_case     		=	np.random.randn(3					,     4					,     5						)
								_snake_case     		=	tf.constant(lowerCAmelCase_						)
								self.assertTrue(np.allclose(transpose(lowerCAmelCase_					,     axes=(1, 2, 0)						)					,     transpose(lowerCAmelCase_					,     axes=(1, 2, 0)						).numpy()						)						)


							@require_flax
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								_snake_case     		=	jnp.array(lowerCAmelCase_						)
								self.assertTrue(np.allclose(transpose(lowerCAmelCase_						)					,     np.asarray(transpose(lowerCAmelCase_						)						)						)						)

								_snake_case     		=	np.random.randn(3					,     4					,     5						)
								_snake_case     		=	jnp.array(lowerCAmelCase_						)
								self.assertTrue(np.allclose(transpose(lowerCAmelCase_					,     axes=(1, 2, 0)						)					,     np.asarray(transpose(lowerCAmelCase_					,     axes=(1, 2, 0)						)						)						)						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								self.assertTrue(np.allclose(reshape(lowerCAmelCase_					,     (4, 3)						)					,     np.reshape(lowerCAmelCase_					,     (4, 3)						)						)						)

								_snake_case     		=	np.random.randn(3					,     4					,     5						)
								self.assertTrue(np.allclose(reshape(lowerCAmelCase_					,     (12, 5)						)					,     np.reshape(lowerCAmelCase_					,     (12, 5)						)						)						)


							@require_torch
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								_snake_case     		=	torch.tensor(lowerCAmelCase_						)
								self.assertTrue(np.allclose(reshape(lowerCAmelCase_					,     (4, 3)						)					,     reshape(lowerCAmelCase_					,     (4, 3)						).numpy()						)						)

								_snake_case     		=	np.random.randn(3					,     4					,     5						)
								_snake_case     		=	torch.tensor(lowerCAmelCase_						)
								self.assertTrue(np.allclose(reshape(lowerCAmelCase_					,     (12, 5)						)					,     reshape(lowerCAmelCase_					,     (12, 5)						).numpy()						)						)


							@require_tf
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								_snake_case     		=	tf.constant(lowerCAmelCase_						)
								self.assertTrue(np.allclose(reshape(lowerCAmelCase_					,     (4, 3)						)					,     reshape(lowerCAmelCase_					,     (4, 3)						).numpy()						)						)

								_snake_case     		=	np.random.randn(3					,     4					,     5						)
								_snake_case     		=	tf.constant(lowerCAmelCase_						)
								self.assertTrue(np.allclose(reshape(lowerCAmelCase_					,     (12, 5)						)					,     reshape(lowerCAmelCase_					,     (12, 5)						).numpy()						)						)


							@require_flax
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								_snake_case     		=	jnp.array(lowerCAmelCase_						)
								self.assertTrue(np.allclose(reshape(lowerCAmelCase_					,     (4, 3)						)					,     np.asarray(reshape(lowerCAmelCase_					,     (4, 3)						)						)						)						)

								_snake_case     		=	np.random.randn(3					,     4					,     5						)
								_snake_case     		=	jnp.array(lowerCAmelCase_						)
								self.assertTrue(np.allclose(reshape(lowerCAmelCase_					,     (12, 5)						)					,     np.asarray(reshape(lowerCAmelCase_					,     (12, 5)						)						)						)						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(1					,     3					,     4						)
								self.assertTrue(np.allclose(squeeze(lowerCAmelCase_						)					,     np.squeeze(lowerCAmelCase_						)						)						)

								_snake_case     		=	np.random.randn(1					,     4					,     1					,     5						)
								self.assertTrue(np.allclose(squeeze(lowerCAmelCase_					,     axis=2						)					,     np.squeeze(lowerCAmelCase_					,     axis=2						)						)						)


							@require_torch
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(1					,     3					,     4						)
								_snake_case     		=	torch.tensor(lowerCAmelCase_						)
								self.assertTrue(np.allclose(squeeze(lowerCAmelCase_						)					,     squeeze(lowerCAmelCase_						).numpy()						)						)

								_snake_case     		=	np.random.randn(1					,     4					,     1					,     5						)
								_snake_case     		=	torch.tensor(lowerCAmelCase_						)
								self.assertTrue(np.allclose(squeeze(lowerCAmelCase_					,     axis=2						)					,     squeeze(lowerCAmelCase_					,     axis=2						).numpy()						)						)


							@require_tf
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(1					,     3					,     4						)
								_snake_case     		=	tf.constant(lowerCAmelCase_						)
								self.assertTrue(np.allclose(squeeze(lowerCAmelCase_						)					,     squeeze(lowerCAmelCase_						).numpy()						)						)

								_snake_case     		=	np.random.randn(1					,     4					,     1					,     5						)
								_snake_case     		=	tf.constant(lowerCAmelCase_						)
								self.assertTrue(np.allclose(squeeze(lowerCAmelCase_					,     axis=2						)					,     squeeze(lowerCAmelCase_					,     axis=2						).numpy()						)						)


							@require_flax
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(1					,     3					,     4						)
								_snake_case     		=	jnp.array(lowerCAmelCase_						)
								self.assertTrue(np.allclose(squeeze(lowerCAmelCase_						)					,     np.asarray(squeeze(lowerCAmelCase_						)						)						)						)

								_snake_case     		=	np.random.randn(1					,     4					,     1					,     5						)
								_snake_case     		=	jnp.array(lowerCAmelCase_						)
								self.assertTrue(np.allclose(squeeze(lowerCAmelCase_					,     axis=2						)					,     np.asarray(squeeze(lowerCAmelCase_					,     axis=2						)						)						)						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								self.assertTrue(np.allclose(expand_dims(lowerCAmelCase_					,     axis=1						)					,     np.expand_dims(lowerCAmelCase_					,     axis=1						)						)						)


							@require_torch
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								_snake_case     		=	torch.tensor(lowerCAmelCase_						)
								self.assertTrue(np.allclose(expand_dims(lowerCAmelCase_					,     axis=1						)					,     expand_dims(lowerCAmelCase_					,     axis=1						).numpy()						)						)


							@require_tf
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								_snake_case     		=	tf.constant(lowerCAmelCase_						)
								self.assertTrue(np.allclose(expand_dims(lowerCAmelCase_					,     axis=1						)					,     expand_dims(lowerCAmelCase_					,     axis=1						).numpy()						)						)




							@require_flax
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	np.random.randn(3					,     4						)
								_snake_case     		=	jnp.array(lowerCAmelCase_						)
								self.assertTrue(np.allclose(expand_dims(lowerCAmelCase_					,     axis=1						)					,     np.asarray(expand_dims(lowerCAmelCase_					,     axis=1						)						)						)						)



'''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, prepare_image_inputs


if is_torch_available():
					import torch

if is_vision_available():
					from PIL import Image

					from transformers import GLPNImageProcessor


class 		__UpperCAmelCase   (      unittest.TestCase		):


							def __init__( self					,     lowerCAmelCase_					,     lowerCAmelCase_=7					,     lowerCAmelCase_=3					,     lowerCAmelCase_=18					,     lowerCAmelCase_=30					,     lowerCAmelCase_=4_00					,     lowerCAmelCase_=True					,     lowerCAmelCase_=32					,     lowerCAmelCase_=True					,     ):





								"""simple docstring"""






								_snake_case     		=	parent
								_snake_case     		=	batch_size
								_snake_case     		=	num_channels
								_snake_case     		=	image_size
								_snake_case     		=	min_resolution
								_snake_case     		=	max_resolution
								_snake_case     		=	do_resize
								_snake_case     		=	size_divisor
								_snake_case     		=	do_rescale




							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								return {
								    "do_resize": self.do_resize,
								    "size_divisor": self.size_divisor,
								    "do_rescale": self.do_rescale,
								}


@require_torch
@require_vision
class 		__UpperCAmelCase   (      _lowerCamelCase		,     unittest.TestCase		):
							__lowercase   	= GLPNImageProcessor if is_vision_available() else None


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	GLPNImageProcessingTester(self						)


							@property
							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								return self.image_processor_tester.prepare_image_processor_dict()


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	self.image_processing_class(**self.image_processor_dict						)
								self.assertTrue(hasattr(lowerCAmelCase_					,     'do_resize'						)						)
								self.assertTrue(hasattr(lowerCAmelCase_					,     'size_divisor'						)						)
								self.assertTrue(hasattr(lowerCAmelCase_					,     'resample'						)						)
								self.assertTrue(hasattr(lowerCAmelCase_					,     'do_rescale'						)						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								pass


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	self.image_processing_class(**self.image_processor_dict						)
								# create random PIL images
								_snake_case     		=	prepare_image_inputs(self.image_processor_tester					,     equal_resolution=lowerCAmelCase_						)
								for image in image_inputs:
									self.assertIsInstance(lowerCAmelCase_					,     Image.Image						)

								# Test not batched input (GLPNImageProcessor doesn't support batching)
								_snake_case     		=	image_processing(image_inputs[0]					,     return_tensors='pt'						).pixel_values
								self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0						)
								self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






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

								# Test not batched input (GLPNImageProcessor doesn't support batching)
								_snake_case     		=	image_processing(image_inputs[0]					,     return_tensors='pt'						).pixel_values
								self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0						)
								self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0						)




							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






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

								# Test not batched input (GLPNImageProcessor doesn't support batching)
								_snake_case     		=	image_processing(image_inputs[0]					,     return_tensors='pt'						).pixel_values
								self.assertTrue(encoded_images.shape[-1] % self.image_processor_tester.size_divisor == 0						)
								self.assertTrue(encoded_images.shape[-2] % self.image_processor_tester.size_divisor == 0						)

