




'''simple docstring'''





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     lowercase  ( TensorFormatter[Mapping, '''tf.Tensor''', Mapping]):






      def __init__(self			,	a__=None			,	**a__       )							-> Union[str, Any]:
         super().__init__(features=a__       )
         SCREAMING_SNAKE_CASE__      :					int							    =			tf_tensor_kwargs
         import tensorflow as tf  # noqa: import tf at initialization






      def  A__(self			,	a__       )							-> Any:
         import tensorflow as tf

         if isinstance(a__			,	a__       ) and column:
            if all(
                isinstance(a__			,	tf.Tensor       ) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column       ):
               return tf.stack(a__       )
            elif all(
                isinstance(a__			,	(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(a__       )

         return column






      def  A__(self			,	a__       )							-> Tuple:
         import tensorflow as tf

         if value is None:
            return value

         SCREAMING_SNAKE_CASE__      :					str							    =			{}

         if isinstance(a__			,	(np.number, np.ndarray)       ) and np.issubdtype(value.dtype			,	np.integer       ):
            SCREAMING_SNAKE_CASE__      :					str							    =			{'''dtype''': tf.intaa}
         elif isinstance(a__			,	(np.number, np.ndarray)       ) and np.issubdtype(value.dtype			,	np.floating       ):
            SCREAMING_SNAKE_CASE__      :					List[Any]							    =			{'''dtype''': tf.floataa}
         elif config.PIL_AVAILABLE and "PIL" in sys.modules:
            import PIL.Image

            if isinstance(a__			,	PIL.Image.Image       ):
               SCREAMING_SNAKE_CASE__      :					Optional[Any]							    =			np.asarray(a__       )

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






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

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

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






      def  A__(self			,	a__       )							-> List[str]:
         return map_nested(self._recursive_tensorize			,	a__			,	map_list=a__       )






      def  A__(self			,	a__       )							-> Tuple:
         SCREAMING_SNAKE_CASE__      :					List[str]							    =			self.numpy_arrow_extractor().extract_row(a__       )
         SCREAMING_SNAKE_CASE__      :					int							    =			self.python_features_decoder.decode_row(a__       )
         return self.recursive_tensorize(a__       )






      def  A__(self			,	a__       )							-> List[Any]:
         SCREAMING_SNAKE_CASE__      :					List[str]							    =			self.numpy_arrow_extractor().extract_column(a__       )
         SCREAMING_SNAKE_CASE__      :					List[str]							    =			self.python_features_decoder.decode_column(a__			,	pa_table.column_names[0]       )
         SCREAMING_SNAKE_CASE__      :					int							    =			self.recursive_tensorize(a__       )
         SCREAMING_SNAKE_CASE__      :					List[str]							    =			self._consolidate(a__       )
         return column






      def  A__(self			,	a__       )							-> str:
         SCREAMING_SNAKE_CASE__      :					Union[str, Any]							    =			self.numpy_arrow_extractor().extract_batch(a__       )
         SCREAMING_SNAKE_CASE__      :					Tuple							    =			self.python_features_decoder.decode_batch(a__       )
         SCREAMING_SNAKE_CASE__      :					List[Any]							    =			self.recursive_tensorize(a__       )
         for column_name in batch:
            SCREAMING_SNAKE_CASE__      :					List[Any]							    =			self._consolidate(batch[column_name]       )
         return batch



'''simple docstring'''







def       _a		(						_SCREAMING_SNAKE_CASE		: int						,      _SCREAMING_SNAKE_CASE		: int	):
						return (input_a, input_a).count(0	) % 2



def       _a		(						):
						assert xor_gate(0						,      0	) == 0
						assert xor_gate(0						,      1	) == 1
						assert xor_gate(1						,      0	) == 1
						assert xor_gate(1						,      1	) == 0


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