



'''simple docstring'''


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


_lowerCamelCase	:       Tuple      	=	random.Random()







def 				__lowerCamelCase				(   A__    ,						A__=1.0    ,						A__=None    ,						A__=None    )       ->	Union[str, Any]:






   """simple docstring"""
   if rng is None:
      UpperCamelCase					=  global_rng

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

   return values

class  SCREAMING_SNAKE_CASE (  unittest.TestCase		):






    """simple docstring"""





    def __init__(  self      :					Any  ,						UpperCamelCase__      :					Any  ,						UpperCamelCase__      :					Optional[Any]=7  ,						UpperCamelCase__      :					List[str]=4_0_0  ,						UpperCamelCase__      :					str=2_0_0_0  ,						UpperCamelCase__      :					Any=1  ,						UpperCamelCase__      :					Optional[Any]=0.0  ,						UpperCamelCase__      :					Tuple=1_6_0_0_0  ,						UpperCamelCase__      :					List[str]=True  ,						UpperCamelCase__      :					Dict=True  ,						):


       """simple docstring"""







       UpperCamelCase					=  parent
       UpperCamelCase					=  batch_size
       UpperCamelCase					=  min_seq_length
       UpperCamelCase					=  max_seq_length
       UpperCamelCase					=  (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
       UpperCamelCase					=  feature_size
       UpperCamelCase					=  padding_value
       UpperCamelCase					=  sampling_rate
       UpperCamelCase					=  return_attention_mask
       UpperCamelCase					=  do_normalize






    def  A       (  self      :					Optional[int] ):


       """simple docstring"""







       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      :					Union[str, Any]  ,						UpperCamelCase__      :					Optional[int]=False  ,						UpperCamelCase__      :					Union[str, Any]=False ):


       """simple docstring"""







       def _flatten(UpperCamelCase__      :					Optional[Any] ):
          return list(itertools.chain(*UpperCamelCase__ ) )

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

       return speech_inputs

class  SCREAMING_SNAKE_CASE (  _a   ,						unittest.TestCase		):






    """simple docstring"""





    _SCREAMING_SNAKE_CASE	  =  WavaVecaFeatureExtractor






    def  A       (  self      :					Union[str, Any] ):


       """simple docstring"""







       UpperCamelCase					=  WavaVecaFeatureExtractionTester(self )






    def  A       (  self      :					Optional[Any]  ,						UpperCamelCase__      :					List[str] ):


       """simple docstring"""







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






    def  A       (  self      :					Optional[int] ):


       """simple docstring"""







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

       # Test not batched input
       UpperCamelCase					=  feat_extract(speech_inputs[0]  ,						return_tensors='np' ).input_values
       UpperCamelCase					=  feat_extract(np_speech_inputs[0]  ,						return_tensors='np' ).input_values
       self.assertTrue(np.allclose(UpperCamelCase__  ,						UpperCamelCase__  ,						atol=1E-3 ) )

       # Test batched
       UpperCamelCase					=  feat_extract(UpperCamelCase__  ,						return_tensors='np' ).input_values
       UpperCamelCase					=  feat_extract(UpperCamelCase__  ,						return_tensors='np' ).input_values
       for enc_seq_a, enc_seq_a in zip(UpperCamelCase__  ,						UpperCamelCase__ ):
          self.assertTrue(np.allclose(UpperCamelCase__  ,						UpperCamelCase__  ,						atol=1E-3 ) )

       # Test 2-D numpy arrays are batched.
       UpperCamelCase					=  [floats_list((1, x) )[0] for x in (8_0_0, 8_0_0, 8_0_0)]
       UpperCamelCase					=  np.asarray(UpperCamelCase__ )
       UpperCamelCase					=  feat_extract(UpperCamelCase__  ,						return_tensors='np' ).input_values
       UpperCamelCase					=  feat_extract(UpperCamelCase__  ,						return_tensors='np' ).input_values
       for enc_seq_a, enc_seq_a in zip(UpperCamelCase__  ,						UpperCamelCase__ ):
          self.assertTrue(np.allclose(UpperCamelCase__  ,						UpperCamelCase__  ,						atol=1E-3 ) )






    def  A       (  self      :					Dict ):


       """simple docstring"""







       UpperCamelCase					=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
       UpperCamelCase					=  [floats_list((1, x) )[0] for x in range(8_0_0  ,						1_4_0_0  ,						2_0_0 )]

       UpperCamelCase					=  ['longest', 'max_length', 'do_not_pad']
       UpperCamelCase					=  [None, 1_6_0_0, None]
       for max_length, padding in zip(UpperCamelCase__  ,						UpperCamelCase__ ):
          UpperCamelCase					=  feat_extract(UpperCamelCase__  ,						padding=UpperCamelCase__  ,						max_length=UpperCamelCase__  ,						return_tensors='np' )
          UpperCamelCase					=  processed.input_values

          self._check_zero_mean_unit_variance(input_values[0][:8_0_0] )
          self.assertTrue(input_values[0][8_0_0:].sum() < 1E-6 )
          self._check_zero_mean_unit_variance(input_values[1][:1_0_0_0] )
          self.assertTrue(input_values[0][1_0_0_0:].sum() < 1E-6 )
          self._check_zero_mean_unit_variance(input_values[2][:1_2_0_0] )






    def  A       (  self      :					Optional[Any] ):


       """simple docstring"""







       UpperCamelCase					=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
       UpperCamelCase					=  range(8_0_0  ,						1_4_0_0  ,						2_0_0 )
       UpperCamelCase					=  [floats_list((1, x) )[0] for x in lengths]

       UpperCamelCase					=  ['longest', 'max_length', 'do_not_pad']
       UpperCamelCase					=  [None, 1_6_0_0, None]

       for max_length, padding in zip(UpperCamelCase__  ,						UpperCamelCase__ ):
          UpperCamelCase					=  feat_extract(UpperCamelCase__  ,						max_length=UpperCamelCase__  ,						padding=UpperCamelCase__ )
          UpperCamelCase					=  processed.input_values

          self._check_zero_mean_unit_variance(input_values[0][:8_0_0] )
          self._check_zero_mean_unit_variance(input_values[1][:1_0_0_0] )
          self._check_zero_mean_unit_variance(input_values[2][:1_2_0_0] )






    def  A       (  self      :					str ):


       """simple docstring"""







       UpperCamelCase					=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
       UpperCamelCase					=  [floats_list((1, x) )[0] for x in range(8_0_0  ,						1_4_0_0  ,						2_0_0 )]
       UpperCamelCase					=  feat_extract(
           UpperCamelCase__  ,						truncation=UpperCamelCase__  ,						max_length=1_0_0_0  ,						padding='max_length'  ,						return_tensors='np' )
       UpperCamelCase					=  processed.input_values

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






    def  A       (  self      :					Tuple ):


       """simple docstring"""







       UpperCamelCase					=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict() )
       UpperCamelCase					=  [floats_list((1, x) )[0] for x in range(8_0_0  ,						1_4_0_0  ,						2_0_0 )]
       UpperCamelCase					=  feat_extract(
           UpperCamelCase__  ,						truncation=UpperCamelCase__  ,						max_length=1_0_0_0  ,						padding='longest'  ,						return_tensors='np' )
       UpperCamelCase					=  processed.input_values

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

       UpperCamelCase					=  [floats_list((1, x) )[0] for x in range(8_0_0  ,						1_4_0_0  ,						2_0_0 )]
       UpperCamelCase					=  feat_extract(
           UpperCamelCase__  ,						truncation=UpperCamelCase__  ,						max_length=2_0_0_0  ,						padding='longest'  ,						return_tensors='np' )
       UpperCamelCase					=  processed.input_values

       self._check_zero_mean_unit_variance(input_values[0, :8_0_0] )
       self._check_zero_mean_unit_variance(input_values[1, :1_0_0_0] )
       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, 1_2_0_0) )






    @require_torch
    def  A       (  self      :					Optional[Any] ):


       """simple docstring"""







       import torch

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

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






    @slow
    @require_torch
    def  A       (  self      :					Any ):


       """simple docstring"""







       for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
          UpperCamelCase					=  WavaVecaConfig.from_pretrained(UpperCamelCase__ )
          UpperCamelCase					=  WavaVecaFeatureExtractor.from_pretrained(UpperCamelCase__ )

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



"""simple docstring"""





from collections import defaultdict



def 						_lowerCAmelCase				(				UpperCamelCase_  ,				UpperCamelCase_				):
		__SCREAMING_SNAKE_CASE            = first_str.lower().strip()
		__SCREAMING_SNAKE_CASE            = second_str.lower().strip()

		# Remove whitespace
		__SCREAMING_SNAKE_CASE            = first_str.replace(""" """  ,				""""""				)
		__SCREAMING_SNAKE_CASE            = second_str.replace(""" """  ,				""""""				)

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

		# Default values for count should be 0
		__SCREAMING_SNAKE_CASE            = defaultdict(UpperCamelCase_				)

		# For each character in input strings,
		# increment count in the corresponding
		for i in range(len(UpperCamelCase_				)				):
				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()
							__magic_name__       =			input("Enter the first string ").strip()
							__magic_name__       =			input("Enter the second string ").strip()

							__magic_name__       =			check_anagrams(input_a, input_b)
							print(F"""{input_a} and {input_b} are {"" if status else "not "}anagrams.""")




