

"""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]				):



    """simple docstring"""



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






         """simple docstring"""


         super().__init__(features=UpperCamelCase       )
         A__										=  torch_tensor_kwargs
         import torch  # noqa import torch at initialization

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






         """simple docstring"""


         import torch

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

    def 				UpperCamelCase	(     self: Any    ,						UpperCamelCase: int       ):






         """simple docstring"""


         import torch

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

         A__										=  {}

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

              if isinstance(UpperCamelCase    ,						PIL.Image.Image       ):
                   A__										=  np.asarray(UpperCamelCase       )
         return torch.tensor(UpperCamelCase    ,						**{**default_dtype, **self.torch_tensor_kwargs}       )

    def 				UpperCamelCase	(     self: Any    ,						UpperCamelCase: Any       ):






         """simple docstring"""


         import torch

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

    def 				UpperCamelCase	(     self: List[str]    ,						UpperCamelCase: dict       ):






         """simple docstring"""


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

    def 				UpperCamelCase	(     self: Union[str, Any]    ,						UpperCamelCase: pa.Table       ):






         """simple docstring"""


         A__										=  self.numpy_arrow_extractor().extract_row(UpperCamelCase       )
         A__										=  self.python_features_decoder.decode_row(UpperCamelCase       )
         return self.recursive_tensorize(UpperCamelCase       )

    def 				UpperCamelCase	(     self: Union[str, Any]    ,						UpperCamelCase: pa.Table       ):






         """simple docstring"""


         A__										=  self.numpy_arrow_extractor().extract_column(UpperCamelCase       )
         A__										=  self.python_features_decoder.decode_column(UpperCamelCase    ,						pa_table.column_names[0]       )
         A__										=  self.recursive_tensorize(UpperCamelCase       )
         A__										=  self._consolidate(UpperCamelCase       )
         return column





    def 				UpperCamelCase	(     self: Any    ,						UpperCamelCase: pa.Table       ):






         """simple docstring"""


         A__										=  self.numpy_arrow_extractor().extract_batch(UpperCamelCase       )
         A__										=  self.python_features_decoder.decode_batch(UpperCamelCase       )
         A__										=  self.recursive_tensorize(UpperCamelCase       )
         for column_name in batch:
              A__										=  self._consolidate(batch[column_name]       )
         return batch









"""simple docstring"""



from __future__ import annotations



class 					a						:



    """simple docstring"""



    def __init__(     self: Any    ,						UpperCamelCase: str    ,						UpperCamelCase: str       ):






         """simple docstring"""


         A__			,				A__										=  text, pattern
         A__			,				A__										=  len(UpperCamelCase       ), len(UpperCamelCase       )

    def 				UpperCamelCase	(     self: Dict    ,						UpperCamelCase: str       ):






         """simple docstring"""


         for i in range(self.patLen - 1    ,						-1    ,						-1       ):
              if char == self.pattern[i]:
                   return i
         return -1

    def 				UpperCamelCase	(     self: str    ,						UpperCamelCase: int       ):






         """simple docstring"""


         for i in range(self.patLen - 1    ,						-1    ,						-1       ):
              if self.pattern[i] != self.text[current_pos + i]:
                   return current_pos + i
         return -1





    def 				UpperCamelCase	(     self: List[Any]       ):






         """simple docstring"""


         A__										=  []
         for i in range(self.textLen - self.patLen + 1       ):
              A__										=  self.mismatch_in_text(UpperCamelCase       )
              if mismatch_index == -1:
                   positions.append(UpperCamelCase       )
              else:
                   A__										=  self.match_in_pattern(self.text[mismatch_index]       )
                   A__										=  (
                       mismatch_index - match_index
                   )  # shifting index lgtm [py/multiple-definition]
         return positions

SCREAMING_SNAKE_CASE_					:	List[Any]							  =						'ABAABA'
SCREAMING_SNAKE_CASE_					:	List[Any]							  =						'AB'
SCREAMING_SNAKE_CASE_					:	Union[str, Any]							  =						BoyerMooreSearch(text, pattern)
SCREAMING_SNAKE_CASE_					:	int							  =						bms.bad_character_heuristic()

if len(positions) == 0:
 print('No match found')
else:
 print('Pattern found in following positions: ')
 print(positions)






