





'''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 torch
class 				a_       (    TensorFormatter[Mapping, "torch.Tensor", Mapping]							):





     def __init__(			self		: Optional[int]     ,				lowercase		: int=None     ,				**lowercase		: Any						):





        """simple docstring"""




        super().__init__(features=lowercase						)
        lowercase_      :int         =			torch_tensor_kwargs
        import torch  # noqa import torch at initialization





     def 							lowercase__				(			self		: List[Any]     ,				lowercase		: Union[str, Any]						):





        """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 							lowercase__				(			self		: Optional[int]     ,				lowercase		: str						):





        """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()

        lowercase_      :Dict         =			{}

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

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





     def 							lowercase__				(			self		: Tuple     ,				lowercase		: str						):





        """simple docstring"""




        import torch

        # support for torch, tf, jax etc.
        if hasattr(lowercase     ,				"__array__"						) and not isinstance(lowercase     ,				torch.Tensor						):
           lowercase_      :Optional[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 							lowercase__				(			self		: int     ,				lowercase		: dict						):





        """simple docstring"""




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





     def 							lowercase__				(			self		: Any     ,				lowercase		: pa.Table						):





        """simple docstring"""




        lowercase_      :Union[str, Any]         =			self.numpy_arrow_extractor().extract_row(lowercase						)
        lowercase_      :int         =			self.python_features_decoder.decode_row(lowercase						)
        return self.recursive_tensorize(lowercase						)





     def 							lowercase__				(			self		: Dict     ,				lowercase		: pa.Table						):





        """simple docstring"""




        lowercase_      :Tuple         =			self.numpy_arrow_extractor().extract_column(lowercase						)
        lowercase_      :List[Any]         =			self.python_features_decoder.decode_column(lowercase     ,				pa_table.column_names[0]						)
        lowercase_      :Optional[int]         =			self.recursive_tensorize(lowercase						)
        lowercase_      :Optional[Any]         =			self._consolidate(lowercase						)
        return column







     def 							lowercase__				(			self		: Any     ,				lowercase		: pa.Table						):





        """simple docstring"""




        lowercase_      :Dict         =			self.numpy_arrow_extractor().extract_batch(lowercase						)
        lowercase_      :Optional[int]         =			self.python_features_decoder.decode_batch(lowercase						)
        lowercase_      :Dict         =			self.recursive_tensorize(lowercase						)
        for column_name in batch:
           lowercase_      :Tuple         =			self._consolidate(batch[column_name]						)
        return batch









'''simple docstring'''


import numpy as np
def 							UpperCAmelCase_  (						__lowerCamelCase : str     ,__lowerCamelCase : Optional[Any]     ,__lowerCamelCase : int     ,__lowerCamelCase : List[str]     ,__lowerCamelCase : List[Any]			):
   lowercase_      :Dict         =			int(np.ceil((x_end - xa) / h			)			)
   lowercase_      :Optional[int]         =			np.zeros((n + 1,)			)
   lowercase_      :Tuple         =			ya
   lowercase_      :List[str]         =			xa

   for k in range(__lowerCamelCase			):
      lowercase_      :Any         =			f(__lowerCamelCase     ,y[k]			)
      lowercase_      :Optional[Any]         =			f(x + 0.5 * h     ,y[k] + 0.5 * h * ka			)
      lowercase_      :Optional[Any]         =			f(x + 0.5 * h     ,y[k] + 0.5 * h * ka			)
      lowercase_      :Any         =			f(x + h     ,y[k] + h * ka			)
      lowercase_      :Tuple         =			y[k] + (1 / 6) * h * (ka + 2 * ka + 2 * ka + ka)
      x += h

   return y


if __name__ == "__main__":
 import doctest

 doctest.testmod()


