





from typing import Dict, Optional, Tuple

import torch






def  SCREAMING_SNAKE_CASE__							(				UpperCamelCase__:							torch.Tensor			):
		SCREAMING_SNAKE_CASE__								=					boundaries[1] - boundaries[0]
		SCREAMING_SNAKE_CASE__								=					boundaries + step / 2
		SCREAMING_SNAKE_CASE__								=					torch.cat([bin_centers, (bin_centers[-1] + step).unsqueeze(-1			)]    ,      dim=0			)
		return bin_centers






def  SCREAMING_SNAKE_CASE__							(				UpperCamelCase__:							torch.Tensor    ,      UpperCamelCase__:							torch.Tensor    ,      ):
		SCREAMING_SNAKE_CASE__								=					_calculate_bin_centers(UpperCamelCase__			)
		return (
		    torch.sum(aligned_distance_error_probs * bin_centers    ,      dim=-1			),
		    bin_centers[-1],
		)






def  SCREAMING_SNAKE_CASE__							(				UpperCamelCase__:							torch.Tensor    ,      UpperCamelCase__:							int = 31    ,      UpperCamelCase__:							int = 64    ,      **UpperCamelCase__:							Tuple    ,      ):
		SCREAMING_SNAKE_CASE__								=					torch.linspace(0    ,      UpperCamelCase__    ,      steps=(no_bins - 1)    ,      device=logits.device			)

		SCREAMING_SNAKE_CASE__								=					torch.nn.functional.softmax(UpperCamelCase__    ,      dim=-1			)
		SCREAMING_SNAKE_CASE__		,  SCREAMING_SNAKE_CASE__								=					_calculate_expected_aligned_error(
		    alignment_confidence_breaks=UpperCamelCase__    ,      aligned_distance_error_probs=UpperCamelCase__    ,      )

		return {
		    "aligned_confidence_probs": aligned_confidence_probs,
		    "predicted_aligned_error": predicted_aligned_error,
		    "max_predicted_aligned_error": max_predicted_aligned_error,
		}






def  SCREAMING_SNAKE_CASE__							(				UpperCamelCase__:							torch.Tensor    ,      UpperCamelCase__:							Optional[torch.Tensor] = None    ,      UpperCamelCase__:							int = 31    ,      UpperCamelCase__:							int = 64    ,      UpperCamelCase__:							float = 1e-8    ,      **UpperCamelCase__:							Dict    ,      ):
		if residue_weights is None:
				SCREAMING_SNAKE_CASE__								=					logits.new_ones(logits.shape[-2]			)

		SCREAMING_SNAKE_CASE__								=					torch.linspace(0    ,      UpperCamelCase__    ,      steps=(no_bins - 1)    ,      device=logits.device			)

		SCREAMING_SNAKE_CASE__								=					_calculate_bin_centers(UpperCamelCase__			)
		torch.sum(UpperCamelCase__			)
		SCREAMING_SNAKE_CASE__								=					logits.shape[-2]
		SCREAMING_SNAKE_CASE__								=					max(UpperCamelCase__    ,      19			)

		SCREAMING_SNAKE_CASE__								=					1.2_4 * (clipped_n - 15) ** (1.0 / 3) - 1.8

		SCREAMING_SNAKE_CASE__								=					torch.nn.functional.softmax(UpperCamelCase__    ,      dim=-1			)

		SCREAMING_SNAKE_CASE__								=					1.0 / (1 + (bin_centers**2) / (da**2))
		SCREAMING_SNAKE_CASE__								=					torch.sum(probs * tm_per_bin    ,      dim=-1			)

		SCREAMING_SNAKE_CASE__								=					residue_weights / (eps + residue_weights.sum())
		SCREAMING_SNAKE_CASE__								=					torch.sum(predicted_tm_term * normed_residue_mask    ,      dim=-1			)

		SCREAMING_SNAKE_CASE__								=					per_alignment * residue_weights

		SCREAMING_SNAKE_CASE__								=					(weighted == torch.max(UpperCamelCase__			)).nonzero()[0]
		return per_alignment[tuple(UpperCamelCase__			)]






import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin




class      UpperCamelCase_				(   UpperCamelCase__			):
							lowerCamelCase_							=    ["image_processor", "tokenizer"]
							lowerCamelCase_							=    "AutoImageProcessor"
							lowerCamelCase_							=    "AutoTokenizer"


							def __init__(							self			:Any							, __A			:List[str]=None							, __A			:Dict=None							, **__A			:List[str]						)      ->      List[Any]:



									"""simple docstring"""



									SCREAMING_SNAKE_CASE__								=					None
									if "feature_extractor" in kwargs:
											warnings.warn(
											    """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
											    """ instead."""							, __A							, )
											SCREAMING_SNAKE_CASE__								=					kwargs.pop("""feature_extractor"""						)

									SCREAMING_SNAKE_CASE__								=					image_processor if image_processor is not None else feature_extractor
									if image_processor is None:
											raise ValueError("""You need to specify an `image_processor`."""						)
									if tokenizer is None:
											raise ValueError("""You need to specify a `tokenizer`."""						)

									super().__init__(__A							, __A						)
									SCREAMING_SNAKE_CASE__								=					self.image_processor
									SCREAMING_SNAKE_CASE__								=					False


							def __call__(							self			:List[str]							, *__A			:int							, **__A			:Optional[int]						)      ->      Optional[Any]:



									"""simple docstring"""



									if self._in_target_context_manager:
											return self.current_processor(*__A							, **__A						)

									SCREAMING_SNAKE_CASE__								=					kwargs.pop("""images"""							, __A						)
									SCREAMING_SNAKE_CASE__								=					kwargs.pop("""text"""							, __A						)
									if len(__A						) > 0:
											SCREAMING_SNAKE_CASE__								=					args[0]
											SCREAMING_SNAKE_CASE__								=					args[1:]

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

									if images is not None:
											SCREAMING_SNAKE_CASE__								=					self.image_processor(__A							, *__A							, **__A						)
									if text is not None:
											SCREAMING_SNAKE_CASE__								=					self.tokenizer(__A							, **__A						)

									if text is None:
											return inputs
									elif images is None:
											return encodings
									else:
											SCREAMING_SNAKE_CASE__								=					encodings["""input_ids"""]
											return inputs


							def    _snake_case     (							self			:Any							, *__A			:Optional[Any]							, **__A			:int						)      ->      List[Any]:



									"""simple docstring"""



									return self.tokenizer.batch_decode(*__A							, **__A						)


							def    _snake_case     (							self			:str							, *__A			:Optional[int]							, **__A			:List[Any]						)      ->      List[str]:



									"""simple docstring"""



									return self.tokenizer.decode(*__A							, **__A						)


							@contextmanager
							def    _snake_case     (							self			:Dict						)      ->      List[str]:



									"""simple docstring"""



									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 images inputs, or in a separate call."""						)
									SCREAMING_SNAKE_CASE__								=					True
									SCREAMING_SNAKE_CASE__								=					self.tokenizer
									yield
									SCREAMING_SNAKE_CASE__								=					self.image_processor
									SCREAMING_SNAKE_CASE__								=					False


							@property
							def    _snake_case     (							self			:List[str]						)      ->      int:



									"""simple docstring"""



									warnings.warn(
									    """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""							, __A							, )
									return self.image_processor_class


							@property
							def    _snake_case     (							self			:str						)      ->      List[Any]:



									"""simple docstring"""



									warnings.warn(
									    """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""							, __A							, )
									return self.image_processor