



def    _snake_case (       __snake_case    )     ->     float:






      '''simple docstring'''







      return 1_0 - x * x







def    _snake_case (       __snake_case					,  __snake_case    )     ->     float:






      '''simple docstring'''







      if equation(__snake_case    ) * equation(__snake_case    ) >= 0:
            raise ValueError("Wrong space!"    )

      UpperCAmelCase_  :	int				      =		a
      while (b - a) >= 0.01:
            # Find middle point
            UpperCAmelCase_  :	List[str]				      =		(a + b) / 2
            # Check if middle point is root
            if equation(__snake_case    ) == 0.0:
                  break
            # Decide the side to repeat the steps
            if equation(__snake_case    ) * equation(__snake_case    ) < 0:
                  UpperCAmelCase_  :	Any				      =		c
            else:
                  UpperCAmelCase_  :	int				      =		c
      return c


if __name__ == "__main__":
   import doctest

   doctest.testmod()

   print(bisection(-2, 5))
   print(bisection(0, 6))





# 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 torch


class   snake_case_ (TensorFormatter[Mapping, """torch.Tensor""", Mapping]  ):




       """simple docstring"""






       def __init__(     self     ,lowercase=None     ,**lowercase):

             """simple docstring"""





             super().__init__(features=lowercase)
             UpperCAmelCase_  :	Union[str, Any]				      =		torch_tensor_kwargs
             import torch  # noqa import torch at initialization



       def  A_   (     self     ,lowercase):

             """simple docstring"""





             import torch

             if isinstance(lowercase     ,lowercase) and column:
                   if all(
                       isinstance(lowercase     ,torch.Tensor) and x.shape == column[0].shape and x.dtype == column[0].dtype
                       for x in column):
                         return torch.stack(lowercase)
             return column



       def  A_   (     self     ,lowercase):

             """simple docstring"""





             import torch

             if isinstance(lowercase     ,(str, bytes, type(lowercase))):
                   return value
             elif isinstance(lowercase     ,(np.character, np.ndarray)) and np.issubdtype(value.dtype     ,np.character):
                   return value.tolist()

             UpperCAmelCase_  :	List[str]				      =		{}

             if isinstance(lowercase     ,(np.number, np.ndarray)) and np.issubdtype(value.dtype     ,np.integer):
                   UpperCAmelCase_  :	Dict				      =		{"dtype": torch.intaa}
             elif isinstance(lowercase     ,(np.number, np.ndarray)) and np.issubdtype(value.dtype     ,np.floating):
                   UpperCAmelCase_  :	Optional[Any]				      =		{"dtype": torch.floataa}
             elif config.PIL_AVAILABLE and "PIL" in sys.modules:
                   import PIL.Image

                   if isinstance(lowercase     ,PIL.Image.Image):
                         UpperCAmelCase_  :	List[str]				      =		np.asarray(lowercase)
             return torch.tensor(lowercase     ,**{**default_dtype, **self.torch_tensor_kwargs})



       def  A_   (     self     ,lowercase):

             """simple docstring"""





             import torch

             # support for torch, tf, jax etc.
             if hasattr(lowercase     ,"__array__") and not isinstance(lowercase     ,torch.Tensor):
                   UpperCAmelCase_  :	int				      =		data_struct.__array__()
             # support for nested types like struct of list of struct
             if isinstance(lowercase     ,np.ndarray):
                   if data_struct.dtype == object:  # torch 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     ,lowercase):

             """simple docstring"""





             return map_nested(self._recursive_tensorize     ,lowercase     ,map_list=lowercase)



       def  A_   (     self     ,lowercase):

             """simple docstring"""





             UpperCAmelCase_  :	List[Any]				      =		self.numpy_arrow_extractor().extract_row(lowercase)
             UpperCAmelCase_  :	Tuple				      =		self.python_features_decoder.decode_row(lowercase)
             return self.recursive_tensorize(lowercase)



       def  A_   (     self     ,lowercase):

             """simple docstring"""





             UpperCAmelCase_  :	str				      =		self.numpy_arrow_extractor().extract_column(lowercase)
             UpperCAmelCase_  :	List[Any]				      =		self.python_features_decoder.decode_column(lowercase     ,pa_table.column_names[0])
             UpperCAmelCase_  :	List[Any]				      =		self.recursive_tensorize(lowercase)
             UpperCAmelCase_  :	List[str]				      =		self._consolidate(lowercase)
             return column



       def  A_   (     self     ,lowercase):

             """simple docstring"""





             UpperCAmelCase_  :	Any				      =		self.numpy_arrow_extractor().extract_batch(lowercase)
             UpperCAmelCase_  :	Optional[int]				      =		self.python_features_decoder.decode_batch(lowercase)
             UpperCAmelCase_  :	List[Any]				      =		self.recursive_tensorize(lowercase)
             for column_name in batch:
                   UpperCAmelCase_  :	Optional[int]				      =		self._consolidate(batch[column_name])
             return batch
