

"""simple docstring"""




import warnings
from collections.abc import Callable
from typing import Any

import numpy
from matplotlib import pyplot

__A	:       List[Any]        =						0.25 + 0.0J
__A	:       Tuple        =						-0.4 + 0.6J
__A	:       List[Any]        =						-0.1 + 0.651J
__A	:       Union[str, Any]        =						-2.0
__A	:       Dict        =						56
__A	:       List[Any]        =						2.0
__A	:       Optional[Any]        =						6_66
def   __SCREAMING_SNAKE_CASE		(		lowercase__     ,				lowercase__ ):
					"""simple docstring"""
					return numpy.exp(lowercase__ ) + c_parameter
def   __SCREAMING_SNAKE_CASE		(		lowercase__     ,				lowercase__ ):
					"""simple docstring"""
					return z_values * z_values + c_parameter
def   __SCREAMING_SNAKE_CASE		(		lowercase__     ,				lowercase__ ):
					"""simple docstring"""
					A     =   numpy.linspace(-window_size     ,				lowercase__     ,				lowercase__ )
					A     =   x.reshape((nb_pixels, 1) )
					A     =   numpy.linspace(-window_size     ,				lowercase__     ,				lowercase__ )
					A     =   y.reshape((1, nb_pixels) )
					return x + 1.0J * y
def   __SCREAMING_SNAKE_CASE		(		lowercase__     ,				lowercase__     ,				lowercase__     ,				lowercase__     ,				lowercase__ = None     ,				):
					"""simple docstring"""
					A     =   z_a.astype("complex64" )
					for _ in range(lowercase__ ):
										A     =   eval_function(lowercase__     ,				lowercase__ )
										if infinity is not None:
															numpy.nan_to_num(lowercase__     ,				copy=lowercase__     ,				nan=lowercase__ )
															A     =   infinity
					return z_n
def   __SCREAMING_SNAKE_CASE		(		lowercase__     ,				lowercase__     ,				lowercase__     ,				lowercase__     ,				):
					"""simple docstring"""
					A     =   (abs(lowercase__ )).transpose()
					A     =   abs_z_final[::-1, :]
					pyplot.matshow(abs_z_final < escape_radius )
					pyplot.title(F"""Julia set of ${function_label}$, $c={function_params}$""" )
					pyplot.show()
def   __SCREAMING_SNAKE_CASE		(		):
					"""simple docstring"""
					warnings.filterwarnings(
					    "ignore"     ,				category=lowercase__     ,				message="overflow encountered in multiply" )
					warnings.filterwarnings(
					    "ignore"     ,				category=lowercase__     ,				message="invalid value encountered in multiply"     ,				)
					warnings.filterwarnings(
					    "ignore"     ,				category=lowercase__     ,				message="overflow encountered in absolute" )
					warnings.filterwarnings(
					    "ignore"     ,				category=lowercase__     ,				message="overflow encountered in exp" )


if __name__ == "__main__":
	__A	:       Optional[Any]        =						prepare_grid(window_size, nb_pixels)

	ignore_overflow_warnings()  # See file header for explanations

	__A	:       Optional[Any]        =						24
	__A	:       Optional[int]        =						2 * abs(c_cauliflower) + 1
	__A	:       int        =						iterate_function(
	    eval_quadratic_polynomial,
	    c_cauliflower,
	    nb_iterations,
	    z_a,
	    infinity=1.1 * escape_radius,
	)
	show_results('z^2+c', c_cauliflower, escape_radius, z_final)

	__A	:       Optional[Any]        =						64
	__A	:       List[str]        =						2 * abs(c_polynomial_a) + 1
	__A	:       Union[str, Any]        =						iterate_function(
	    eval_quadratic_polynomial,
	    c_polynomial_a,
	    nb_iterations,
	    z_a,
	    infinity=1.1 * escape_radius,
	)
	show_results('z^2+c', c_polynomial_a, escape_radius, z_final)

	__A	:       Any        =						1_61
	__A	:       Union[str, Any]        =						2 * abs(c_polynomial_a) + 1
	__A	:       int        =						iterate_function(
	    eval_quadratic_polynomial,
	    c_polynomial_a,
	    nb_iterations,
	    z_a,
	    infinity=1.1 * escape_radius,
	)
	show_results('z^2+c', c_polynomial_a, escape_radius, z_final)

	__A	:       str        =						12
	__A	:       List[str]        =						1_00_00.0
	__A	:       Dict        =						iterate_function(
	    eval_exponential,
	    c_exponential,
	    nb_iterations,
	    z_a + 2,
	    infinity=1.0E10,
	)
	show_results('e^z+c', c_exponential, escape_radius, z_final)










import json
import os
import shutil
import tempfile
import unittest

from transformers import is_speech_available, is_torch_available
from transformers.models.speechta import SpeechTaTokenizer
from transformers.testing_utils import get_tests_dir, require_torch
from transformers.utils import FEATURE_EXTRACTOR_NAME


if is_speech_available() and is_torch_available():
	from transformers import SpeechTaFeatureExtractor, SpeechTaProcessor

	from .test_feature_extraction_speechta import floats_list


A__       =			get_tests_dir("""fixtures/test_sentencepiece_bpe_char.model""")





@require_torch
class    __lowerCAmelCase					(	unittest.TestCase			):




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       tempfile.mkdtemp()

									_lowerCAmelCase         =       SpeechTaTokenizer(_snake_case						)
									tokenizer.save_pretrained(self.tmpdirname						)

									_lowerCAmelCase         =       {
									    """feature_size""": 1,
									    """padding_value""": 0.0,
									    """sampling_rate""": 16000,
									    """do_normalize""": False,
									    """num_mel_bins""": 80,
									    """hop_length""": 16,
									    """win_length""": 64,
									    """win_function""": """hann_window""",
									    """fmin""": 80,
									    """fmax""": 7600,
									    """mel_floor""": 1e-10,
									    """reduction_factor""": 2,
									    """return_attention_mask""": True,
									}

									_lowerCAmelCase         =       os.path.join(self.tmpdirname		,							_snake_case						)
									with open(self.feature_extraction_file		,							"""w"""		,							encoding="""utf-8"""						) as fp:
														fp.write(json.dumps(_snake_case						) + """\n"""						)




				def 				snake_case  (				self		,							**_snake_case						):



									"""simple docstring"""





									return SpeechTaTokenizer.from_pretrained(self.tmpdirname		,							**_snake_case						)




				def 				snake_case  (				self		,							**_snake_case						):



									"""simple docstring"""





									return SpeechTaFeatureExtractor.from_pretrained(self.tmpdirname		,							**_snake_case						)




				def 				snake_case  (				self						):



									"""simple docstring"""





									shutil.rmtree(self.tmpdirname						)




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.get_tokenizer()
									_lowerCAmelCase         =       self.get_feature_extractor()

									_lowerCAmelCase         =       SpeechTaProcessor(tokenizer=_snake_case		,							feature_extractor=_snake_case						)

									processor.save_pretrained(self.tmpdirname						)
									_lowerCAmelCase         =       SpeechTaProcessor.from_pretrained(self.tmpdirname						)

									self.assertEqual(processor.tokenizer.get_vocab()		,							tokenizer.get_vocab()						)
									self.assertIsInstance(processor.tokenizer		,							_snake_case						)

									self.assertEqual(processor.feature_extractor.to_json_string()		,							feature_extractor.to_json_string()						)
									self.assertIsInstance(processor.feature_extractor		,							_snake_case						)




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       SpeechTaProcessor(tokenizer=self.get_tokenizer()		,							feature_extractor=self.get_feature_extractor()						)
									processor.save_pretrained(self.tmpdirname						)

									_lowerCAmelCase         =       self.get_tokenizer(bos_token="""(BOS)"""		,							eos_token="""(EOS)"""						)
									_lowerCAmelCase         =       self.get_feature_extractor(do_normalize=_snake_case		,							padding_value=1.0						)

									_lowerCAmelCase         =       SpeechTaProcessor.from_pretrained(
									    self.tmpdirname		,							bos_token="""(BOS)"""		,							eos_token="""(EOS)"""		,							do_normalize=_snake_case		,							padding_value=1.0						)

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

									self.assertEqual(processor.feature_extractor.to_json_string()		,							feature_extractor_add_kwargs.to_json_string()						)
									self.assertIsInstance(processor.feature_extractor		,							_snake_case						)




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.get_feature_extractor()
									_lowerCAmelCase         =       self.get_tokenizer()

									_lowerCAmelCase         =       SpeechTaProcessor(tokenizer=_snake_case		,							feature_extractor=_snake_case						)

									_lowerCAmelCase         =       floats_list((3, 1000)						)

									_lowerCAmelCase         =       feature_extractor(audio=_snake_case		,							return_tensors="""np"""						)
									_lowerCAmelCase         =       processor(audio=_snake_case		,							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 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.get_feature_extractor()
									_lowerCAmelCase         =       self.get_tokenizer()

									_lowerCAmelCase         =       SpeechTaProcessor(tokenizer=_snake_case		,							feature_extractor=_snake_case						)

									_lowerCAmelCase         =       floats_list((3, 1000)						)

									_lowerCAmelCase         =       feature_extractor(audio_target=_snake_case		,							return_tensors="""np"""						)
									_lowerCAmelCase         =       processor(audio_target=_snake_case		,							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 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.get_feature_extractor()
									_lowerCAmelCase         =       self.get_tokenizer()

									_lowerCAmelCase         =       SpeechTaProcessor(tokenizer=_snake_case		,							feature_extractor=_snake_case						)

									_lowerCAmelCase         =       """This is a test string"""

									_lowerCAmelCase         =       processor(text=_snake_case						)
									_lowerCAmelCase         =       tokenizer(_snake_case						)

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




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.get_feature_extractor()
									_lowerCAmelCase         =       self.get_tokenizer()

									_lowerCAmelCase         =       SpeechTaProcessor(tokenizer=_snake_case		,							feature_extractor=_snake_case						)

									_lowerCAmelCase         =       """This is a test string"""

									_lowerCAmelCase         =       processor(text_target=_snake_case						)
									_lowerCAmelCase         =       tokenizer(_snake_case						)

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




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.get_feature_extractor()
									_lowerCAmelCase         =       self.get_tokenizer()

									_lowerCAmelCase         =       SpeechTaProcessor(tokenizer=_snake_case		,							feature_extractor=_snake_case						)

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

									_lowerCAmelCase         =       processor.batch_decode(_snake_case						)
									_lowerCAmelCase         =       tokenizer.batch_decode(_snake_case						)

									self.assertListEqual(_snake_case		,							_snake_case						)




				def 				snake_case  (				self						):



									"""simple docstring"""





									_lowerCAmelCase         =       self.get_feature_extractor()
									_lowerCAmelCase         =       self.get_tokenizer()

									_lowerCAmelCase         =       SpeechTaProcessor(tokenizer=_snake_case		,							feature_extractor=_snake_case						)

									self.assertListEqual(
									    processor.model_input_names		,							feature_extractor.model_input_names		,							msg="""`processor` and `feature_extractor` model input names do not match"""		,							)



