
'''simple docstring'''

import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

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







class 	__lowerCAmelCase    (  TensorFormatter[Mapping, np.ndarray, Mapping]				):



     def __init__(self						,	lowerCAmelCase__=None						,	**lowerCAmelCase__	):
          super().__init__(features=lowerCAmelCase__	)
          _UpperCAmelCase					:  Any         =    np_array_kwargs



     def     snake_case_ (self						,	lowerCAmelCase__	):
          if isinstance(lowerCAmelCase__						,	lowerCAmelCase__	):
               if column and all(
                   isinstance(lowerCAmelCase__						,	np.ndarray	) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column	):
                    return np.stack(lowerCAmelCase__	)
               else:
                    # don't use np.array(column, dtype=object)
                    # since it fails in certain cases
                    # see https://stackoverflow.com/q/51005699
                    _UpperCAmelCase					:  Tuple         =    np.empty(len(lowerCAmelCase__	)						,	dtype=lowerCAmelCase__	)
                    _UpperCAmelCase					:  int         =    column
                    return out
          return column



     def     snake_case_ (self						,	lowerCAmelCase__	):
          if isinstance(lowerCAmelCase__						,	(str, bytes, type(lowerCAmelCase__	))	):
               return value
          elif isinstance(lowerCAmelCase__						,	(np.character, np.ndarray)	) and np.issubdtype(value.dtype						,	np.character	):
               return value
          elif isinstance(lowerCAmelCase__						,	np.number	):
               return value

          _UpperCAmelCase					:  str         =    {}

          if isinstance(lowerCAmelCase__						,	np.ndarray	) and np.issubdtype(value.dtype						,	np.integer	):
               _UpperCAmelCase					:  Tuple         =    {"""dtype""": np.intaa}
          elif isinstance(lowerCAmelCase__						,	np.ndarray	) and np.issubdtype(value.dtype						,	np.floating	):
               _UpperCAmelCase					:  Dict         =    {"""dtype""": np.floataa}
          elif config.PIL_AVAILABLE and "PIL" in sys.modules:
               import PIL.Image

               if isinstance(lowerCAmelCase__						,	PIL.Image.Image	):
                    return np.asarray(lowerCAmelCase__						,	**self.np_array_kwargs	)

          return np.asarray(lowerCAmelCase__						,	**{**default_dtype, **self.np_array_kwargs}	)



     def     snake_case_ (self						,	lowerCAmelCase__	):
          # support for torch, tf, jax etc.
          if config.TORCH_AVAILABLE and "torch" in sys.modules:
               import torch

               if isinstance(lowerCAmelCase__						,	torch.Tensor	):
                    return self._tensorize(data_struct.detach().cpu().numpy()[()]	)
          if hasattr(lowerCAmelCase__						,	"""__array__"""	) and not isinstance(lowerCAmelCase__						,	(np.ndarray, np.character, np.number)	):
               _UpperCAmelCase					:  List[str]         =    data_struct.__array__()
          # support for nested types like struct of list of struct
          if isinstance(lowerCAmelCase__						,	np.ndarray	):
               if data_struct.dtype == object:
                    return self._consolidate([self.recursive_tensorize(lowerCAmelCase__	) for substruct in data_struct]	)
          if isinstance(lowerCAmelCase__						,	(list, tuple)	):
               return self._consolidate([self.recursive_tensorize(lowerCAmelCase__	) for substruct in data_struct]	)
          return self._tensorize(lowerCAmelCase__	)



     def     snake_case_ (self						,	lowerCAmelCase__	):
          return map_nested(self._recursive_tensorize						,	lowerCAmelCase__						,	map_list=lowerCAmelCase__	)



     def     snake_case_ (self						,	lowerCAmelCase__	):
          _UpperCAmelCase					:  Optional[int]         =    self.numpy_arrow_extractor().extract_row(lowerCAmelCase__	)
          _UpperCAmelCase					:  List[Any]         =    self.python_features_decoder.decode_row(lowerCAmelCase__	)
          return self.recursive_tensorize(lowerCAmelCase__	)



     def     snake_case_ (self						,	lowerCAmelCase__	):
          _UpperCAmelCase					:  Optional[Any]         =    self.numpy_arrow_extractor().extract_column(lowerCAmelCase__	)
          _UpperCAmelCase					:  Optional[int]         =    self.python_features_decoder.decode_column(lowerCAmelCase__						,	pa_table.column_names[0]	)
          _UpperCAmelCase					:  Dict         =    self.recursive_tensorize(lowerCAmelCase__	)
          _UpperCAmelCase					:  List[str]         =    self._consolidate(lowerCAmelCase__	)
          return column



     def     snake_case_ (self						,	lowerCAmelCase__	):
          _UpperCAmelCase					:  str         =    self.numpy_arrow_extractor().extract_batch(lowerCAmelCase__	)
          _UpperCAmelCase					:  Dict         =    self.python_features_decoder.decode_batch(lowerCAmelCase__	)
          _UpperCAmelCase					:  str         =    self.recursive_tensorize(lowerCAmelCase__	)
          for column_name in batch:
               _UpperCAmelCase					:  str         =    self._consolidate(batch[column_name]	)
          return batch




'''simple docstring'''

from itertools import combinations, product







def __A  (    lowerCAmelCase_ ,       lowerCAmelCase_ ,       lowerCAmelCase_ ,       lowerCAmelCase_       ):
     if xa == ya == 0 or xa == ya == 0:
          return False
     _UpperCAmelCase					:  Any         =    xa * xa + ya * ya
     _UpperCAmelCase					:  Any         =    xa * xa + ya * ya
     _UpperCAmelCase					:  Tuple         =    (xa - xa) * (xa - xa) + (ya - ya) * (ya - ya)
     return (
         a_square + b_square == c_square
         or a_square + c_square == b_square
         or b_square + c_square == a_square
     )







def __A  (    lowerCAmelCase_ = 50       ):
     return sum(
         1
         for pta, pta in combinations(product(range(limit + 1       ) ,       repeat=2       ) ,       2       )
         if is_right(*lowerCAmelCase_ ,       *lowerCAmelCase_       )       )


if __name__ == "__main__":
   print(F"{solution() = }")


