
"""simple docstring"""





import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor






class     _UpperCAmelCase(    unittest.TestCase	):



		def __init__(					self				,		__a				,		__a=7				,		__a=3				,		__a=18				,		__a=30				,		__a=4_00				,		__a=True				,		__a=None				,		__a=True				,		__a=False				,		__a=True				,		__a=True				,		__a=[0.5, 0.5, 0.5]				,		__a=[0.5, 0.5, 0.5]				,		)       ->       Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase							 =  parent
							_UpperCamelCase							 =  batch_size
							_UpperCamelCase							 =  num_channels
							_UpperCamelCase							 =  image_size
							_UpperCamelCase							 =  min_resolution
							_UpperCamelCase							 =  max_resolution
							_UpperCamelCase							 =  do_resize
							_UpperCamelCase							 =  size if size is not None else {'''height''': 18, '''width''': 20}
							_UpperCamelCase							 =  do_thumbnail
							_UpperCamelCase							 =  do_align_axis
							_UpperCamelCase							 =  do_pad
							_UpperCamelCase							 =  do_normalize
							_UpperCamelCase							 =  image_mean
							_UpperCamelCase							 =  image_std




		def 						UpperCAmelCase							(					self)       ->       Any:






							'''simple docstring'''
							return {
							    "do_resize": self.do_resize,
							    "size": self.size,
							    "do_thumbnail": self.do_thumbnail,
							    "do_align_long_axis": self.do_align_axis,
							    "do_pad": self.do_pad,
							    "do_normalize": self.do_normalize,
							    "image_mean": self.image_mean,
							    "image_std": self.image_std,
							}






@require_torch
@require_vision
class     _UpperCAmelCase(    lowerCamelCase      ,     unittest.TestCase	):
		lowercase__						=      DonutImageProcessor if is_vision_available() else None



		def 						UpperCAmelCase							(					self)       ->       Dict:






							'''simple docstring'''
							_UpperCamelCase							 =  DonutImageProcessingTester(self)



		@property
		def 						UpperCAmelCase							(					self)       ->       List[str]:






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



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






							'''simple docstring'''
							_UpperCamelCase							 =  self.image_processing_class(**self.image_processor_dict)
							self.assertTrue(hasattr(__a				,		'''do_resize'''))
							self.assertTrue(hasattr(__a				,		'''size'''))
							self.assertTrue(hasattr(__a				,		'''do_thumbnail'''))
							self.assertTrue(hasattr(__a				,		'''do_align_long_axis'''))
							self.assertTrue(hasattr(__a				,		'''do_pad'''))
							self.assertTrue(hasattr(__a				,		'''do_normalize'''))
							self.assertTrue(hasattr(__a				,		'''image_mean'''))
							self.assertTrue(hasattr(__a				,		'''image_std'''))



		def 						UpperCAmelCase							(					self)       ->       Optional[Any]:






							'''simple docstring'''
							_UpperCamelCase							 =  self.image_processing_class.from_dict(self.image_processor_dict)
							self.assertEqual(image_processor.size				,		{'''height''': 18, '''width''': 20})

							_UpperCamelCase							 =  self.image_processing_class.from_dict(self.image_processor_dict				,		size=42)
							self.assertEqual(image_processor.size				,		{'''height''': 42, '''width''': 42})

							# Previous config had dimensions in (width, height) order
							_UpperCamelCase							 =  self.image_processing_class.from_dict(self.image_processor_dict				,		size=(42, 84))
							self.assertEqual(image_processor.size				,		{'''height''': 84, '''width''': 42})



		def 						UpperCAmelCase							(					self)       ->       Any:






							'''simple docstring'''
							pass



		@is_flaky()
		def 						UpperCAmelCase							(					self)       ->       List[Any]:






							'''simple docstring'''
							# Initialize image_processing
							_UpperCamelCase							 =  self.image_processing_class(**self.image_processor_dict)
							# create random PIL images
							_UpperCamelCase							 =  prepare_image_inputs(self.image_processor_tester				,		equal_resolution=__a)
							for image in image_inputs:
												self.assertIsInstance(__a				,		Image.Image)

							# Test not batched input
							_UpperCamelCase							 =  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							 =  image_processing(__a				,		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'''],
							    )				,		)



		@is_flaky()
		def 						UpperCAmelCase							(					self)       ->       List[Any]:






							'''simple docstring'''
							# Initialize image_processing
							_UpperCamelCase							 =  self.image_processing_class(**self.image_processor_dict)
							# create random numpy tensors
							_UpperCamelCase							 =  prepare_image_inputs(self.image_processor_tester				,		equal_resolution=__a				,		numpify=__a)
							for image in image_inputs:
												self.assertIsInstance(__a				,		np.ndarray)

							# Test not batched input
							_UpperCamelCase							 =  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							 =  image_processing(__a				,		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'''],
							    )				,		)




		@is_flaky()
		def 						UpperCAmelCase							(					self)       ->       int:






							'''simple docstring'''
							# Initialize image_processing
							_UpperCamelCase							 =  self.image_processing_class(**self.image_processor_dict)
							# create random PyTorch tensors
							_UpperCamelCase							 =  prepare_image_inputs(self.image_processor_tester				,		equal_resolution=__a				,		torchify=__a)
							for image in image_inputs:
												self.assertIsInstance(__a				,		torch.Tensor)

							# Test not batched input
							_UpperCamelCase							 =  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							 =  image_processing(__a				,		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'''],
							    )				,		)








"""simple docstring"""





import datasets


_a														=		"""\
@InProceedings{conneau2018xnli,
  author = \"Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin\",
  title = \"XNLI: Evaluating Cross-lingual Sentence Representations\",
  booktitle = \"Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing\",
  year = \"2018\",
  publisher = \"Association for Computational Linguistics\",
  location = \"Brussels, Belgium\",
}
"""

_a														=		"""\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
"""

_a														=		"""
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    'accuracy': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric(\"xnli\")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}
"""



def       lowerCamelCase__		(			__snake_case,     __snake_case	)							->		str:


					"""simple docstring"""





					return (preds == labels).mean()






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION      ,     _KWARGS_DESCRIPTION	)
class     _UpperCAmelCase(    datasets.Metric	):



		def 						UpperCAmelCase							(					self)       ->       Dict:






							'''simple docstring'''
							return datasets.MetricInfo(
							    description=_DESCRIPTION				,		citation=_CITATION				,		inputs_description=_KWARGS_DESCRIPTION				,		features=datasets.Features(
							        {
							            '''predictions''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''),
							            '''references''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''),
							        })				,		codebase_urls=[]				,		reference_urls=[]				,		format='''numpy'''				,		)




		def 						UpperCAmelCase							(					self				,		__a				,		__a)       ->       Dict:






							'''simple docstring'''
							return {"accuracy": simple_accuracy(__a				,		__a)}






