



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A_		:  Any										=  {'''configuration_visual_bert''': ['''VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''VisualBertConfig''']}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     A_		:  int										=  [
         '''VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''VisualBertForMultipleChoice''',
         '''VisualBertForPreTraining''',
         '''VisualBertForQuestionAnswering''',
         '''VisualBertForRegionToPhraseAlignment''',
         '''VisualBertForVisualReasoning''',
         '''VisualBertLayer''',
         '''VisualBertModel''',
         '''VisualBertPreTrainedModel''',
     ]


if TYPE_CHECKING:
     from .configuration_visual_bert import VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, VisualBertConfig

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_visual_bert import (
              VISUAL_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
              VisualBertForMultipleChoice,
              VisualBertForPreTraining,
              VisualBertForQuestionAnswering,
              VisualBertForRegionToPhraseAlignment,
              VisualBertForVisualReasoning,
              VisualBertLayer,
              VisualBertModel,
              VisualBertPreTrainedModel,
          )


else:
     import sys

     A_		:  Optional[int]										=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




def 				__a							(       __A			,							__A			,							__A			,							__A						):
    return len_board * len_board_column * row + column





def 				__a							(       __A			,							__A			,							__A			,							__A			,							__A			,							__A			,							):

    if board[row][column] != word[word_index]:
        return False

    if word_index == len(__A						) - 1:
        return True

    SCREAMING_SNAKE_CASE__         =    [(0, 1), (0, -1), (-1, 0), (1, 0)]
    SCREAMING_SNAKE_CASE__         =    len(__A						)
    SCREAMING_SNAKE_CASE__         =    len(board[0]						)
    for direction in traverts_directions:
        SCREAMING_SNAKE_CASE__         =    row + direction[0]
        SCREAMING_SNAKE_CASE__         =    column + direction[1]
        if not (0 <= next_i < len_board and 0 <= next_j < len_board_column):
            continue

        SCREAMING_SNAKE_CASE__         =    get_point_key(__A			,							__A			,							__A			,							__A						)
        if key in visited_points_set:
            continue

        visited_points_set.add(__A						)
        if exits_word(__A			,							__A			,							__A			,							__A			,							word_index + 1			,							__A						):
            return True

        visited_points_set.remove(__A						)

    return False





def 				__a							(       __A			,							__A						):
    SCREAMING_SNAKE_CASE__         =    (
        "The board should be a non empty matrix of single chars strings."
    )

    SCREAMING_SNAKE_CASE__         =    len(__A						)
    if not isinstance(__A			,							__A						) or len(__A						) == 0:
        raise ValueError(__A						)

    for row in board:
        if not isinstance(__A			,							__A						) or len(__A						) == 0:
            raise ValueError(__A						)

        for item in row:
            if not isinstance(__A			,							__A						) or len(__A						) != 1:
                raise ValueError(__A						)

    # Validate word
    if not isinstance(__A			,							__A						) or len(__A						) == 0:
        raise ValueError(
            "The word parameter should be a string of length greater than 0."						)

    SCREAMING_SNAKE_CASE__         =    len(board[0]						)
    for i in range(__A						):
        for j in range(__A						):
            if exits_word(
                __A			,							__A			,							__A			,							__A			,							0			,							{get_point_key(__A			,							__A			,							__A			,							__A						)}						):
                return True

    return False


if __name__ == "__main__":
  import doctest

  doctest.testmod()


