
"""simple docstring"""

from typing import List, Optional, Union

import numpy as np

from ...feature_extraction_sequence_utils import SequenceFeatureExtractor
from ...feature_extraction_utils import BatchFeature
from ...utils import PaddingStrategy, TensorType, logging


SCREAMING_SNAKE_CASE_    					=						logging.get_logger(__name__)
class      _UpperCAmelCase							(		lowercase__							):
						__SCREAMING_SNAKE_CASE   :							Union[str, Any]							      =	["input_values", "padding_mask"]




						def __init__(							self   ,       lowercase_ = 1   ,       lowercase_ = 2_4_0_0_0   ,       lowercase_ = 0.0   ,       lowercase_ = None   ,       lowercase_ = None   ,       **lowercase_   ,       )						->					Tuple:
										super().__init__(feature_size=__lowerCamelCase   ,       sampling_rate=__lowerCamelCase   ,       padding_value=__lowerCamelCase   ,       **__lowerCamelCase							)
										UpperCAmelCase									=					chunk_length_s
										UpperCAmelCase									=					overlap




						@property
						def     a_      (							self							)						->					Tuple:



										if self.chunk_length_s is None:
														return None
										else:
														return int(self.chunk_length_s * self.sampling_rate							)




						@property
						def     a_      (							self							)						->					str:



										if self.chunk_length_s is None or self.overlap is None:
														return None
										else:
														return max(1   ,       int((1.0 - self.overlap) * self.chunk_length							)							)




						def __call__(							self   ,       lowercase_   ,       lowercase_ = None   ,       lowercase_ = False   ,       lowercase_ = None   ,       lowercase_ = None   ,       lowercase_ = None   ,       )						->					Any:



										if sampling_rate is not None:
														if sampling_rate != self.sampling_rate:
																		raise ValueError(
																		    F"The model corresponding to this feature extractor: {self} was trained using a sampling rate of"
																		    F" {self.sampling_rate}. Please make sure that the provided audio input was sampled with"
																		    F" {self.sampling_rate} and not {sampling_rate}."							)
										else:
														logger.warning(
														    'It is strongly recommended to pass the `sampling_rate` argument to this function. '
														    'Failing to do so can result in silent errors that might be hard to debug.'							)

										if padding and truncation:
														raise ValueError('Both padding and truncation were set. Make sure you only set one.'							)
										elif padding is None:
														# by default let's pad the inputs
														UpperCAmelCase									=					True

										UpperCAmelCase									=					bool(
										    isinstance(__lowerCamelCase   ,       (list, tuple)							) and (isinstance(raw_audio[0]   ,       (np.ndarray, tuple, list)							))							)

										if is_batched:
														UpperCAmelCase									=					[np.asarray(__lowerCamelCase   ,       dtype=np.floataa							).T for audio in raw_audio]
										elif not is_batched and not isinstance(__lowerCamelCase   ,       np.ndarray							):
														UpperCAmelCase									=					np.asarray(__lowerCamelCase   ,       dtype=np.floataa							)
										elif isinstance(__lowerCamelCase   ,       np.ndarray							) and raw_audio.dtype is np.dtype(np.floataa							):
														UpperCAmelCase									=					raw_audio.astype(np.floataa							)

										# always return batch
										if not is_batched:
														UpperCAmelCase									=					[np.asarray(__lowerCamelCase							).T]

										# verify inputs are valid
										for idx, example in enumerate(__lowerCamelCase							):
														if example.ndim > 2:
																		raise ValueError(F"Expected input shape (channels, length) but got shape {example.shape}"							)
														if self.feature_size == 1 and example.ndim != 1:
																		raise ValueError(F"Expected mono audio but example has {example.shape[-1]} channels"							)
														if self.feature_size == 2 and example.shape[-1] != 2:
																		raise ValueError(F"Expected stereo audio but example has {example.shape[-1]} channels"							)

										UpperCAmelCase									=					None
										UpperCAmelCase									=					BatchFeature({'input_values': raw_audio}							)
										if self.chunk_stride is not None and self.chunk_length is not None and max_length is None:
														if truncation:
																		UpperCAmelCase									=					min(array.shape[0] for array in raw_audio							)
																		UpperCAmelCase									=					int(np.floor(max_length / self.chunk_stride							)							)
																		UpperCAmelCase									=					(nb_step - 1) * self.chunk_stride + self.chunk_length
														elif padding:
																		UpperCAmelCase									=					max(array.shape[0] for array in raw_audio							)
																		UpperCAmelCase									=					int(np.ceil(max_length / self.chunk_stride							)							)
																		UpperCAmelCase									=					(nb_step - 1) * self.chunk_stride + self.chunk_length
																		UpperCAmelCase									=					"max_length"
														else:
																		UpperCAmelCase									=					input_values

        # normal padding on batch
										if padded_inputs is None:
														UpperCAmelCase									=					self.pad(
														    __lowerCamelCase   ,       max_length=__lowerCamelCase   ,       truncation=__lowerCamelCase   ,       padding=__lowerCamelCase   ,       return_attention_mask=__lowerCamelCase   ,       )
														if padding:
																		UpperCAmelCase									=					padded_inputs.pop('attention_mask'							)

										UpperCAmelCase									=					[]
										for example in padded_inputs.pop('input_values'							):
														if self.feature_size == 1:
																		UpperCAmelCase									=					example[..., None]
														input_values.append(example.T							)

										UpperCAmelCase									=					input_values
										if return_tensors is not None:
														UpperCAmelCase									=					padded_inputs.convert_to_tensors(__lowerCamelCase							)

										return padded_inputs





"""simple docstring"""

def     lowercase__						(					lowerCAmelCase				:					int ,				lowerCAmelCase				:					int ) ->      int:






    """simple docstring"""




    return int((input_a, input_a).count(0 ) == 0 )




def     lowercase__						(					) ->      None:






    """simple docstring"""




    assert and_gate(0 ,				0 ) == 0
    assert and_gate(0 ,				1 ) == 0
    assert and_gate(1 ,				0 ) == 0
    assert and_gate(1 ,				1 ) == 1


if __name__ == "__main__":
   test_and_gate()
   print(and_gate(1, 0))
   print(and_gate(0, 0))
   print(and_gate(0, 1))
   print(and_gate(1, 1))



