





import itertools
import random
import unittest

import numpy as np

from transformers import BatchFeature, SpeechTaFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
					import torch


A       :   List[Any]					= random.Random()







def   __lowerCamelCase   (				__a  :List[Any]       ,	__a  :int=1.0       ,	__a  :Optional[int]=None       ,	__a  :Any=None       )						->							Optional[int]:






		"""simple docstring"""

		if rng is None:
				A__     =  global_rng

		A__     =  []
		for batch_idx in range(shape[0]       ):
				values.append([]       )
				for _ in range(shape[1]       ):
						values[-1].append(rng.random() * scale       )

		return values


@require_torch
class     A     (unittest.TestCase       ):
			'''simple docstring'''




			def __init__(     self  :       Tuple				,      __lowerCAmelCase  :       Any				,      __lowerCAmelCase  :       List[Any]=7				,      __lowerCAmelCase  :       List[str]=4_00				,      __lowerCAmelCase  :       int=20_00				,      __lowerCAmelCase  :       str=1				,      __lowerCAmelCase  :       Optional[Any]=0.0				,      __lowerCAmelCase  :       int=1_60_00				,      __lowerCAmelCase  :       Any=True				,      __lowerCAmelCase  :       Union[str, Any]=80				,      __lowerCAmelCase  :       List[Any]=16				,      __lowerCAmelCase  :       Dict=64				,      __lowerCAmelCase  :       List[str]="hann_window"				,      __lowerCAmelCase  :       List[Any]=80				,      __lowerCAmelCase  :       Optional[Any]=76_00				,      __lowerCAmelCase  :       Optional[int]=1e-10				,      __lowerCAmelCase  :       Dict=True				,      )      ->      Tuple:







					"""simple docstring"""






					A__     =  parent
					A__     =  batch_size
					A__     =  min_seq_length
					A__     =  max_seq_length
					A__     =  (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
					A__     =  feature_size
					A__     =  padding_value
					A__     =  sampling_rate
					A__     =  do_normalize
					A__     =  num_mel_bins
					A__     =  hop_length
					A__     =  win_length
					A__     =  win_function
					A__     =  fmin
					A__     =  fmax
					A__     =  mel_floor
					A__     =  return_attention_mask






			def   a_			(     self  :       List[str]  )      ->      Tuple:







					"""simple docstring"""






					return {
					    "feature_size": self.feature_size,
					    "padding_value": self.padding_value,
					    "sampling_rate": self.sampling_rate,
					    "do_normalize": self.do_normalize,
					    "num_mel_bins": self.num_mel_bins,
					    "hop_length": self.hop_length,
					    "win_length": self.win_length,
					    "win_function": self.win_function,
					    "fmin": self.fmin,
					    "fmax": self.fmax,
					    "mel_floor": self.mel_floor,
					    "return_attention_mask": self.return_attention_mask,
					}






			def   a_			(     self  :       Union[str, Any]				,      __lowerCAmelCase  :       Optional[Any]=False				,      __lowerCAmelCase  :       str=False  )      ->      str:







					"""simple docstring"""






					def _flatten(__lowerCAmelCase  :       str  ):
							return list(itertools.chain(*__lowerCAmelCase  )  )

					if equal_length:
							A__     =  floats_list((self.batch_size, self.max_seq_length)  )
					else:
							# make sure that inputs increase in size
							A__     =  [
							    _flatten(floats_list((x, self.feature_size)  )  )
							    for x in range(self.min_seq_length				,      self.max_seq_length				,      self.seq_length_diff  )
							]

					if numpify:
							A__     =  [np.asarray(__lowerCAmelCase  ) for x in speech_inputs]

					return speech_inputs







			def   a_			(     self  :       List[str]				,      __lowerCAmelCase  :       List[Any]=False				,      __lowerCAmelCase  :       List[Any]=False  )      ->      str:







					"""simple docstring"""






					if equal_length:
							A__     =  [floats_list((self.max_seq_length, self.num_mel_bins)  ) for _ in range(self.batch_size  )]
					else:
							# make sure that inputs increase in size
							A__     =  [
							    floats_list((x, self.num_mel_bins)  )
							    for x in range(self.min_seq_length				,      self.max_seq_length				,      self.seq_length_diff  )
							]

					if numpify:
							A__     =  [np.asarray(__lowerCAmelCase  ) for x in speech_inputs]

					return speech_inputs


@require_torch
class     A     (SCREAMING_SNAKE_CASE  ,	unittest.TestCase       ):
			'''simple docstring'''




			__lowerCamelCase      :			Dict							     =       SpeechTaFeatureExtractor






			def   a_			(     self  :       List[str]  )      ->      Union[str, Any]:







					"""simple docstring"""






					A__     =  SpeechTaFeatureExtractionTester(self  )






			def   a_			(     self  :       Optional[Any]				,      __lowerCAmelCase  :       str  )      ->      List[str]:







					"""simple docstring"""






					self.assertTrue(np.all(np.mean(__lowerCAmelCase				,      axis=0  ) < 1e-3  )  )
					self.assertTrue(np.all(np.abs(np.var(__lowerCAmelCase				,      axis=0  ) - 1  ) < 1e-3  )  )






			def   a_			(     self  :       int  )      ->      Tuple:







					"""simple docstring"""






					A__     =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
					# create three inputs of length 800, 1000, and 1200
					A__     =  [floats_list((1, x)  )[0] for x in range(8_00				,      14_00				,      2_00  )]
					A__     =  [np.asarray(__lowerCAmelCase  ) for speech_input in speech_inputs]

					# Test not batched input
					A__     =  feat_extract(speech_inputs[0]				,      return_tensors="""np"""  ).input_values
					A__     =  feat_extract(np_speech_inputs[0]				,      return_tensors="""np"""  ).input_values
					self.assertTrue(np.allclose(__lowerCAmelCase				,      __lowerCAmelCase				,      atol=1e-3  )  )

					# Test batched
					A__     =  feat_extract(__lowerCAmelCase				,      return_tensors="""np"""  ).input_values
					A__     =  feat_extract(__lowerCAmelCase				,      return_tensors="""np"""  ).input_values
					for enc_seq_a, enc_seq_a in zip(__lowerCAmelCase				,      __lowerCAmelCase  ):
							self.assertTrue(np.allclose(__lowerCAmelCase				,      __lowerCAmelCase				,      atol=1e-3  )  )






			def   a_			(     self  :       List[Any]  )      ->      List[str]:







					"""simple docstring"""






					A__     =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
					A__     =  [floats_list((1, x)  )[0] for x in range(8_00				,      14_00				,      2_00  )]

					A__     =  ["""longest""", """max_length""", """do_not_pad"""]
					A__     =  [None, 16_00, None]
					for max_length, padding in zip(__lowerCAmelCase				,      __lowerCAmelCase  ):
							A__     =  feat_extract(__lowerCAmelCase				,      padding=__lowerCAmelCase				,      max_length=__lowerCAmelCase				,      return_tensors="""np"""  )
							A__     =  processed.input_values

							self._check_zero_mean_unit_variance(input_values[0][:8_00]  )
							self.assertTrue(input_values[0][8_00:].sum() < 1e-6  )
							self._check_zero_mean_unit_variance(input_values[1][:10_00]  )
							self.assertTrue(input_values[0][10_00:].sum() < 1e-6  )
							self._check_zero_mean_unit_variance(input_values[2][:12_00]  )






			def   a_			(     self  :       int  )      ->      Any:







					"""simple docstring"""






					A__     =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
					A__     =  range(8_00				,      14_00				,      2_00  )
					A__     =  [floats_list((1, x)  )[0] for x in lengths]

					A__     =  ["""longest""", """max_length""", """do_not_pad"""]
					A__     =  [None, 16_00, None]

					for max_length, padding in zip(__lowerCAmelCase				,      __lowerCAmelCase  ):
							A__     =  feat_extract(__lowerCAmelCase				,      max_length=__lowerCAmelCase				,      padding=__lowerCAmelCase  )
							A__     =  processed.input_values

							self._check_zero_mean_unit_variance(input_values[0][:8_00]  )
							self._check_zero_mean_unit_variance(input_values[1][:10_00]  )
							self._check_zero_mean_unit_variance(input_values[2][:12_00]  )






			def   a_			(     self  :       int  )      ->      str:







					"""simple docstring"""






					A__     =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
					A__     =  [floats_list((1, x)  )[0] for x in range(8_00				,      14_00				,      2_00  )]
					A__     =  feat_extract(
					    __lowerCAmelCase				,      truncation=__lowerCAmelCase				,      max_length=10_00				,      padding="""max_length"""				,      return_tensors="""np"""  )
					A__     =  processed.input_values

					self._check_zero_mean_unit_variance(input_values[0, :8_00]  )
					self._check_zero_mean_unit_variance(input_values[1]  )
					self._check_zero_mean_unit_variance(input_values[2]  )






			def   a_			(     self  :       Dict  )      ->      Tuple:







					"""simple docstring"""






					A__     =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
					A__     =  [floats_list((1, x)  )[0] for x in range(8_00				,      14_00				,      2_00  )]
					A__     =  feat_extract(
					    __lowerCAmelCase				,      truncation=__lowerCAmelCase				,      max_length=10_00				,      padding="""longest"""				,      return_tensors="""np"""  )
					A__     =  processed.input_values

					self._check_zero_mean_unit_variance(input_values[0, :8_00]  )
					self._check_zero_mean_unit_variance(input_values[1, :10_00]  )
					self._check_zero_mean_unit_variance(input_values[2]  )

					# make sure that if max_length < longest -> then pad to max_length
					self.assertTrue(input_values.shape == (3, 10_00)  )

					A__     =  [floats_list((1, x)  )[0] for x in range(8_00				,      14_00				,      2_00  )]
					A__     =  feat_extract(
					    __lowerCAmelCase				,      truncation=__lowerCAmelCase				,      max_length=20_00				,      padding="""longest"""				,      return_tensors="""np"""  )
					A__     =  processed.input_values

					self._check_zero_mean_unit_variance(input_values[0, :8_00]  )
					self._check_zero_mean_unit_variance(input_values[1, :10_00]  )
					self._check_zero_mean_unit_variance(input_values[2]  )

					# make sure that if max_length > longest -> then pad to longest
					self.assertTrue(input_values.shape == (3, 12_00)  )






			def   a_			(     self  :       str  )      ->      Any:







					"""simple docstring"""






					A__     =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
					A__     =  np.random.rand(1_00  ).astype(np.floataa  )
					A__     =  np_speech_inputs.tolist()

					for inputs in [py_speech_inputs, np_speech_inputs]:
							A__     =  feature_extractor.pad([{"""input_values""": inputs}]				,      return_tensors="""np"""  )
							self.assertTrue(np_processed.input_values.dtype == np.floataa  )
							A__     =  feature_extractor.pad([{"""input_values""": inputs}]				,      return_tensors="""pt"""  )
							self.assertTrue(pt_processed.input_values.dtype == torch.floataa  )






			def   a_			(     self  :       Dict  )      ->      List[str]:







					"""simple docstring"""






					A__     =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()  )
					# create three inputs of length 800, 1000, and 1200
					A__     =  [floats_list((1, x)  )[0] for x in range(8_00				,      14_00				,      2_00  )]
					A__     =  [np.asarray(__lowerCAmelCase  ) for speech_input in speech_inputs]

					# Test feature size
					A__     =  feature_extractor(audio_target=__lowerCAmelCase				,      padding=__lowerCAmelCase				,      return_tensors="""np"""  ).input_values
					self.assertTrue(input_values.ndim == 3  )
					self.assertTrue(input_values.shape[-1] == feature_extractor.num_mel_bins  )

					# Test not batched input
					A__     =  feature_extractor(speech_inputs[0]				,      return_tensors="""np"""  ).input_values
					A__     =  feature_extractor(np_speech_inputs[0]				,      return_tensors="""np"""  ).input_values
					self.assertTrue(np.allclose(__lowerCAmelCase				,      __lowerCAmelCase				,      atol=1e-3  )  )

					# Test batched
					A__     =  feature_extractor(__lowerCAmelCase				,      return_tensors="""np"""  ).input_values
					A__     =  feature_extractor(__lowerCAmelCase				,      return_tensors="""np"""  ).input_values
					for enc_seq_a, enc_seq_a in zip(__lowerCAmelCase				,      __lowerCAmelCase  ):
							self.assertTrue(np.allclose(__lowerCAmelCase				,      __lowerCAmelCase				,      atol=1e-3  )  )

					# Test 2-D numpy arrays are batched.
					A__     =  [floats_list((1, x)  )[0] for x in (8_00, 8_00, 8_00)]
					A__     =  np.asarray(__lowerCAmelCase  )
					A__     =  feature_extractor(__lowerCAmelCase				,      return_tensors="""np"""  ).input_values
					A__     =  feature_extractor(__lowerCAmelCase				,      return_tensors="""np"""  ).input_values
					for enc_seq_a, enc_seq_a in zip(__lowerCAmelCase				,      __lowerCAmelCase  ):
							self.assertTrue(np.allclose(__lowerCAmelCase				,      __lowerCAmelCase				,      atol=1e-3  )  )






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







					"""simple docstring"""






					A__     =  self.feat_extract_tester.prepare_inputs_for_target()
					A__     =  self.feature_extraction_class(**self.feat_extract_dict  )
					A__     =  feat_extract.model_input_names[0]

					A__     =  BatchFeature({input_name: speech_inputs}  )

					self.assertTrue(all(len(__lowerCAmelCase  ) == len(__lowerCAmelCase  ) for x, y in zip(__lowerCAmelCase				,      processed_features[input_name]  )  )  )

					A__     =  self.feat_extract_tester.prepare_inputs_for_target(equal_length=__lowerCAmelCase  )
					A__     =  BatchFeature({input_name: speech_inputs}				,      tensor_type="""np"""  )

					A__     =  processed_features[input_name]

					if len(batch_features_input.shape  ) < 3:
							A__     =  batch_features_input[:, :, None]

					self.assertTrue(
					    batch_features_input.shape
					    == (self.feat_extract_tester.batch_size, len(speech_inputs[0]  ), self.feat_extract_tester.num_mel_bins)  )






			@require_torch
			def   a_			(     self  :       Union[str, Any]  )      ->      Optional[int]:







					"""simple docstring"""






					A__     =  self.feat_extract_tester.prepare_inputs_for_target(equal_length=__lowerCAmelCase  )
					A__     =  self.feature_extraction_class(**self.feat_extract_dict  )
					A__     =  feat_extract.model_input_names[0]

					A__     =  BatchFeature({input_name: speech_inputs}				,      tensor_type="""pt"""  )

					A__     =  processed_features[input_name]

					if len(batch_features_input.shape  ) < 3:
							A__     =  batch_features_input[:, :, None]

					self.assertTrue(
					    batch_features_input.shape
					    == (self.feat_extract_tester.batch_size, len(speech_inputs[0]  ), self.feat_extract_tester.num_mel_bins)  )






			@require_torch
			def   a_			(     self  :       Any  )      ->      Dict:







					"""simple docstring"""






					A__     =  self.feature_extraction_class(**self.feat_extract_dict  )
					A__     =  self.feat_extract_tester.prepare_inputs_for_target()
					A__     =  feat_extract.model_input_names[0]

					A__     =  BatchFeature({input_name: speech_inputs}  )

					A__     =  feat_extract.num_mel_bins  # hack!

					A__     =  feat_extract.pad(__lowerCAmelCase				,      padding="""longest"""				,      return_tensors="""np"""  )[input_name]
					A__     =  feat_extract.pad(__lowerCAmelCase				,      padding="""longest"""				,      return_tensors="""pt"""  )[input_name]

					self.assertTrue(abs(input_np.astype(np.floataa  ).sum() - input_pt.numpy().astype(np.floataa  ).sum()  ) < 1e-2  )






			def   a_			(     self  :       Union[str, Any]  )      ->      Optional[Any]:







					"""simple docstring"""






					A__     =  self.feat_extract_dict
					A__     =  True
					A__     =  self.feature_extraction_class(**__lowerCAmelCase  )
					A__     =  self.feat_extract_tester.prepare_inputs_for_target()
					A__     =  [len(__lowerCAmelCase  ) for x in speech_inputs]
					A__     =  feat_extract.model_input_names[0]

					A__     =  BatchFeature({input_name: speech_inputs}  )

					A__     =  feat_extract.num_mel_bins  # hack!

					A__     =  feat_extract.pad(__lowerCAmelCase				,      padding="""longest"""				,      return_tensors="""np"""  )
					self.assertIn("""attention_mask"""				,      __lowerCAmelCase  )
					self.assertListEqual(list(processed.attention_mask.shape  )				,      list(processed[input_name].shape[:2]  )  )
					self.assertListEqual(processed.attention_mask.sum(-1  ).tolist()				,      __lowerCAmelCase  )






			def   a_			(     self  :       Optional[Any]  )      ->      Tuple:







					"""simple docstring"""






					A__     =  self.feat_extract_dict
					A__     =  True
					A__     =  self.feature_extraction_class(**__lowerCAmelCase  )
					A__     =  self.feat_extract_tester.prepare_inputs_for_target()
					A__     =  [len(__lowerCAmelCase  ) for x in speech_inputs]
					A__     =  feat_extract.model_input_names[0]

					A__     =  BatchFeature({input_name: speech_inputs}  )
					A__     =  min(__lowerCAmelCase  )

					A__     =  feat_extract.num_mel_bins  # hack!

					A__     =  feat_extract.pad(
					    __lowerCAmelCase				,      padding="""max_length"""				,      max_length=__lowerCAmelCase				,      truncation=__lowerCAmelCase				,      return_tensors="""np"""  )
					self.assertIn("""attention_mask"""				,      __lowerCAmelCase  )
					self.assertListEqual(
					    list(processed_pad.attention_mask.shape  )				,      [processed_pad[input_name].shape[0], max_length]  )
					self.assertListEqual(
					    processed_pad.attention_mask[:, :max_length].sum(-1  ).tolist()				,      [max_length for x in speech_inputs]  )






			def   a_			(     self  :       Dict				,      __lowerCAmelCase  :       List[Any]  )      ->      List[Any]:







					"""simple docstring"""






					from datasets import load_dataset

					A__     =  load_dataset("""hf-internal-testing/librispeech_asr_dummy"""				,      """clean"""				,      split="""validation"""  )
					# automatic decoding with librispeech
					A__     =  ds.sort("""id"""  ).select(range(__lowerCAmelCase  )  )[:num_samples]["""audio"""]

					return [x["array"] for x in speech_samples]






			def   a_			(     self  :       Tuple  )      ->      Union[str, Any]:







					"""simple docstring"""






					A__     =  torch.tensor(
					    [2.3_804e-03, 2.0_752e-03, 1.9_836e-03, 2.1_057e-03, 1.6_174e-03,
					     3.0_518e-04, 9.1_553e-05, 3.3_569e-04, 9.7_656e-04, 1.8_311e-03,
					     2.0_142e-03, 2.1_057e-03, 1.7_395e-03, 4.5_776e-04, -3.9_673e-04,
					     4.5_776e-04, 1.0_071e-03, 9.1_553e-05, 4.8_828e-04, 1.1_597e-03,
					     7.3_242e-04, 9.4_604e-04, 1.8_005e-03, 1.8_311e-03, 8.8_501e-04,
					     4.2_725e-04, 4.8_828e-04, 7.3_242e-04, 1.0_986e-03, 2.1_057e-03]  )
					# fmt: on

					A__     =  self._load_datasamples(1  )
					A__     =  SpeechTaFeatureExtractor()
					A__     =  feature_extractor(__lowerCAmelCase				,      return_tensors="""pt"""  ).input_values
					self.assertEquals(input_values.shape				,      (1, 9_36_80)  )
					self.assertTrue(torch.allclose(input_values[0, :30]				,      __lowerCAmelCase				,      atol=1e-6  )  )







			def   a_			(     self  :       Any  )      ->      List[str]:







					"""simple docstring"""






					A__     =  torch.tensor(
					    [-2.6_8_7_0, -3.0_1_0_4, -3.1_3_5_6, -3.5_3_5_2, -3.0_0_4_4, -3.0_3_5_3, -3.4_7_1_9, -3.6_7_7_7,
					     -3.1_5_2_0, -2.9_4_3_5, -2.6_5_5_3, -2.8_7_9_5, -2.9_9_4_4, -2.5_9_2_1, -3.0_2_7_9, -3.0_3_8_6,
					     -3.0_8_6_4, -3.1_2_9_1, -3.2_3_5_3, -2.7_4_4_4, -2.6_8_3_1, -2.7_2_8_7, -3.1_7_6_1, -3.1_5_7_1,
					     -3.2_7_2_6, -3.0_5_8_2, -3.1_0_0_7, -3.4_5_3_3, -3.4_6_9_5, -3.0_9_9_8]  )
					# fmt: on

					A__     =  self._load_datasamples(1  )
					A__     =  SpeechTaFeatureExtractor()
					A__     =  feature_extractor(audio_target=__lowerCAmelCase				,      return_tensors="""pt"""  ).input_values
					self.assertEquals(input_values.shape				,      (1, 3_66, 80)  )
					self.assertTrue(torch.allclose(input_values[0, 0, :30]				,      __lowerCAmelCase				,      atol=1e-4  )  )










import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import IMAGE_PROCESSOR_NAME, is_vision_available


if is_vision_available():
					from PIL import Image

					from transformers import CLIPImageProcessor, CLIPProcessor


@require_vision
class     A     (unittest.TestCase       ):
			'''simple docstring'''




			def   a_			(     self  :       Optional[int]  )      ->      Dict:







					"""simple docstring"""






					A__     =  tempfile.mkdtemp()

					# fmt: off
					A__     =  ["""l""", """o""", """w""", """e""", """r""", """s""", """t""", """i""", """d""", """n""", """lo""", """l</w>""", """w</w>""", """r</w>""", """t</w>""", """low</w>""", """er</w>""", """lowest</w>""", """newer</w>""", """wider""", """<unk>""", """<|startoftext|>""", """<|endoftext|>"""]
					# fmt: on
					A__     =  dict(zip(__lowerCAmelCase				,      range(len(__lowerCAmelCase  )  )  )  )
					A__     =  ["""#version: 0.2""", """l o""", """lo w</w>""", """e r</w>""", """"""]
					A__     =  {"""unk_token""": """<unk>"""}

					A__     =  os.path.join(self.tmpdirname				,      VOCAB_FILES_NAMES["""vocab_file"""]  )
					A__     =  os.path.join(self.tmpdirname				,      VOCAB_FILES_NAMES["""merges_file"""]  )
					with open(self.vocab_file				,      """w"""				,      encoding="""utf-8"""  ) as fp:
							fp.write(json.dumps(__lowerCAmelCase  ) + """\n"""  )
					with open(self.merges_file				,      """w"""				,      encoding="""utf-8"""  ) as fp:
							fp.write("""\n""".join(__lowerCAmelCase  )  )

					A__     =  {
					    """do_resize""": True,
					    """size""": 20,
					    """do_center_crop""": True,
					    """crop_size""": 18,
					    """do_normalize""": True,
					    """image_mean""": [0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3],
					    """image_std""": [0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1],
					}
					A__     =  os.path.join(self.tmpdirname				,      __lowerCAmelCase  )
					with open(self.image_processor_file				,      """w"""				,      encoding="""utf-8"""  ) as fp:
							json.dump(__lowerCAmelCase				,      __lowerCAmelCase  )






			def   a_			(     self  :       str				,      **__lowerCAmelCase  :       Optional[int]  )      ->      str:







					"""simple docstring"""






					return CLIPTokenizer.from_pretrained(self.tmpdirname				,      **__lowerCAmelCase  )






			def   a_			(     self  :       Dict				,      **__lowerCAmelCase  :       List[Any]  )      ->      Optional[int]:







					"""simple docstring"""






					return CLIPTokenizerFast.from_pretrained(self.tmpdirname				,      **__lowerCAmelCase  )






			def   a_			(     self  :       List[Any]				,      **__lowerCAmelCase  :       List[Any]  )      ->      Tuple:







					"""simple docstring"""






					return CLIPImageProcessor.from_pretrained(self.tmpdirname				,      **__lowerCAmelCase  )






			def   a_			(     self  :       Optional[Any]  )      ->      str:







					"""simple docstring"""






					shutil.rmtree(self.tmpdirname  )






			def   a_			(     self  :       int  )      ->      Tuple:







					"""simple docstring"""






					A__     =  [np.random.randint(2_55				,      size=(3, 30, 4_00)				,      dtype=np.uinta  )]

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

					return image_inputs






			def   a_			(     self  :       List[str]  )      ->      Optional[int]:







					"""simple docstring"""






					A__     =  self.get_tokenizer()
					A__     =  self.get_rust_tokenizer()
					A__     =  self.get_image_processor()

					A__     =  CLIPProcessor(tokenizer=__lowerCAmelCase				,      image_processor=__lowerCAmelCase  )
					processor_slow.save_pretrained(self.tmpdirname  )
					A__     =  CLIPProcessor.from_pretrained(self.tmpdirname				,      use_fast=__lowerCAmelCase  )

					A__     =  CLIPProcessor(tokenizer=__lowerCAmelCase				,      image_processor=__lowerCAmelCase  )
					processor_fast.save_pretrained(self.tmpdirname  )
					A__     =  CLIPProcessor.from_pretrained(self.tmpdirname  )

					self.assertEqual(processor_slow.tokenizer.get_vocab()				,      tokenizer_slow.get_vocab()  )
					self.assertEqual(processor_fast.tokenizer.get_vocab()				,      tokenizer_fast.get_vocab()  )
					self.assertEqual(tokenizer_slow.get_vocab()				,      tokenizer_fast.get_vocab()  )
					self.assertIsInstance(processor_slow.tokenizer				,      __lowerCAmelCase  )
					self.assertIsInstance(processor_fast.tokenizer				,      __lowerCAmelCase  )

					self.assertEqual(processor_slow.image_processor.to_json_string()				,      image_processor.to_json_string()  )
					self.assertEqual(processor_fast.image_processor.to_json_string()				,      image_processor.to_json_string()  )
					self.assertIsInstance(processor_slow.image_processor				,      __lowerCAmelCase  )
					self.assertIsInstance(processor_fast.image_processor				,      __lowerCAmelCase  )






			def   a_			(     self  :       int  )      ->      Any:







					"""simple docstring"""






					A__     =  CLIPProcessor(tokenizer=self.get_tokenizer()				,      image_processor=self.get_image_processor()  )
					processor.save_pretrained(self.tmpdirname  )

					A__     =  self.get_tokenizer(bos_token="""(BOS)"""				,      eos_token="""(EOS)"""  )
					A__     =  self.get_image_processor(do_normalize=__lowerCAmelCase				,      padding_value=1.0  )

					A__     =  CLIPProcessor.from_pretrained(
					    self.tmpdirname				,      bos_token="""(BOS)"""				,      eos_token="""(EOS)"""				,      do_normalize=__lowerCAmelCase				,      padding_value=1.0  )

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

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






			def   a_			(     self  :       List[Any]  )      ->      Union[str, Any]:







					"""simple docstring"""






					A__     =  self.get_image_processor()
					A__     =  self.get_tokenizer()

					A__     =  CLIPProcessor(tokenizer=__lowerCAmelCase				,      image_processor=__lowerCAmelCase  )

					A__     =  self.prepare_image_inputs()

					A__     =  image_processor(__lowerCAmelCase				,      return_tensors="""np"""  )
					A__     =  processor(images=__lowerCAmelCase				,      return_tensors="""np"""  )

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






			def   a_			(     self  :       Union[str, Any]  )      ->      Tuple:







					"""simple docstring"""






					A__     =  self.get_image_processor()
					A__     =  self.get_tokenizer()

					A__     =  CLIPProcessor(tokenizer=__lowerCAmelCase				,      image_processor=__lowerCAmelCase  )

					A__     =  """lower newer"""

					A__     =  processor(text=__lowerCAmelCase  )

					A__     =  tokenizer(__lowerCAmelCase  )

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






			def   a_			(     self  :       str  )      ->      Optional[Any]:







					"""simple docstring"""






					A__     =  self.get_image_processor()
					A__     =  self.get_tokenizer()

					A__     =  CLIPProcessor(tokenizer=__lowerCAmelCase				,      image_processor=__lowerCAmelCase  )

					A__     =  """lower newer"""
					A__     =  self.prepare_image_inputs()

					A__     =  processor(text=__lowerCAmelCase				,      images=__lowerCAmelCase  )

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

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






			def   a_			(     self  :       Optional[int]  )      ->      Tuple:







					"""simple docstring"""






					A__     =  self.get_image_processor()
					A__     =  self.get_tokenizer()

					A__     =  CLIPProcessor(tokenizer=__lowerCAmelCase				,      image_processor=__lowerCAmelCase  )

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

					A__     =  processor.batch_decode(__lowerCAmelCase  )
					A__     =  tokenizer.batch_decode(__lowerCAmelCase  )

					self.assertListEqual(__lowerCAmelCase				,      __lowerCAmelCase  )







			def   a_			(     self  :       Dict  )      ->      str:







					"""simple docstring"""






					A__     =  self.get_image_processor()
					A__     =  self.get_tokenizer()

					A__     =  CLIPProcessor(tokenizer=__lowerCAmelCase				,      image_processor=__lowerCAmelCase  )

					A__     =  """lower newer"""
					A__     =  self.prepare_image_inputs()

					A__     =  processor(text=__lowerCAmelCase				,      images=__lowerCAmelCase  )

					self.assertListEqual(list(inputs.keys()  )				,      processor.model_input_names  )



