






import itertools
import random
import unittest

import numpy as np

from transformers import WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST, WavaVecaConfig, WavaVecaFeatureExtractor
from transformers.testing_utils import require_torch, slow

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


_UpperCamelCase			:	Optional[int]								=random.Random()



def  a__ (__lowercase							:Dict					,  __lowercase							:int=1.0					,  __lowercase							:Tuple=None					,  __lowercase							:Optional[Any]=None   )		-> int:
				if rng is None:
								_A	:				Any   =      global_rng

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

				return values






class 						UpperCAmelCase__ (							unittest.TestCase							):







		def __init__(					self       ,A__       ,A__=7       ,A__=400       ,A__=2000       ,A__=1       ,A__=0.0       ,A__=16000       ,A__=True       ,A__=True       ,):
						_A	:				str   =      parent
						_A	:				List[str]   =      batch_size
						_A	:				Optional[int]   =      min_seq_length
						_A	:				Union[str, Any]   =      max_seq_length
						_A	:				Optional[int]   =      (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
						_A	:				List[str]   =      feature_size
						_A	:				Tuple   =      padding_value
						_A	:				Tuple   =      sampling_rate
						_A	:				List[str]   =      return_attention_mask
						_A	:				str   =      do_normalize







		def  A__      (					self		):
						return {
						    "feature_size": self.feature_size,
						    "padding_value": self.padding_value,
						    "sampling_rate": self.sampling_rate,
						    "return_attention_mask": self.return_attention_mask,
						    "do_normalize": self.do_normalize,
						}







		def  A__      (					self       ,A__=False       ,A__=False		):
						def _flatten(A__		):
										return list(itertools.chain(*A__		)		)

						if equal_length:
										_A	:				Tuple   =      floats_list((self.batch_size, self.max_seq_length)		)
						else:
										# make sure that inputs increase in size
										_A	:				Optional[Any]   =      [
										    _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	:				Tuple   =      [np.asarray(A__		) for x in speech_inputs]

						return speech_inputs






class 						UpperCAmelCase__ (							__snake_case     ,				unittest.TestCase							):
		__snake_case      :       Optional[int]     =   WavaVecaFeatureExtractor







		def  A__      (					self		):
						_A	:				str   =      WavaVecaFeatureExtractionTester(self		)







		def  A__      (					self       ,A__		):
						self.assertTrue(np.all(np.mean(A__       ,axis=0		) < 1E-3		)		)
						self.assertTrue(np.all(np.abs(np.var(A__       ,axis=0		) - 1		) < 1E-3		)		)







		def  A__      (					self		):
						# Tests that all call wrap to encode_plus and batch_encode_plus
						_A	:				List[str]   =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
						# create three inputs of length 800, 1000, and 1200
						_A	:				str   =      [floats_list((1, x)		)[0] for x in range(800       ,1400       ,200		)]
						_A	:				Any   =      [np.asarray(A__		) for speech_input in speech_inputs]

						# Test not batched input
						_A	:				Union[str, Any]   =      feat_extract(speech_inputs[0]       ,return_tensors='''np'''		).input_values
						_A	:				str   =      feat_extract(np_speech_inputs[0]       ,return_tensors='''np'''		).input_values
						self.assertTrue(np.allclose(A__       ,A__       ,atol=1E-3		)		)

						# Test batched
						_A	:				str   =      feat_extract(A__       ,return_tensors='''np'''		).input_values
						_A	:				List[Any]   =      feat_extract(A__       ,return_tensors='''np'''		).input_values
						for enc_seq_a, enc_seq_a in zip(A__       ,A__		):
										self.assertTrue(np.allclose(A__       ,A__       ,atol=1E-3		)		)

						# Test 2-D numpy arrays are batched.
						_A	:				Optional[int]   =      [floats_list((1, x)		)[0] for x in (800, 800, 800)]
						_A	:				Tuple   =      np.asarray(A__		)
						_A	:				Any   =      feat_extract(A__       ,return_tensors='''np'''		).input_values
						_A	:				str   =      feat_extract(A__       ,return_tensors='''np'''		).input_values
						for enc_seq_a, enc_seq_a in zip(A__       ,A__		):
										self.assertTrue(np.allclose(A__       ,A__       ,atol=1E-3		)		)







		def  A__      (					self		):
						_A	:				Dict   =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
						_A	:				Any   =      [floats_list((1, x)		)[0] for x in range(800       ,1400       ,200		)]

						_A	:				List[str]   =      ['''longest''', '''max_length''', '''do_not_pad''']
						_A	:				str   =      [None, 1600, None]
						for max_length, padding in zip(A__       ,A__		):
										_A	:				List[str]   =      feat_extract(A__       ,padding=A__       ,max_length=A__       ,return_tensors='''np'''		)
										_A	:				int   =      processed.input_values

										self._check_zero_mean_unit_variance(input_values[0][:800]		)
										self.assertTrue(input_values[0][800:].sum() < 1E-6		)
										self._check_zero_mean_unit_variance(input_values[1][:1000]		)
										self.assertTrue(input_values[0][1000:].sum() < 1E-6		)
										self._check_zero_mean_unit_variance(input_values[2][:1200]		)







		def  A__      (					self		):
						_A	:				Optional[Any]   =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
						_A	:				Tuple   =      range(800       ,1400       ,200		)
						_A	:				Tuple   =      [floats_list((1, x)		)[0] for x in lengths]

						_A	:				Dict   =      ['''longest''', '''max_length''', '''do_not_pad''']
						_A	:				str   =      [None, 1600, None]

						for max_length, padding in zip(A__       ,A__		):
										_A	:				Union[str, Any]   =      feat_extract(A__       ,max_length=A__       ,padding=A__		)
										_A	:				Tuple   =      processed.input_values

										self._check_zero_mean_unit_variance(input_values[0][:800]		)
										self._check_zero_mean_unit_variance(input_values[1][:1000]		)
										self._check_zero_mean_unit_variance(input_values[2][:1200]		)







		def  A__      (					self		):
						_A	:				Optional[int]   =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
						_A	:				List[Any]   =      [floats_list((1, x)		)[0] for x in range(800       ,1400       ,200		)]
						_A	:				str   =      feat_extract(
						    A__       ,truncation=A__       ,max_length=1000       ,padding='''max_length'''       ,return_tensors='''np'''		)
						_A	:				Tuple   =      processed.input_values

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







		def  A__      (					self		):
						_A	:				Dict   =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
						_A	:				List[Any]   =      [floats_list((1, x)		)[0] for x in range(800       ,1400       ,200		)]
						_A	:				int   =      feat_extract(
						    A__       ,truncation=A__       ,max_length=1000       ,padding='''longest'''       ,return_tensors='''np'''		)
						_A	:				List[Any]   =      processed.input_values

						self._check_zero_mean_unit_variance(input_values[0, :800]		)
						self._check_zero_mean_unit_variance(input_values[1, :1000]		)
						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, 1000)		)

						_A	:				Union[str, Any]   =      [floats_list((1, x)		)[0] for x in range(800       ,1400       ,200		)]
						_A	:				List[Any]   =      feat_extract(
						    A__       ,truncation=A__       ,max_length=2000       ,padding='''longest'''       ,return_tensors='''np'''		)
						_A	:				List[str]   =      processed.input_values

						self._check_zero_mean_unit_variance(input_values[0, :800]		)
						self._check_zero_mean_unit_variance(input_values[1, :1000]		)
						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, 1200)		)







		@require_torch
		def  A__      (					self		):
						import torch

						_A	:				str   =      self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()		)
						_A	:				List[Any]   =      np.random.rand(100		).astype(np.floataa		)
						_A	:				Tuple   =      np_speech_inputs.tolist()

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







		@slow
		@require_torch
		def  A__      (					self		):
						# this test makes sure that models that are using
						# group norm don't have their feature extractor return the
						# attention_mask
						for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
										_A	:				Tuple   =      WavaVecaConfig.from_pretrained(A__		)
										_A	:				int   =      WavaVecaFeatureExtractor.from_pretrained(A__		)

										# only "layer" feature extraction norm should make use of
										# attention_mask
										self.assertEqual(feat_extract.return_attention_mask       ,config.feat_extract_norm == '''layer'''		)











from collections import defaultdict



def  a__ (__lowercase							:str					,  __lowercase							:str   )		-> bool:
				_A	:				Union[str, Any]   =      first_str.lower().strip()
				_A	:				int   =      second_str.lower().strip()

				# Remove whitespace
				_A	:				int   =      first_str.replace(''' '''					,  ''''''   )
				_A	:				Optional[Any]   =      second_str.replace(''' '''					,  ''''''   )

				# Strings of different lengths are not anagrams
				if len(__lowercase   ) != len(__lowercase   ):
								return False

				# Default values for count should be 0
				_A	:				defaultdict[str, int]   =      defaultdict(__lowercase   )

				# For each character in input strings,
				# increment count in the corresponding
				for i in range(len(__lowercase   )   ):
								count[first_str[i]] += 1
								count[second_str[i]] -= 1

				return all(_count == 0 for _count in count.values()   )


if __name__ == "__main__":
	from doctest import testmod

	testmod()
	_UpperCamelCase			:	Dict								=input('Enter the first string ').strip()
	_UpperCamelCase			:	Union[str, Any]								=input('Enter the second string ').strip()

	_UpperCamelCase			:	Dict								=check_anagrams(input_a, input_b)
	print(f'''{input_a} and {input_b} are {"" if status else "not "}anagrams.''')



