
"""simple docstring"""




def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round((float(SCREAMING_SNAKE_CASE_      ) * 9 / 5) + 3_2,					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round(float(SCREAMING_SNAKE_CASE_      ) + 273.15,					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round((float(SCREAMING_SNAKE_CASE_      ) * 9 / 5) + 491.67,					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round((float(SCREAMING_SNAKE_CASE_      ) - 3_2) * 5 / 9,					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round(((float(SCREAMING_SNAKE_CASE_      ) - 3_2) * 5 / 9) + 273.15,					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round(float(SCREAMING_SNAKE_CASE_      ) + 459.67,					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round(float(SCREAMING_SNAKE_CASE_      ) - 273.15,					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round(((float(SCREAMING_SNAKE_CASE_      ) - 273.15) * 9 / 5) + 3_2,					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round((float(SCREAMING_SNAKE_CASE_      ) * 9 / 5),					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round((float(SCREAMING_SNAKE_CASE_      ) - 491.67) * 5 / 9,					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round(float(SCREAMING_SNAKE_CASE_      ) - 459.67,					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round((float(SCREAMING_SNAKE_CASE_      ) * 5 / 9),					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round((float(SCREAMING_SNAKE_CASE_      ) * 1.25 + 273.15),					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round((float(SCREAMING_SNAKE_CASE_      ) * 2.25 + 3_2),					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round((float(SCREAMING_SNAKE_CASE_      ) * 1.25),					SCREAMING_SNAKE_CASE_      )

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_,					SCREAMING_SNAKE_CASE_ = 2      ):
     return round((float(SCREAMING_SNAKE_CASE_      ) * 2.25 + 3_2 + 459.67),					SCREAMING_SNAKE_CASE_      )


if __name__ == "__main__":
 import doctest

 doctest.testmod()


"""simple docstring"""




import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available


if is_torch_available():
	from transformers.pytorch_utils import is_torch_greater_or_equal_than_1_11
else:
	snake_case			       =		False

if is_vision_available():
	from PIL import Image

	from transformers import (
	    AutoProcessor,
	    PixaStructImageProcessor,
	    PixaStructProcessor,
	    PreTrainedTokenizerFast,
	    TaTokenizer,
	)




@unittest.skipIf(
    not is_torch_greater_or_equal_than_1_11  ,				reason="`Pix2StructImageProcessor` requires `torch>=1.11.0`."  ,				)
@require_vision
@require_torch
class 					UpperCamelCase     (	unittest.TestCase				):

				"""simple docstring"""



				def 							A (    self      )   ->   Any:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =     tempfile.mkdtemp()

									SCREAMING_SNAKE_CASE           =     PixaStructImageProcessor()
									SCREAMING_SNAKE_CASE           =     TaTokenizer.from_pretrained('t5-small'      )

									SCREAMING_SNAKE_CASE           =     PixaStructProcessor(lowercase__		,     lowercase__      )

									processor.save_pretrained(self.tmpdirname      )


				def 							A (    self		,     **lowercase__      )   ->   Dict:
									"""simple docstring"""







									return AutoProcessor.from_pretrained(self.tmpdirname		,     **lowercase__      ).tokenizer


				def 							A (    self		,     **lowercase__      )   ->   Union[str, Any]:
									"""simple docstring"""







									return AutoProcessor.from_pretrained(self.tmpdirname		,     **lowercase__      ).image_processor


				def 							A (    self      )   ->   Optional[int]:
									"""simple docstring"""







									shutil.rmtree(self.tmpdirname      )


				def 							A (    self      )   ->   int:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =     [np.random.randint(255		,     size=(3, 30, 400)		,     dtype=np.uinta      )]

									SCREAMING_SNAKE_CASE           =     [Image.fromarray(np.moveaxis(lowercase__		,     0		,     -1      )      ) for x in image_inputs]

									return image_inputs


				def 							A (    self      )   ->   int:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =     PixaStructProcessor(tokenizer=self.get_tokenizer()		,     image_processor=self.get_image_processor()      )
									processor.save_pretrained(self.tmpdirname      )

									SCREAMING_SNAKE_CASE           =     self.get_tokenizer(bos_token='(BOS)'		,     eos_token='(EOS)'      )
									SCREAMING_SNAKE_CASE           =     self.get_image_processor(do_normalize=lowercase__		,     padding_value=1.0      )

									SCREAMING_SNAKE_CASE           =     PixaStructProcessor.from_pretrained(
									    self.tmpdirname		,     bos_token='(BOS)'		,     eos_token='(EOS)'		,     do_normalize=lowercase__		,     padding_value=1.0      )

									self.assertEqual(processor.tokenizer.get_vocab()		,     tokenizer_add_kwargs.get_vocab()      )
									self.assertIsInstance(processor.tokenizer		,     lowercase__      )

									self.assertEqual(processor.image_processor.to_json_string()		,     image_processor_add_kwargs.to_json_string()      )
									self.assertIsInstance(processor.image_processor		,     lowercase__      )


				def 							A (    self      )   ->   int:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =     self.get_image_processor()
									SCREAMING_SNAKE_CASE           =     self.get_tokenizer()

									SCREAMING_SNAKE_CASE           =     PixaStructProcessor(tokenizer=lowercase__		,     image_processor=lowercase__      )

									SCREAMING_SNAKE_CASE           =     self.prepare_image_inputs()

									SCREAMING_SNAKE_CASE           =     image_processor(lowercase__		,     return_tensors='np'      )
									SCREAMING_SNAKE_CASE           =     processor(images=lowercase__		,     return_tensors='np'      )

									for key in input_feat_extract.keys():
														self.assertAlmostEqual(input_feat_extract[key].sum()		,     input_processor[key].sum()		,     delta=1E-2      )


				def 							A (    self      )   ->   List[Any]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =     self.get_image_processor()
									SCREAMING_SNAKE_CASE           =     self.get_tokenizer()

									SCREAMING_SNAKE_CASE           =     PixaStructProcessor(tokenizer=lowercase__		,     image_processor=lowercase__      )

									SCREAMING_SNAKE_CASE           =     'lower newer'

									SCREAMING_SNAKE_CASE           =     processor(text=lowercase__      )

									SCREAMING_SNAKE_CASE           =     tokenizer(lowercase__		,     return_token_type_ids=lowercase__		,     add_special_tokens=lowercase__      )

									for key in encoded_tok.keys():
														self.assertListEqual(encoded_tok[key]		,     encoded_processor[key]      )


				def 							A (    self      )   ->   List[Any]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =     self.get_image_processor()
									SCREAMING_SNAKE_CASE           =     self.get_tokenizer()

									SCREAMING_SNAKE_CASE           =     PixaStructProcessor(tokenizer=lowercase__		,     image_processor=lowercase__      )

									SCREAMING_SNAKE_CASE           =     'lower newer'
									SCREAMING_SNAKE_CASE           =     self.prepare_image_inputs()

									SCREAMING_SNAKE_CASE           =     processor(text=lowercase__		,     images=lowercase__      )

									self.assertListEqual(
									    list(inputs.keys()      )		,     ['flattened_patches', 'attention_mask', 'decoder_attention_mask', 'decoder_input_ids']      )

									# test if it raises when no input is passed
									with pytest.raises(lowercase__      ):
														processor()


				def 							A (    self      )   ->   Union[str, Any]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =     self.get_image_processor()
									SCREAMING_SNAKE_CASE           =     self.get_tokenizer()

									SCREAMING_SNAKE_CASE           =     PixaStructProcessor(tokenizer=lowercase__		,     image_processor=lowercase__      )

									SCREAMING_SNAKE_CASE           =     'lower newer'
									SCREAMING_SNAKE_CASE           =     self.prepare_image_inputs()

									SCREAMING_SNAKE_CASE           =     processor(text=lowercase__		,     images=lowercase__      )

									SCREAMING_SNAKE_CASE           =     [512, 1024, 2048, 4096]
									SCREAMING_SNAKE_CASE           =     [770, 770, 770, 770]
									# with text
									for i, max_patch in enumerate(lowercase__      ):
														SCREAMING_SNAKE_CASE           =     processor(text=lowercase__		,     images=lowercase__		,     max_patches=lowercase__      )
														self.assertEqual(inputs['flattened_patches'][0].shape[0]		,     lowercase__      )
														self.assertEqual(inputs['flattened_patches'][0].shape[1]		,     expected_hidden_size[i]      )

									# without text input
									for i, max_patch in enumerate(lowercase__      ):
														SCREAMING_SNAKE_CASE           =     processor(images=lowercase__		,     max_patches=lowercase__      )
														self.assertEqual(inputs['flattened_patches'][0].shape[0]		,     lowercase__      )
														self.assertEqual(inputs['flattened_patches'][0].shape[1]		,     expected_hidden_size[i]      )


				def 							A (    self      )   ->   Tuple:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =     self.get_image_processor()
									SCREAMING_SNAKE_CASE           =     self.get_tokenizer()

									SCREAMING_SNAKE_CASE           =     PixaStructProcessor(tokenizer=lowercase__		,     image_processor=lowercase__      )

									SCREAMING_SNAKE_CASE           =     [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

									SCREAMING_SNAKE_CASE           =     processor.batch_decode(lowercase__      )
									SCREAMING_SNAKE_CASE           =     tokenizer.batch_decode(lowercase__      )

									self.assertListEqual(lowercase__		,     lowercase__      )




				def 							A (    self      )   ->   Optional[Any]:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE           =     self.get_image_processor()
									SCREAMING_SNAKE_CASE           =     self.get_tokenizer()

									SCREAMING_SNAKE_CASE           =     PixaStructProcessor(tokenizer=lowercase__		,     image_processor=lowercase__      )

									SCREAMING_SNAKE_CASE           =     'lower newer'
									SCREAMING_SNAKE_CASE           =     self.prepare_image_inputs()

									SCREAMING_SNAKE_CASE           =     processor(text=lowercase__		,     images=lowercase__      )

									# For now the processor supports only ["flattened_patches", "input_ids", "attention_mask", "decoder_attention_mask"]
									self.assertListEqual(
									    list(inputs.keys()      )		,     ['flattened_patches', 'attention_mask', 'decoder_attention_mask', 'decoder_input_ids']      )

									SCREAMING_SNAKE_CASE           =     processor(text=lowercase__      )

									# For now the processor supports only ["flattened_patches", "input_ids", "attention_mask", "decoder_attention_mask"]
									self.assertListEqual(list(inputs.keys()      )		,     ['input_ids', 'attention_mask']      )
