


import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
from .tokenization_wavaveca import WavaVecaCTCTokenizer

class     a		(_lowerCAmelCase				):




							"""simple docstring"""


							__UpperCAmelCase   :							Dict					  =  "Wav2Vec2FeatureExtractor"
							__UpperCAmelCase   :							List[str]					  =  "AutoTokenizer"

							def __init__(							self	:  List[str]   ,     lowerCamelCase	:  List[str]   ,     lowerCamelCase	:  Dict    )     ->   List[Any]:
														super().__init__(lowerCamelCase   ,     lowerCamelCase    )
														__snake_case		:      Dict										=       self.feature_extractor
														__snake_case		:      Union[str, Any]										=       False

							@classmethod
							def    __snake_case (							cls	:  Tuple   ,     lowerCamelCase	:  Tuple   ,     **lowerCamelCase	:  Optional[Any]    )     ->   List[Any]:
														try:
																					return super().from_pretrained(lowerCamelCase   ,     **lowerCamelCase    )
														except OSError:
																					warnings.warn(
																					    F'Loading a tokenizer inside {cls.__name__} from a config that does not'
																					    " include a `tokenizer_class` attribute is deprecated and will be "
																					    "removed in v5. Please add `'tokenizer_class': 'Wav2Vec2CTCTokenizer'`"
																					    " attribute to either your `config.json` or `tokenizer_config.json` "
																					    "file to suppress this warning: "   ,     lowerCamelCase   ,     )

																					__snake_case		:      Tuple										=       WavaVecaFeatureExtractor.from_pretrained(lowerCamelCase   ,     **lowerCamelCase    )
																					__snake_case		:      Any										=       WavaVecaCTCTokenizer.from_pretrained(lowerCamelCase   ,     **lowerCamelCase    )

																					return cls(feature_extractor=lowerCamelCase   ,     tokenizer=lowerCamelCase    )

							def __call__(							self	:  Dict   ,     *lowerCamelCase	:  Union[str, Any]   ,     **lowerCamelCase	:  Optional[int]    )     ->   Union[str, Any]:
														# For backward compatibility
														if self._in_target_context_manager:
																					return self.current_processor(*lowerCamelCase   ,     **lowerCamelCase    )

														if "raw_speech" in kwargs:
																					warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."    )
																					__snake_case		:      Any										=       kwargs.pop("raw_speech"    )
														else:
																					__snake_case		:      Optional[Any]										=       kwargs.pop("audio"   ,     lowerCamelCase    )
														__snake_case		:      Optional[int]										=       kwargs.pop("sampling_rate"   ,     lowerCamelCase    )
														__snake_case		:      str										=       kwargs.pop("text"   ,     lowerCamelCase    )
														if len(lowerCamelCase    ) > 0:
																					__snake_case		:      List[Any]										=       args[0]
																					__snake_case		:      str										=       args[1:]

														if audio is None and text is None:
																					raise ValueError("You need to specify either an `audio` or `text` input to process."    )

														if audio is not None:
																					__snake_case		:      Union[str, Any]										=       self.feature_extractor(lowerCamelCase   ,     *lowerCamelCase   ,     sampling_rate=lowerCamelCase   ,     **lowerCamelCase    )
														if text is not None:
																					__snake_case		:      Union[str, Any]										=       self.tokenizer(lowerCamelCase   ,     **lowerCamelCase    )

														if text is None:
																					return inputs
														elif audio is None:
																					return encodings
														else:
																					__snake_case		:      List[Any]										=       encodings["input_ids"]
																					return inputs

							def    __snake_case (							self	:  Dict   ,     *lowerCamelCase	:  str   ,     **lowerCamelCase	:  Dict    )     ->   int:
														# For backward compatibility
														if self._in_target_context_manager:
																					return self.current_processor.pad(*lowerCamelCase   ,     **lowerCamelCase    )

														__snake_case		:      str										=       kwargs.pop("input_features"   ,     lowerCamelCase    )
														__snake_case		:      List[str]										=       kwargs.pop("labels"   ,     lowerCamelCase    )
														if len(lowerCamelCase    ) > 0:
																					__snake_case		:      Optional[Any]										=       args[0]
																					__snake_case		:      Optional[int]										=       args[1:]

														if input_features is not None:
																					__snake_case		:      Optional[Any]										=       self.feature_extractor.pad(lowerCamelCase   ,     *lowerCamelCase   ,     **lowerCamelCase    )
														if labels is not None:
																					__snake_case		:      int										=       self.tokenizer.pad(lowerCamelCase   ,     **lowerCamelCase    )

														if labels is None:
																					return input_features
														elif input_features is None:
																					return labels
														else:
																					__snake_case		:      Union[str, Any]										=       labels["input_ids"]
																					return input_features

							def    __snake_case (							self	:  Optional[int]   ,     *lowerCamelCase	:  Any   ,     **lowerCamelCase	:  List[Any]    )     ->   Any:
														return self.tokenizer.batch_decode(*lowerCamelCase   ,     **lowerCamelCase    )

							def    __snake_case (							self	:  Union[str, Any]   ,     *lowerCamelCase	:  List[Any]   ,     **lowerCamelCase	:  Optional[Any]    )     ->   Union[str, Any]:
														return self.tokenizer.decode(*lowerCamelCase   ,     **lowerCamelCase    )






							@contextmanager
							def    __snake_case (							self	:  Union[str, Any]    )     ->   Union[str, Any]:
														warnings.warn(
														    "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your "
														    "labels by using the argument `text` of the regular `__call__` method (either in the same call as "
														    "your audio inputs, or in a separate call."    )
														__snake_case		:      Dict										=       True
														__snake_case		:      Dict										=       self.tokenizer
														yield
														__snake_case		:      Dict										=       self.feature_extractor
														__snake_case		:      Union[str, Any]										=       False





from typing import Dict

import numpy as np
import torch

from . import residue_constants as rc
from .tensor_utils import tensor_tree_map, tree_map







def     lowerCAmelCase_					( __lowerCamelCase     ):
							__snake_case		:      Any										=       []
							__snake_case		:      Optional[Any]										=       []
							__snake_case		:      List[Any]										=       []

							for rt in rc.restypes:
														__snake_case		:      Any										=       rc.restype_name_to_atomaa_names[rc.restype_atoa[rt]]
														restype_atomaa_to_atomaa_list.append([(rc.atom_order[name] if name else 0) for name in atom_names]     )
														__snake_case		:      Tuple										=       {name: i for i, name in enumerate(__lowerCamelCase     )}
														restype_atomaa_to_atomaa_list.append(
														    [(atom_name_to_idxaa[name] if name in atom_name_to_idxaa else 0) for name in rc.atom_types]     )

														restype_atomaa_mask_list.append([(1.0 if name else 0.0) for name in atom_names]     )

							# Add dummy mapping for restype 'UNK'
							restype_atomaa_to_atomaa_list.append([0] * 1_4     )
							restype_atomaa_to_atomaa_list.append([0] * 3_7     )
							restype_atomaa_mask_list.append([0.0] * 1_4     )

							__snake_case		:      int										=       torch.tensor(
							    __lowerCamelCase							,     dtype=torch.intaa							,     device=protein["aatype"].device							,     )
							__snake_case		:      List[str]										=       torch.tensor(
							    __lowerCamelCase							,     dtype=torch.intaa							,     device=protein["aatype"].device							,     )
							__snake_case		:      Optional[Any]										=       torch.tensor(
							    __lowerCamelCase							,     dtype=torch.floataa							,     device=protein["aatype"].device							,     )
							__snake_case		:      Optional[int]										=       protein["aatype"].to(torch.long     )

							# create the mapping for (residx, atom14) --> atom37, i.e. an array
							# with shape (num_res, 14) containing the atom37 indices for this protein
							__snake_case		:      Optional[Any]										=       restype_atomaa_to_atomaa[protein_aatype]
							__snake_case		:      Tuple										=       restype_atomaa_mask[protein_aatype]

							__snake_case		:      Optional[Any]										=       residx_atomaa_mask
							__snake_case		:      Union[str, Any]										=       residx_atomaa_to_atomaa.long()

							# create the gather indices for mapping back
							__snake_case		:      Dict										=       restype_atomaa_to_atomaa[protein_aatype]
							__snake_case		:      Dict										=       residx_atomaa_to_atomaa.long()

							# create the corresponding mask
							__snake_case		:      List[str]										=       torch.zeros([2_1, 3_7]							,     dtype=torch.floataa							,     device=protein["aatype"].device     )
							for restype, restype_letter in enumerate(rc.restypes     ):
														__snake_case		:      List[str]										=       rc.restype_atoa[restype_letter]
														__snake_case		:      List[Any]										=       rc.residue_atoms[restype_name]
														for atom_name in atom_names:
																					__snake_case		:      Union[str, Any]										=       rc.atom_order[atom_name]
																					__snake_case		:      str										=       1

							__snake_case		:      List[str]										=       restype_atomaa_mask[protein_aatype]
							__snake_case		:      List[str]										=       residx_atomaa_mask

							return protein







def     lowerCAmelCase_					( __lowerCamelCase     ):
							__snake_case		:      str										=       tree_map(lambda __lowerCamelCase     : torch.tensor(__lowerCamelCase							,     device=batch["aatype"].device     )							,     __lowerCamelCase							,     np.ndarray     )
							__snake_case		:      str										=       tensor_tree_map(lambda __lowerCamelCase     : np.array(__lowerCamelCase     )							,     make_atomaa_masks(__lowerCamelCase     )     )
							return out

