






'''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


SCREAMING_SNAKE_CASE__     =       random.Random()







def    lowercase__			(				__UpperCamelCase		,						__UpperCamelCase=1.0		,						__UpperCamelCase=None		,						__UpperCamelCase=None   )->			Any:
      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     a_						(      unittest.TestCase    ):

  def __init__(				self      ,		_SCREAMING_SNAKE_CASE      ,		_SCREAMING_SNAKE_CASE=7      ,		_SCREAMING_SNAKE_CASE=400      ,		_SCREAMING_SNAKE_CASE=2000      ,		_SCREAMING_SNAKE_CASE=1      ,		_SCREAMING_SNAKE_CASE=0.0      ,		_SCREAMING_SNAKE_CASE=16000      ,		_SCREAMING_SNAKE_CASE=True      ,		_SCREAMING_SNAKE_CASE=True      ,		)  ->				Optional[int]:



        """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				)  ->				str:



        """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      ,		_SCREAMING_SNAKE_CASE=False      ,		_SCREAMING_SNAKE_CASE=False				)  ->				Optional[int]:



        """simple docstring"""






        def _flatten(_SCREAMING_SNAKE_CASE				):
              return list(itertools.chain(*_a				)				)

        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(_a				) for x in speech_inputs]

        return speech_inputs






class     a_						(      UpperCamelCase_     ,	unittest.TestCase    ):
  lowercase							=				WavaVecaFeatureExtractor

  def   A__						(				self				)  ->				Optional[int]:



        """simple docstring"""






        UpperCamelCase      = WavaVecaFeatureExtractionTester(self				)

  def   A__						(				self      ,		_SCREAMING_SNAKE_CASE				)  ->				Optional[Any]:



        """simple docstring"""






        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				)  ->				List[str]:



        """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(800      ,		1400      ,		200				)]
        UpperCamelCase      = [np.asarray(_a				) 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(_a      ,		_a      ,		atol=1e-3				)				)

        # Test batched
        UpperCamelCase      = feat_extract(_a      ,		return_tensors="""np"""				).input_values
        UpperCamelCase      = 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.
        UpperCamelCase      = [floats_list((1, x)				)[0] for x in (800, 800, 800)]
        UpperCamelCase      = np.asarray(_a				)
        UpperCamelCase      = feat_extract(_a      ,		return_tensors="""np"""				).input_values
        UpperCamelCase      = 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				)  ->				int:



        """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(800      ,		1400      ,		200				)]

        UpperCamelCase      = ["""longest""", """max_length""", """do_not_pad"""]
        UpperCamelCase      = [None, 1600, None]
        for max_length, padding in zip(_a      ,		_a				):
              UpperCamelCase      = feat_extract(_a      ,		padding=_a      ,		max_length=_a      ,		return_tensors="""np"""				)
              UpperCamelCase      = 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				)  ->				Tuple:



        """simple docstring"""






        UpperCamelCase      = self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
        UpperCamelCase      = range(800      ,		1400      ,		200				)
        UpperCamelCase      = [floats_list((1, x)				)[0] for x in lengths]

        UpperCamelCase      = ["""longest""", """max_length""", """do_not_pad"""]
        UpperCamelCase      = [None, 1600, None]

        for max_length, padding in zip(_a      ,		_a				):
              UpperCamelCase      = feat_extract(_a      ,		max_length=_a      ,		padding=_a				)
              UpperCamelCase      = 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				)  ->				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(800      ,		1400      ,		200				)]
        UpperCamelCase      = feat_extract(
            _a      ,		truncation=_a      ,		max_length=1000      ,		padding="""max_length"""      ,		return_tensors="""np"""				)
        UpperCamelCase      = 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				)  ->				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(800      ,		1400      ,		200				)]
        UpperCamelCase      = feat_extract(
            _a      ,		truncation=_a      ,		max_length=1000      ,		padding="""longest"""      ,		return_tensors="""np"""				)
        UpperCamelCase      = 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)				)

        UpperCamelCase      = [floats_list((1, x)				)[0] for x in range(800      ,		1400      ,		200				)]
        UpperCamelCase      = feat_extract(
            _a      ,		truncation=_a      ,		max_length=2000      ,		padding="""longest"""      ,		return_tensors="""np"""				)
        UpperCamelCase      = 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				)  ->				Tuple:



        """simple docstring"""






        import torch

        UpperCamelCase      = self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()				)
        UpperCamelCase      = np.random.rand(100				).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				)  ->				int:



        """simple docstring"""






        for model_id in WAV_2_VEC_2_PRETRAINED_MODEL_ARCHIVE_LIST:
              UpperCamelCase      = WavaVecaConfig.from_pretrained(_a				)
              UpperCamelCase      = 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"""				)








'''simple docstring'''

from maths.is_square_free import is_square_free
from maths.prime_factors import prime_factors







def    lowercase__			(				__UpperCamelCase   )->			int:
      UpperCamelCase      = prime_factors(__UpperCamelCase   )
      if is_square_free(__UpperCamelCase   ):
            return -1 if len(__UpperCamelCase   ) % 2 else 1
      return 0


if __name__ == "__main__":
     import doctest

     doctest.testmod()
