




import unittest

import numpy as np
import PIL
import torch

from diffusers.image_processor import VaeImageProcessor





class 						SCREAMING_SNAKE_CASE__		(unittest.TestCase ):
     @property
     def 					A__			(	self  :		Optional[int]	):



       """simple docstring"""
       lowerCAmelCase__								=			1
       lowerCAmelCase__								=			3
       lowerCAmelCase__								=			8
       lowerCAmelCase__								=			8

       lowerCAmelCase__								=			torch.rand((batch_size, num_channels, height, width)	)

       return sample
     def 					A__			(	self  :		Any					,	__lowerCamelCase  :		Dict	):



       """simple docstring"""
       if isinstance(image[0]					,	PIL.Image.Image	):
         return np.stack([np.array(__lowerCamelCase	) for i in image]					,	axis=0	)
       elif isinstance(__lowerCamelCase					,	torch.Tensor	):
         return image.cpu().numpy().transpose(0					,	2					,	3					,	1	)
       return image
     def 					A__			(	self  :		List[Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			VaeImageProcessor(do_resize=__lowerCamelCase					,	do_normalize=__lowerCamelCase	)

       lowerCAmelCase__								=			self.dummy_sample
       lowerCAmelCase__								=			self.to_np(__lowerCamelCase	)

       for output_type in ["pt", "np", "pil"]:
         lowerCAmelCase__								=			image_processor.postprocess(
             image_processor.preprocess(__lowerCamelCase	)					,	output_type=__lowerCamelCase					,	)
         lowerCAmelCase__								=			self.to_np(__lowerCamelCase	)
         lowerCAmelCase__								=			(input_np * 2_55).round() if output_type == '''pil''' else input_np
         assert (
             np.abs(in_np - out_np	).max() < 1e-6
         ), F"""decoded output does not match input for output_type {output_type}"""
     def 					A__			(	self  :		Optional[Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			VaeImageProcessor(do_resize=__lowerCamelCase					,	do_normalize=__lowerCamelCase	)
       lowerCAmelCase__								=			self.dummy_sample.cpu().numpy().transpose(0					,	2					,	3					,	1	)

       for output_type in ["pt", "np", "pil"]:
         lowerCAmelCase__								=			image_processor.postprocess(image_processor.preprocess(__lowerCamelCase	)					,	output_type=__lowerCamelCase	)

         lowerCAmelCase__								=			self.to_np(__lowerCamelCase	)
         lowerCAmelCase__								=			(input_np * 2_55).round() if output_type == '''pil''' else input_np
         assert (
             np.abs(in_np - out_np	).max() < 1e-6
         ), F"""decoded output does not match input for output_type {output_type}"""
     def 					A__			(	self  :		Optional[int]	):



       """simple docstring"""
       lowerCAmelCase__								=			VaeImageProcessor(do_resize=__lowerCamelCase					,	do_normalize=__lowerCamelCase	)

       lowerCAmelCase__								=			self.dummy_sample.cpu().numpy().transpose(0					,	2					,	3					,	1	)
       lowerCAmelCase__								=			image_processor.numpy_to_pil(__lowerCamelCase	)

       for output_type in ["pt", "np", "pil"]:
         lowerCAmelCase__								=			image_processor.postprocess(image_processor.preprocess(__lowerCamelCase	)					,	output_type=__lowerCamelCase	)
         for i, o in zip(__lowerCamelCase					,	__lowerCamelCase	):
           lowerCAmelCase__								=			np.array(__lowerCamelCase	)
           lowerCAmelCase__								=			self.to_np(__lowerCamelCase	) if output_type == '''pil''' else (self.to_np(__lowerCamelCase	) * 2_55).round()
           assert (
               np.abs(in_np - out_np	).max() < 1e-6
           ), F"""decoded output does not match input for output_type {output_type}"""
     def 					A__			(	self  :		str	):



       """simple docstring"""
       lowerCAmelCase__								=			VaeImageProcessor(do_resize=__lowerCamelCase					,	do_normalize=__lowerCamelCase	)

       lowerCAmelCase__								=			self.dummy_sample
       lowerCAmelCase__								=			input_pt_ad.squeeze(0	)

       lowerCAmelCase__								=			image_processor.postprocess(
           image_processor.preprocess(__lowerCamelCase	)					,	output_type='''np'''					,	)
       lowerCAmelCase__								=			image_processor.postprocess(
           image_processor.preprocess(__lowerCamelCase	)					,	output_type='''np'''					,	)

       lowerCAmelCase__								=			self.to_np(self.dummy_sample	)
       lowerCAmelCase__								=			input_np_ad.squeeze(0	)

       lowerCAmelCase__								=			image_processor.postprocess(
           image_processor.preprocess(__lowerCamelCase	)					,	output_type='''np'''					,	)
       lowerCAmelCase__								=			image_processor.postprocess(
           image_processor.preprocess(__lowerCamelCase	)					,	output_type='''np'''					,	)

       assert np.abs(out_pt_ad - out_pt_ad	).max() < 1e-6
       assert np.abs(out_np_ad - out_np_ad	).max() < 1e-6



     def 					A__			(	self  :		Optional[int]	):



       """simple docstring"""
       lowerCAmelCase__								=			VaeImageProcessor(do_resize=__lowerCamelCase					,	do_normalize=__lowerCamelCase	)

       lowerCAmelCase__								=			self.dummy_sample
       lowerCAmelCase__								=			list(__lowerCamelCase	)

       lowerCAmelCase__								=			image_processor.postprocess(
           image_processor.preprocess(__lowerCamelCase	)					,	output_type='''np'''					,	)

       lowerCAmelCase__								=			image_processor.postprocess(
           image_processor.preprocess(__lowerCamelCase	)					,	output_type='''np'''					,	)

       lowerCAmelCase__								=			self.to_np(self.dummy_sample	)
       list(__lowerCamelCase	)

       lowerCAmelCase__								=			image_processor.postprocess(
           image_processor.preprocess(__lowerCamelCase	)					,	output_type='''np'''					,	)

       lowerCAmelCase__								=			image_processor.postprocess(
           image_processor.preprocess(__lowerCamelCase	)					,	output_type='''np'''					,	)

       assert np.abs(out_pt_ad - out_pt_list	).max() < 1e-6
       assert np.abs(out_np_ad - out_np_list	).max() < 1e-6







import os

from ...utils import logging
from .utils import DataProcessor, InputExample


__magic_name__     :     str  							=					logging.get_logger(__name__)





class 						SCREAMING_SNAKE_CASE__		(_a ):
     def __init__(	self  :		Any					,	__lowerCamelCase  :		Any					,	__lowerCamelCase  :		Optional[int]=None	):



       """simple docstring"""
       lowerCAmelCase__								=			language
       lowerCAmelCase__								=			train_language
     def 					A__			(	self  :		str					,	__lowerCamelCase  :		List[str]	):



       """simple docstring"""
       lowerCAmelCase__								=			self.language if self.train_language is None else self.train_language
       lowerCAmelCase__								=			self._read_tsv(os.path.join(__lowerCamelCase					,	F"""XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv"""	)	)
       lowerCAmelCase__								=			[]
       for i, line in enumerate(__lowerCamelCase	):
         if i == 0:
           continue
         lowerCAmelCase__								=			F"""train-{i}"""
         lowerCAmelCase__								=			line[0]
         lowerCAmelCase__								=			line[1]
         lowerCAmelCase__								=			'''contradiction''' if line[2] == '''contradictory''' else line[2]
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_a} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_b} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training label {label} is not a string"""	)
         examples.append(InputExample(guid=__lowerCamelCase					,	text_a=__lowerCamelCase					,	text_b=__lowerCamelCase					,	label=__lowerCamelCase	)	)
       return examples
     def 					A__			(	self  :		Dict					,	__lowerCamelCase  :		Union[str, Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			self._read_tsv(os.path.join(__lowerCamelCase					,	'''XNLI-1.0/xnli.test.tsv'''	)	)
       lowerCAmelCase__								=			[]
       for i, line in enumerate(__lowerCamelCase	):
         if i == 0:
           continue
         lowerCAmelCase__								=			line[0]
         if language != self.language:
           continue
         lowerCAmelCase__								=			F"""test-{i}"""
         lowerCAmelCase__								=			line[6]
         lowerCAmelCase__								=			line[7]
         lowerCAmelCase__								=			line[1]
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_a} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_b} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training label {label} is not a string"""	)
         examples.append(InputExample(guid=__lowerCamelCase					,	text_a=__lowerCamelCase					,	text_b=__lowerCamelCase					,	label=__lowerCamelCase	)	)
       return examples



     def 					A__			(	self  :		List[str]	):



       """simple docstring"""
       return ["contradiction", "entailment", "neutral"]



__magic_name__     :     Tuple  							=					{
    """xnli""": XnliProcessor,
}

__magic_name__     :     List[Any]  							=					{
    """xnli""": """classification""",
}

__magic_name__     :     str  							=					{
    """xnli""": 3,
}

