




'''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,						lowerCAmelCase,						lowerCAmelCase=7,						lowerCAmelCase=3,						lowerCAmelCase=18,						lowerCAmelCase=30,						lowerCAmelCase=400,						lowerCAmelCase=True,						lowerCAmelCase=None,						lowerCAmelCase=True,						lowerCAmelCase=False,						lowerCAmelCase=True,						lowerCAmelCase=True,						lowerCAmelCase=[0.5, 0.5, 0.5],						lowerCAmelCase=[0.5, 0.5, 0.5],						):



              """simple docstring"""







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






       def 	lowercase__	(				self    ):



              """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      :       Union[str, Any] 		=DonutImageProcessor if is_vision_available() else None






       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=DonutImageProcessingTester(self    )






       @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(lowerCAmelCase,						'''do_resize'''    )    )
              self.assertTrue(hasattr(lowerCAmelCase,						'''size'''    )    )
              self.assertTrue(hasattr(lowerCAmelCase,						'''do_thumbnail'''    )    )
              self.assertTrue(hasattr(lowerCAmelCase,						'''do_align_long_axis'''    )    )
              self.assertTrue(hasattr(lowerCAmelCase,						'''do_pad'''    )    )
              self.assertTrue(hasattr(lowerCAmelCase,						'''do_normalize'''    )    )
              self.assertTrue(hasattr(lowerCAmelCase,						'''image_mean'''    )    )
              self.assertTrue(hasattr(lowerCAmelCase,						'''image_std'''    )    )






       def 	lowercase__	(				self    ):



              """simple docstring"""







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

              lowerCamelCase_				=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
              lowerCamelCase_				=self.image_processing_class.from_dict(self.image_processor_dict,						size=(42, 84)    )
              self.assertEqual(image_processor.size,						{'''height''': 84, '''width''': 42}    )






       def 	lowercase__	(				self    ):



              """simple docstring"""







              pass






       @is_flaky()
       def 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.image_processing_class(**self.image_processor_dict    )
              # create random PIL images
              lowerCamelCase_				=prepare_image_inputs(self.image_processor_tester,						equal_resolution=lowerCAmelCase    )
              for image in image_inputs:
                     self.assertIsInstance(lowerCAmelCase,						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.size['''height'''],
                      self.image_processor_tester.size['''width'''],
                  ),						)

              # Test batched
              lowerCamelCase_				=image_processing(lowerCAmelCase,						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 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.image_processing_class(**self.image_processor_dict    )
              # create random numpy tensors
              lowerCamelCase_				=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
              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.size['''height'''],
                      self.image_processor_tester.size['''width'''],
                  ),						)

              # Test batched
              lowerCamelCase_				=image_processing(lowerCAmelCase,						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 	lowercase__	(				self    ):



              """simple docstring"""







              lowerCamelCase_				=self.image_processing_class(**self.image_processor_dict    )
              # create random PyTorch tensors
              lowerCamelCase_				=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
              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.size['''height'''],
                      self.image_processor_tester.size['''width'''],
                  ),						)

              # Test batched
              lowerCamelCase_				=image_processing(lowerCAmelCase,						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'''







# Lint as: python3
# pylint: enable=line-too-long
# pylint: disable=g-import-not-at-top,g-bad-import-order,wrong-import-position

lowerCAmelCase_     						=				'''2.13.1'''

import platform

import pyarrow
from packaging import version


if version.parse(platform.python_version()) < version.parse('''3.7'''):
    raise ImportWarning(
        '''To use `datasets`, Python>=3.7 is required, and the current version of Python doesn\'t match this condition.'''
    )

if version.parse(pyarrow.__version__).major < 8:
    raise ImportWarning(
        '''To use `datasets`, the module `pyarrow>=8.0.0` is required, and the current version of `pyarrow` doesn\'t match this condition.\n'''
        '''If you are running this in a Google Colab, you should probably just restart the runtime to use the right version of `pyarrow`.'''
    )

del platform
del pyarrow
del version

from .arrow_dataset import Dataset
from .arrow_reader import ReadInstruction
from .builder import ArrowBasedBuilder, BeamBasedBuilder, BuilderConfig, DatasetBuilder, GeneratorBasedBuilder
from .combine import concatenate_datasets, interleave_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .download import *
from .features import *
from .fingerprint import disable_caching, enable_caching, is_caching_enabled, set_caching_enabled
from .info import DatasetInfo, MetricInfo
from .inspect import (
    get_dataset_config_info,
    get_dataset_config_names,
    get_dataset_infos,
    get_dataset_split_names,
    inspect_dataset,
    inspect_metric,
    list_datasets,
    list_metrics,
)
from .iterable_dataset import IterableDataset
from .load import load_dataset, load_dataset_builder, load_from_disk, load_metric
from .metric import Metric
from .splits import (
    NamedSplit,
    NamedSplitAll,
    Split,
    SplitBase,
    SplitDict,
    SplitGenerator,
    SplitInfo,
    SubSplitInfo,
    percent,
)
from .tasks import *
from .utils import *
from .utils import logging


# deprecated modules
from datasets import arrow_dataset as _arrow_dataset  # isort:skip
from datasets import utils as _utils  # isort:skip
from datasets.utils import download_manager as _deprecated_download_manager  # isort:skip

lowerCAmelCase_     						=				concatenate_datasets
lowerCAmelCase_     						=				DownloadConfig
lowerCAmelCase_     						=				DownloadManager
lowerCAmelCase_     						=				DownloadMode
lowerCAmelCase_     						=				DownloadConfig
lowerCAmelCase_     						=				DownloadMode
lowerCAmelCase_     						=				DownloadManager

del _arrow_dataset, _utils, _deprecated_download_manager


