




"""simple docstring"""

# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
		import tensorflow as tf
class      A__   (   TensorFormatter[Mapping, """tf.Tensor""", Mapping]  ):




	def __init__( self	:						List[Any]   ,     lowercase	:						Optional[Any]=None   ,     **lowercase	:						Any						)       ->			Tuple:
						super().__init__(features=lowercase						)
						__snake_case        =						tf_tensor_kwargs
						import tensorflow as tf  # noqa: import tf at initialization




	def 				a_		( self	:						List[str]   ,     lowercase	:						str						)       ->			Optional[Any]:
						import tensorflow as tf

						if isinstance(lowercase   ,     lowercase						) and column:
											if all(
											    isinstance(lowercase   ,     tf.Tensor						) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column						):
																return tf.stack(lowercase						)
											elif all(
											    isinstance(lowercase   ,     (tf.Tensor, tf.RaggedTensor)						) and x.ndim == 1 and x.dtype == column[0].dtype
											    for x in column						):
																# only rag 1-D tensors, otherwise some dimensions become ragged even though they were consolidated
																return tf.ragged.stack(lowercase						)

						return column




	def 				a_		( self	:						str   ,     lowercase	:						Any						)       ->			Union[str, Any]:
						import tensorflow as tf

						if value is None:
											return value

						__snake_case        =						{}

						if isinstance(lowercase   ,     (np.number, np.ndarray)						) and np.issubdtype(value.dtype   ,     np.integer						):
											__snake_case        =						{"""dtype""": tf.intaa}
						elif isinstance(lowercase   ,     (np.number, np.ndarray)						) and np.issubdtype(value.dtype   ,     np.floating						):
											__snake_case        =						{"""dtype""": tf.floataa}
						elif config.PIL_AVAILABLE and "PIL" in sys.modules:
											import PIL.Image

											if isinstance(lowercase   ,     PIL.Image.Image						):
																__snake_case        =						np.asarray(lowercase						)

						return tf.convert_to_tensor(lowercase   ,     **{**default_dtype, **self.tf_tensor_kwargs}						)




	def 				a_		( self	:						str   ,     lowercase	:						List[Any]						)       ->			Dict:
						import tensorflow as tf

						# support for torch, tf, jax etc.
						if config.TORCH_AVAILABLE and "torch" in sys.modules:
											import torch

											if isinstance(lowercase   ,     torch.Tensor						):
																return self._tensorize(data_struct.detach().cpu().numpy()[()]						)
						if hasattr(lowercase   ,     """__array__"""						) and not isinstance(lowercase   ,     tf.Tensor						):
											__snake_case        =						data_struct.__array__()
						# support for nested types like struct of list of struct
						if isinstance(lowercase   ,     np.ndarray						):
											if data_struct.dtype == object:  # tf tensors cannot be instantied from an array of objects
																return self._consolidate([self.recursive_tensorize(lowercase						) for substruct in data_struct]						)
						elif isinstance(lowercase   ,     (list, tuple)						):
											return self._consolidate([self.recursive_tensorize(lowercase						) for substruct in data_struct]						)
						return self._tensorize(lowercase						)




	def 				a_		( self	:						Optional[Any]   ,     lowercase	:						dict						)       ->			Optional[Any]:
						return map_nested(self._recursive_tensorize   ,     lowercase   ,     map_list=lowercase						)




	def 				a_		( self	:						List[Any]   ,     lowercase	:						pa.Table						)       ->			Mapping:
						__snake_case        =						self.numpy_arrow_extractor().extract_row(lowercase						)
						__snake_case        =						self.python_features_decoder.decode_row(lowercase						)
						return self.recursive_tensorize(lowercase						)




	def 				a_		( self	:						Optional[Any]   ,     lowercase	:						pa.Table						)       ->			"tf.Tensor":
						__snake_case        =						self.numpy_arrow_extractor().extract_column(lowercase						)
						__snake_case        =						self.python_features_decoder.decode_column(lowercase   ,     pa_table.column_names[0]						)
						__snake_case        =						self.recursive_tensorize(lowercase						)
						__snake_case        =						self._consolidate(lowercase						)
						return column




	def 				a_		( self	:						Union[str, Any]   ,     lowercase	:						pa.Table						)       ->			Mapping:
						__snake_case        =						self.numpy_arrow_extractor().extract_batch(lowercase						)
						__snake_case        =						self.python_features_decoder.decode_batch(lowercase						)
						__snake_case        =						self.recursive_tensorize(lowercase						)
						for column_name in batch:
											__snake_case        =						self._consolidate(batch[column_name]						)
						return batch








"""simple docstring"""

from .chunk_utils import chunk_layer
from .data_transforms import make_atomaa_masks
from .feats import atomaa_to_atomaa, frames_and_literature_positions_to_atomaa_pos, torsion_angles_to_frames
from .loss import compute_predicted_aligned_error, compute_tm
from .protein import Protein as OFProtein
from .protein import to_pdb
from .rigid_utils import Rigid, Rotation
from .tensor_utils import dict_multimap, flatten_final_dims, permute_final_dims


