


'''simple docstring'''




import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers.testing_utils import require_vision
from transformers.utils import is_vision_available


if is_vision_available():
    from PIL import Image

    from transformers import AutoProcessor, BertTokenizer, BlipImageProcessor, BlipProcessor, PreTrainedTokenizerFast






@require_vision
class UpperCAmelCase							(		unittest.TestCase							):



    def 					__lowerCamelCase						(  self					):
     __UpperCAmelCase					=   tempfile.mkdtemp()

     __UpperCAmelCase					=   BlipImageProcessor()
     __UpperCAmelCase					=   BertTokenizer.from_pretrained('hf-internal-testing/tiny-random-BertModel'					)

     __UpperCAmelCase					=   BlipProcessor(UpperCamelCase__     ,			UpperCamelCase__					)

     processor.save_pretrained(self.tmpdirname					)



    def 					__lowerCamelCase						(  self     ,			**__A					):
     return AutoProcessor.from_pretrained(self.tmpdirname     ,			**UpperCamelCase__					).tokenizer



    def 					__lowerCamelCase						(  self     ,			**__A					):
     return AutoProcessor.from_pretrained(self.tmpdirname     ,			**UpperCamelCase__					).image_processor



    def 					__lowerCamelCase						(  self					):
     shutil.rmtree(self.tmpdirname					)



    def 					__lowerCamelCase						(  self					):
     __UpperCAmelCase					=   [np.random.randint(255     ,			size=(3, 30, 400)     ,			dtype=np.uinta					)]

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

     return image_inputs



    def 					__lowerCamelCase						(  self					):
     __UpperCAmelCase					=   BlipProcessor(tokenizer=self.get_tokenizer()     ,			image_processor=self.get_image_processor()					)
     processor.save_pretrained(self.tmpdirname					)

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

     __UpperCAmelCase					=   BlipProcessor.from_pretrained(
         self.tmpdirname     ,			bos_token='(BOS)'     ,			eos_token='(EOS)'     ,			do_normalize=UpperCamelCase__     ,			padding_value=1.0					)

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

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



    def 					__lowerCamelCase						(  self					):
     __UpperCAmelCase					=   self.get_image_processor()
     __UpperCAmelCase					=   self.get_tokenizer()

     __UpperCAmelCase					=   BlipProcessor(tokenizer=UpperCamelCase__     ,			image_processor=UpperCamelCase__					)

     __UpperCAmelCase					=   self.prepare_image_inputs()

     __UpperCAmelCase					=   image_processor(UpperCamelCase__     ,			return_tensors='np'					)
     __UpperCAmelCase					=   processor(images=UpperCamelCase__     ,			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 					__lowerCamelCase						(  self					):
     __UpperCAmelCase					=   self.get_image_processor()
     __UpperCAmelCase					=   self.get_tokenizer()

     __UpperCAmelCase					=   BlipProcessor(tokenizer=UpperCamelCase__     ,			image_processor=UpperCamelCase__					)

     __UpperCAmelCase					=   'lower newer'

     __UpperCAmelCase					=   processor(text=UpperCamelCase__					)

     __UpperCAmelCase					=   tokenizer(UpperCamelCase__     ,			return_token_type_ids=UpperCamelCase__					)

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



    def 					__lowerCamelCase						(  self					):
     __UpperCAmelCase					=   self.get_image_processor()
     __UpperCAmelCase					=   self.get_tokenizer()

     __UpperCAmelCase					=   BlipProcessor(tokenizer=UpperCamelCase__     ,			image_processor=UpperCamelCase__					)

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

     __UpperCAmelCase					=   processor(text=UpperCamelCase__     ,			images=UpperCamelCase__					)

     self.assertListEqual(list(inputs.keys()					)     ,			['pixel_values', 'input_ids', 'attention_mask']					)

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



    def 					__lowerCamelCase						(  self					):
     __UpperCAmelCase					=   self.get_image_processor()
     __UpperCAmelCase					=   self.get_tokenizer()

     __UpperCAmelCase					=   BlipProcessor(tokenizer=UpperCamelCase__     ,			image_processor=UpperCamelCase__					)

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

     __UpperCAmelCase					=   processor.batch_decode(UpperCamelCase__					)
     __UpperCAmelCase					=   tokenizer.batch_decode(UpperCamelCase__					)

     self.assertListEqual(UpperCamelCase__     ,			UpperCamelCase__					)




    def 					__lowerCamelCase						(  self					):
     __UpperCAmelCase					=   self.get_image_processor()
     __UpperCAmelCase					=   self.get_tokenizer()

     __UpperCAmelCase					=   BlipProcessor(tokenizer=UpperCamelCase__     ,			image_processor=UpperCamelCase__					)

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

     __UpperCAmelCase					=   processor(text=UpperCamelCase__     ,			images=UpperCamelCase__					)

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












'''simple docstring'''




from __future__ import annotations







def _lowerCAmelCase     (      _lowerCAmelCase       ,    _lowerCAmelCase       ,    _lowerCAmelCase       ,    )->     tuple:
 if (electron_conc, hole_conc, intrinsic_conc).count(0    ) != 1:
  raise ValueError('You cannot supply more or less than 2 values'    )
 elif electron_conc < 0:
  raise ValueError('Electron concentration cannot be negative in a semiconductor'    )
 elif hole_conc < 0:
  raise ValueError('Hole concentration cannot be negative in a semiconductor'    )
 elif intrinsic_conc < 0:
  raise ValueError(
      'Intrinsic concentration cannot be negative in a semiconductor'    )
 elif electron_conc == 0:
  return (
      "electron_conc",
      intrinsic_conc**2 / hole_conc,
  )
 elif hole_conc == 0:
  return (
      "hole_conc",
      intrinsic_conc**2 / electron_conc,
  )
 elif intrinsic_conc == 0:
  return (
      "intrinsic_conc",
      (electron_conc * hole_conc) ** 0.5,
  )
 else:
  return (-1, -1)


if __name__ == "__main__":
    import doctest

    doctest.testmod()





