






from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFImageClassifierOutputWithNoAttention,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging
from .configuration_resnet import ResNetConfig


__UpperCAmelCase										=		logging.get_logger(__name__)

# General docstring
__UpperCAmelCase										=		'ResNetConfig'

# Base docstring
__UpperCAmelCase										=		'microsoft/resnet-50'
__UpperCAmelCase										=		[1, 2048, 7, 7]

# Image classification docstring
__UpperCAmelCase										=		'microsoft/resnet-50'
__UpperCAmelCase										=		'tiger cat'

__UpperCAmelCase										=		[
    'microsoft/resnet-50',
    # See all resnet models at https://huggingface.co/models?filter=resnet
]



class 						lowerCamelCase   (tf.keras.layers.Layer    ):







		'''simple docstring'''



		def __init__(							self       ,	_UpperCamelCase       ,	_UpperCamelCase = 3       ,	_UpperCamelCase = 1       ,	_UpperCamelCase = "relu"       ,	**_UpperCamelCase     )			->							None:
							super().__init__(**_UpperCamelCase     )
							UpperCAmelCase_					:   Dict   =		kernel_size // 2
							UpperCAmelCase_					:   Any   =		tf.keras.layers.ConvaD(
							    _UpperCamelCase       ,	kernel_size=_UpperCamelCase       ,	strides=_UpperCamelCase       ,	padding='valid'       ,	use_bias=_UpperCamelCase       ,	name='convolution'     )
							# Use same default momentum and epsilon as PyTorch equivalent
							UpperCAmelCase_					:   Dict   =		tf.keras.layers.BatchNormalization(epsilon=1E-5       ,	momentum=0.9       ,	name='normalization'     )
							UpperCAmelCase_					:   List[str]   =		ACTaFN[activation] if activation is not None else tf.keras.layers.Activation('linear'     )



		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase     )			->							tf.Tensor:
							# Pad to match that done in the PyTorch Conv2D model
							UpperCAmelCase_					:   List[Any]   =		(self.pad_value, self.pad_value)
							UpperCAmelCase_					:   Union[str, Any]   =		tf.pad(_UpperCamelCase       ,	[(0, 0), height_pad, width_pad, (0, 0)]     )
							UpperCAmelCase_					:   Any   =		self.conv(_UpperCamelCase     )
							return hidden_state



		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase       ,	_UpperCamelCase = False     )			->							tf.Tensor:
							UpperCAmelCase_					:   Union[str, Any]   =		self.convolution(_UpperCamelCase     )
							UpperCAmelCase_					:   Dict   =		self.normalization(_UpperCamelCase       ,	training=_UpperCamelCase     )
							UpperCAmelCase_					:   Dict   =		self.activation(_UpperCamelCase     )
							return hidden_state





class 						lowerCamelCase   (tf.keras.layers.Layer    ):







		'''simple docstring'''



		def __init__(							self       ,	_UpperCamelCase       ,	**_UpperCamelCase     )			->							None:
							super().__init__(**_UpperCamelCase     )
							UpperCAmelCase_					:   Any   =		TFResNetConvLayer(
							    config.embedding_size       ,	kernel_size=7       ,	stride=2       ,	activation=config.hidden_act       ,	name='embedder'       ,	)
							UpperCAmelCase_					:   List[str]   =		tf.keras.layers.MaxPoolaD(pool_size=3       ,	strides=2       ,	padding='valid'       ,	name='pooler'     )
							UpperCAmelCase_					:   str   =		config.num_channels



		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase       ,	_UpperCamelCase = False     )			->							tf.Tensor:
							UpperCAmelCase_ ,						UpperCAmelCase_ ,						UpperCAmelCase_ ,						UpperCAmelCase_					:   Optional[int]   =		shape_list(_UpperCamelCase     )
							if tf.executing_eagerly() and num_channels != self.num_channels:
												raise ValueError(
												    'Make sure that the channel dimension of the pixel values match with the one set in the configuration.'     )
							UpperCAmelCase_					:   Optional[int]   =		pixel_values
							UpperCAmelCase_					:   Tuple   =		self.embedder(_UpperCamelCase     )
							UpperCAmelCase_					:   Optional[int]   =		tf.pad(_UpperCamelCase       ,	[[0, 0], [1, 1], [1, 1], [0, 0]]     )
							UpperCAmelCase_					:   Any   =		self.pooler(_UpperCamelCase     )
							return hidden_state





class 						lowerCamelCase   (tf.keras.layers.Layer    ):







		'''simple docstring'''



		def __init__(							self       ,	_UpperCamelCase       ,	_UpperCamelCase = 2       ,	**_UpperCamelCase     )			->							None:
							super().__init__(**_UpperCamelCase     )
							UpperCAmelCase_					:   List[str]   =		tf.keras.layers.ConvaD(
							    _UpperCamelCase       ,	kernel_size=1       ,	strides=_UpperCamelCase       ,	use_bias=_UpperCamelCase       ,	name='convolution'     )
							# Use same default momentum and epsilon as PyTorch equivalent
							UpperCAmelCase_					:   List[Any]   =		tf.keras.layers.BatchNormalization(epsilon=1E-5       ,	momentum=0.9       ,	name='normalization'     )



		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase       ,	_UpperCamelCase = False     )			->							tf.Tensor:
							UpperCAmelCase_					:   int   =		x
							UpperCAmelCase_					:   Optional[int]   =		self.convolution(_UpperCamelCase     )
							UpperCAmelCase_					:   Union[str, Any]   =		self.normalization(_UpperCamelCase       ,	training=_UpperCamelCase     )
							return hidden_state





class 						lowerCamelCase   (tf.keras.layers.Layer    ):







		'''simple docstring'''



		def __init__(							self       ,	_UpperCamelCase       ,	_UpperCamelCase       ,	_UpperCamelCase = 1       ,	_UpperCamelCase = "relu"       ,	**_UpperCamelCase     )			->							None:
							super().__init__(**_UpperCamelCase     )
							UpperCAmelCase_					:   Union[str, Any]   =		in_channels != out_channels or stride != 1
							UpperCAmelCase_					:   Optional[Any]   =		TFResNetConvLayer(_UpperCamelCase       ,	stride=_UpperCamelCase       ,	name='layer.0'     )
							UpperCAmelCase_					:   Tuple   =		TFResNetConvLayer(_UpperCamelCase       ,	activation=_UpperCamelCase       ,	name='layer.1'     )
							UpperCAmelCase_					:   int   =		(
							    TFResNetShortCut(_UpperCamelCase       ,	stride=_UpperCamelCase       ,	name='shortcut'     )
							    if should_apply_shortcut
							    else tf.keras.layers.Activation('linear'       ,	name='shortcut'     )
							)
							UpperCAmelCase_					:   int   =		ACTaFN[activation]



		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase       ,	_UpperCamelCase = False     )			->							tf.Tensor:
							UpperCAmelCase_					:   Any   =		hidden_state
							UpperCAmelCase_					:   int   =		self.conva(_UpperCamelCase       ,	training=_UpperCamelCase     )
							UpperCAmelCase_					:   Dict   =		self.conva(_UpperCamelCase       ,	training=_UpperCamelCase     )
							UpperCAmelCase_					:   Union[str, Any]   =		self.shortcut(_UpperCamelCase       ,	training=_UpperCamelCase     )
							hidden_state += residual
							UpperCAmelCase_					:   List[str]   =		self.activation(_UpperCamelCase     )
							return hidden_state





class 						lowerCamelCase   (tf.keras.layers.Layer    ):







		'''simple docstring'''



		def __init__(							self       ,	_UpperCamelCase       ,	_UpperCamelCase       ,	_UpperCamelCase = 1       ,	_UpperCamelCase = "relu"       ,	_UpperCamelCase = 4       ,	**_UpperCamelCase       ,	)			->							None:
							super().__init__(**_UpperCamelCase     )
							UpperCAmelCase_					:   Optional[Any]   =		in_channels != out_channels or stride != 1
							UpperCAmelCase_					:   Union[str, Any]   =		out_channels // reduction
							UpperCAmelCase_					:   int   =		TFResNetConvLayer(_UpperCamelCase       ,	kernel_size=1       ,	name='layer.0'     )
							UpperCAmelCase_					:   Optional[int]   =		TFResNetConvLayer(_UpperCamelCase       ,	stride=_UpperCamelCase       ,	name='layer.1'     )
							UpperCAmelCase_					:   int   =		TFResNetConvLayer(_UpperCamelCase       ,	kernel_size=1       ,	activation=_UpperCamelCase       ,	name='layer.2'     )
							UpperCAmelCase_					:   List[str]   =		(
							    TFResNetShortCut(_UpperCamelCase       ,	stride=_UpperCamelCase       ,	name='shortcut'     )
							    if should_apply_shortcut
							    else tf.keras.layers.Activation('linear'       ,	name='shortcut'     )
							)
							UpperCAmelCase_					:   Optional[int]   =		ACTaFN[activation]



		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase       ,	_UpperCamelCase = False     )			->							tf.Tensor:
							UpperCAmelCase_					:   int   =		hidden_state
							UpperCAmelCase_					:   List[Any]   =		self.conva(_UpperCamelCase       ,	training=_UpperCamelCase     )
							UpperCAmelCase_					:   str   =		self.conva(_UpperCamelCase       ,	training=_UpperCamelCase     )
							UpperCAmelCase_					:   str   =		self.conva(_UpperCamelCase       ,	training=_UpperCamelCase     )
							UpperCAmelCase_					:   Any   =		self.shortcut(_UpperCamelCase       ,	training=_UpperCamelCase     )
							hidden_state += residual
							UpperCAmelCase_					:   int   =		self.activation(_UpperCamelCase     )
							return hidden_state





class 						lowerCamelCase   (tf.keras.layers.Layer    ):







		'''simple docstring'''



		def __init__(							self       ,	_UpperCamelCase       ,	_UpperCamelCase       ,	_UpperCamelCase       ,	_UpperCamelCase = 2       ,	_UpperCamelCase = 2       ,	**_UpperCamelCase     )			->							None:
							super().__init__(**_UpperCamelCase     )

							UpperCAmelCase_					:   int   =		TFResNetBottleNeckLayer if config.layer_type == 'bottleneck' else TFResNetBasicLayer

							UpperCAmelCase_					:   int   =		[layer(_UpperCamelCase       ,	_UpperCamelCase       ,	stride=_UpperCamelCase       ,	activation=config.hidden_act       ,	name='layers.0'     )]
							layers += [
							    layer(_UpperCamelCase       ,	_UpperCamelCase       ,	activation=config.hidden_act       ,	name=f"layers.{i + 1}"     )
							    for i in range(depth - 1     )
							]
							UpperCAmelCase_					:   Dict   =		layers



		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase       ,	_UpperCamelCase = False     )			->							tf.Tensor:
							for layer in self.stage_layers:
												UpperCAmelCase_					:   List[Any]   =		layer(_UpperCamelCase       ,	training=_UpperCamelCase     )
							return hidden_state





class 						lowerCamelCase   (tf.keras.layers.Layer    ):







		'''simple docstring'''



		def __init__(							self       ,	_UpperCamelCase       ,	**_UpperCamelCase     )			->							None:
							super().__init__(**_UpperCamelCase     )
							# based on `downsample_in_first_stage` the first layer of the first stage may or may not downsample the input
							UpperCAmelCase_					:   Optional[int]   =		[
							    TFResNetStage(
							        _UpperCamelCase       ,	config.embedding_size       ,	config.hidden_sizes[0]       ,	stride=2 if config.downsample_in_first_stage else 1       ,	depth=config.depths[0]       ,	name='stages.0'       ,	)
							]
							for i, (in_channels, out_channels, depth) in enumerate(
							    zip(config.hidden_sizes       ,	config.hidden_sizes[1:]       ,	config.depths[1:]     )     ):
												self.stages.append(TFResNetStage(_UpperCamelCase       ,	_UpperCamelCase       ,	_UpperCamelCase       ,	depth=_UpperCamelCase       ,	name=f"stages.{i + 1}"     )     )



		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase       ,	_UpperCamelCase = False       ,	_UpperCamelCase = True       ,	_UpperCamelCase = False       ,	)			->							TFBaseModelOutputWithNoAttention:
							UpperCAmelCase_					:   Union[str, Any]   =		() if output_hidden_states else None

							for stage_module in self.stages:
												if output_hidden_states:
																	UpperCAmelCase_					:   int   =		hidden_states + (hidden_state,)

												UpperCAmelCase_					:   Dict   =		stage_module(_UpperCamelCase       ,	training=_UpperCamelCase     )

							if output_hidden_states:
												UpperCAmelCase_					:   str   =		hidden_states + (hidden_state,)

							if not return_dict:
												return tuple(v for v in [hidden_state, hidden_states] if v is not None     )

							return TFBaseModelOutputWithNoAttention(last_hidden_state=_UpperCamelCase       ,	hidden_states=_UpperCamelCase     )





class 						lowerCamelCase   (_snake_case    ):







		'''simple docstring'''



		_snake_case					:					Optional[Any] 		=						ResNetConfig
		_snake_case					:					List[str] 		=						'''resnet'''
		_snake_case					:					Dict 		=						'''pixel_values'''



		@property
		def       __UpperCAmelCase    (							self     )			->							Any:
							return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 2_2_4, 2_2_4)       ,	dtype=tf.floataa     )}





__UpperCAmelCase										=		R'\n    This model is a TensorFlow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular TensorFlow Module and refer to the TensorFlow documentation for all matter related to general usage and\n    behavior.\n\n    Parameters:\n        config ([`ResNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n'


__UpperCAmelCase										=		R'\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConvNextImageProcessor.__call__`] for details.\n\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n'



@keras_serializable
class 						lowerCamelCase   (tf.keras.layers.Layer    ):







		'''simple docstring'''



		_snake_case					:					Dict 		=						ResNetConfig



		def __init__(							self       ,	_UpperCamelCase       ,	**_UpperCamelCase     )			->							None:
							super().__init__(**_UpperCamelCase     )
							UpperCAmelCase_					:   int   =		config
							UpperCAmelCase_					:   Dict   =		TFResNetEmbeddings(_UpperCamelCase       ,	name='embedder'     )
							UpperCAmelCase_					:   Tuple   =		TFResNetEncoder(_UpperCamelCase       ,	name='encoder'     )
							UpperCAmelCase_					:   Union[str, Any]   =		tf.keras.layers.GlobalAveragePoolingaD(keepdims=_UpperCamelCase     )



		@unpack_inputs
		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase       ,	_UpperCamelCase = None       ,	_UpperCamelCase = None       ,	_UpperCamelCase = False       ,	)			->							Union[Tuple[tf.Tensor], TFBaseModelOutputWithPoolingAndNoAttention]:
							UpperCAmelCase_					:   Optional[int]   =		(
							    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
							)
							UpperCAmelCase_					:   Optional[int]   =		return_dict if return_dict is not None else self.config.use_return_dict

							# TF 2.0 image layers can't use NCHW format when running on CPU.
							# We transpose to NHWC format and then transpose back after the full forward pass.
							# (batch_size, num_channels, height, width) -> (batch_size, height, width, num_channels)
							UpperCAmelCase_					:   Optional[int]   =		tf.transpose(_UpperCamelCase       ,	perm=[0, 2, 3, 1]     )
							UpperCAmelCase_					:   List[str]   =		self.embedder(_UpperCamelCase       ,	training=_UpperCamelCase     )

							UpperCAmelCase_					:   List[str]   =		self.encoder(
							    _UpperCamelCase       ,	output_hidden_states=_UpperCamelCase       ,	return_dict=_UpperCamelCase       ,	training=_UpperCamelCase     )

							UpperCAmelCase_					:   Tuple   =		encoder_outputs[0]

							UpperCAmelCase_					:   Tuple   =		self.pooler(_UpperCamelCase     )

							# Transpose all the outputs to the NCHW format
							# (batch_size, height, width, num_channels) -> (batch_size, num_channels, height, width)
							UpperCAmelCase_					:   List[str]   =		tf.transpose(_UpperCamelCase       ,	(0, 3, 1, 2)     )
							UpperCAmelCase_					:   Dict   =		tf.transpose(_UpperCamelCase       ,	(0, 3, 1, 2)     )
							UpperCAmelCase_					:   Union[str, Any]   =		()
							for hidden_state in encoder_outputs[1:]:
												UpperCAmelCase_					:   List[Any]   =		hidden_states + tuple(tf.transpose(_UpperCamelCase       ,	(0, 3, 1, 2)     ) for h in hidden_state     )

							if not return_dict:
												return (last_hidden_state, pooled_output) + hidden_states

							UpperCAmelCase_					:   Union[str, Any]   =		hidden_states if output_hidden_states else None

							return TFBaseModelOutputWithPoolingAndNoAttention(
							    last_hidden_state=_UpperCamelCase       ,	pooler_output=_UpperCamelCase       ,	hidden_states=_UpperCamelCase       ,	)





@add_start_docstrings(
    '''The bare ResNet model outputting raw features without any specific head on top.'''				,						_snake_case				,						)
class 						lowerCamelCase   (_snake_case    ):







		'''simple docstring'''



		def __init__(							self       ,	_UpperCamelCase       ,	**_UpperCamelCase     )			->							None:
							super().__init__(_UpperCamelCase       ,	**_UpperCamelCase     )
							UpperCAmelCase_					:   int   =		TFResNetMainLayer(config=_UpperCamelCase       ,	name='resnet'     )



		@add_start_docstrings_to_model_forward(_UpperCamelCase     )
		@add_code_sample_docstrings(
		    checkpoint=_CHECKPOINT_FOR_DOC       ,	output_type=_UpperCamelCase       ,	config_class=_CONFIG_FOR_DOC       ,	modality='vision'       ,	expected_output=_EXPECTED_OUTPUT_SHAPE       ,	)
		@unpack_inputs
		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase       ,	_UpperCamelCase = None       ,	_UpperCamelCase = None       ,	_UpperCamelCase = False       ,	)			->							Union[Tuple[tf.Tensor], TFBaseModelOutputWithPoolingAndNoAttention]:
							UpperCAmelCase_					:   int   =		(
							    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
							)
							UpperCAmelCase_					:   List[Any]   =		return_dict if return_dict is not None else self.config.use_return_dict

							UpperCAmelCase_					:   List[str]   =		self.resnet(
							    pixel_values=_UpperCamelCase       ,	output_hidden_states=_UpperCamelCase       ,	return_dict=_UpperCamelCase       ,	training=_UpperCamelCase       ,	)
							return resnet_outputs





@add_start_docstrings(
    '''
    ResNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    '''				,						_snake_case				,						)
class 						lowerCamelCase   (_snake_case				,						_snake_case    ):







		'''simple docstring'''



		def __init__(							self       ,	_UpperCamelCase       ,	**_UpperCamelCase     )			->							None:
							super().__init__(_UpperCamelCase       ,	**_UpperCamelCase     )
							UpperCAmelCase_					:   int   =		config.num_labels
							UpperCAmelCase_					:   Dict   =		TFResNetMainLayer(_UpperCamelCase       ,	name='resnet'     )
							# classification head
							UpperCAmelCase_					:   Any   =		(
							    tf.keras.layers.Dense(config.num_labels       ,	name='classifier.1'     )
							    if config.num_labels > 0
							    else tf.keras.layers.Activation('linear'       ,	name='classifier.1'     )
							)



		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase     )			->							tf.Tensor:
							UpperCAmelCase_					:   int   =		tf.keras.layers.Flatten()(_UpperCamelCase     )
							UpperCAmelCase_					:   List[str]   =		self.classifier_layer(_UpperCamelCase     )
							return logits



		@add_start_docstrings_to_model_forward(_UpperCamelCase     )
		@add_code_sample_docstrings(
		    checkpoint=_IMAGE_CLASS_CHECKPOINT       ,	output_type=_UpperCamelCase       ,	config_class=_CONFIG_FOR_DOC       ,	expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT       ,	)
		@unpack_inputs
		def       __UpperCAmelCase    (							self       ,	_UpperCamelCase = None       ,	_UpperCamelCase = None       ,	_UpperCamelCase = None       ,	_UpperCamelCase = None       ,	_UpperCamelCase = False       ,	)			->							Union[Tuple[tf.Tensor], TFImageClassifierOutputWithNoAttention]:
							UpperCAmelCase_					:   Any   =		return_dict if return_dict is not None else self.config.use_return_dict

							UpperCAmelCase_					:   int   =		self.resnet(
							    _UpperCamelCase       ,	output_hidden_states=_UpperCamelCase       ,	return_dict=_UpperCamelCase       ,	training=_UpperCamelCase     )

							UpperCAmelCase_					:   Any   =		outputs.pooler_output if return_dict else outputs[1]

							UpperCAmelCase_					:   str   =		self.classifier(_UpperCamelCase     )

							UpperCAmelCase_					:   List[str]   =		None if labels is None else self.hf_compute_loss(_UpperCamelCase       ,	_UpperCamelCase     )

							if not return_dict:
												UpperCAmelCase_					:   Union[str, Any]   =		(logits,) + outputs[2:]
												return (loss,) + output if loss is not None else output

							return TFImageClassifierOutputWithNoAttention(loss=_UpperCamelCase       ,	logits=_UpperCamelCase       ,	hidden_states=outputs.hidden_states     )














def   lowercase__   (  __snake_case					:							int  , __snake_case					:							int  , __snake_case					:							int  , __snake_case					:							int						):


					'''simple docstring'''


					return len_board * len_board_column * row + column




def   lowercase__   (  __snake_case					:							list[list[str]]  , __snake_case					:							str  , __snake_case					:							int  , __snake_case					:							int  , __snake_case					:							int  , __snake_case					:							set[int]  , ):


					'''simple docstring'''


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

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

					UpperCAmelCase_					:   Dict   =		[(0, 1), (0, -1), (-1, 0), (1, 0)]
					UpperCAmelCase_					:   Union[str, Any]   =		len(__snake_case						)
					UpperCAmelCase_					:   List[Any]   =		len(board[0]						)
					for direction in traverts_directions:
										UpperCAmelCase_					:   Optional[int]   =		row + direction[0]
										UpperCAmelCase_					:   Optional[int]   =		column + direction[1]
										if not (0 <= next_i < len_board and 0 <= next_j < len_board_column):
															continue

										UpperCAmelCase_					:   Tuple   =		get_point_key(__snake_case  , __snake_case  , __snake_case  , __snake_case						)
										if key in visited_points_set:
															continue

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

										visited_points_set.remove(__snake_case						)

					return False




def   lowercase__   (  __snake_case					:							list[list[str]]  , __snake_case					:							str						):


					'''simple docstring'''


					UpperCAmelCase_					:   Any   =		(
					    'The board should be a non empty matrix of single chars strings.'
					)

					UpperCAmelCase_					:   Optional[Any]   =		len(__snake_case						)
					if not isinstance(__snake_case  , __snake_case						) or len(__snake_case						) == 0:
										raise ValueError(__snake_case						)

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

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

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

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

					return False


if __name__ == "__main__":
		import doctest

		doctest.testmod()






