"""simple docstring"""







import functools
import operator

from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE									=						logging.get_logger(__name__)

SCREAMING_SNAKE_CASE									=						{
    'microsoft/unispeech-large-1500h-cv': (
        'https://huggingface.co/microsoft/unispeech-large-1500h-cv/resolve/main/config.json'
    ),
    # See all UniSpeech models at https://huggingface.co/models?filter=unispeech
}



class  _lowerCamelCase			(__A     ):
				_snake_case     =  "unispeech"







				def __init__( self    :       List[str]			,					lowerCamelCase_    :       List[Any]=3_2			,					lowerCamelCase_    :       Tuple=7_6_8			,					lowerCamelCase_    :       int=1_2			,					lowerCamelCase_    :       Any=1_2			,					lowerCamelCase_    :       Union[str, Any]=3_0_7_2			,					lowerCamelCase_    :       Optional[Any]="gelu"			,					lowerCamelCase_    :       Union[str, Any]=0.1			,					lowerCamelCase_    :       Union[str, Any]=0.1			,					lowerCamelCase_    :       List[str]=0.1			,					lowerCamelCase_    :       Union[str, Any]=0.0			,					lowerCamelCase_    :       Dict=0.0			,					lowerCamelCase_    :       str=0.1			,					lowerCamelCase_    :       Any=0.1			,					lowerCamelCase_    :       Union[str, Any]=0.02			,					lowerCamelCase_    :       str=1E-5			,					lowerCamelCase_    :       Tuple="group"			,					lowerCamelCase_    :       int="gelu"			,					lowerCamelCase_    :       Optional[int]=(5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2, 5_1_2)			,					lowerCamelCase_    :       List[Any]=(5, 2, 2, 2, 2, 2, 2)			,					lowerCamelCase_    :       Tuple=(1_0, 3, 3, 3, 3, 2, 2)			,					lowerCamelCase_    :       str=False			,					lowerCamelCase_    :       Optional[int]=1_2_8			,					lowerCamelCase_    :       Tuple=1_6			,					lowerCamelCase_    :       Any=False			,					lowerCamelCase_    :       Dict=True			,					lowerCamelCase_    :       Union[str, Any]=0.05			,					lowerCamelCase_    :       Optional[Any]=1_0			,					lowerCamelCase_    :       Any=2			,					lowerCamelCase_    :       str=0.0			,					lowerCamelCase_    :       List[Any]=1_0			,					lowerCamelCase_    :       List[str]=0			,					lowerCamelCase_    :       str=3_2_0			,					lowerCamelCase_    :       Optional[Any]=2			,					lowerCamelCase_    :       Tuple=0.1			,					lowerCamelCase_    :       str=1_0_0			,					lowerCamelCase_    :       Union[str, Any]=2_5_6			,					lowerCamelCase_    :       Any=2_5_6			,					lowerCamelCase_    :       Any=0.1			,					lowerCamelCase_    :       Any="mean"			,					lowerCamelCase_    :       int=False			,					lowerCamelCase_    :       Tuple=False			,					lowerCamelCase_    :       List[str]=2_5_6			,					lowerCamelCase_    :       Union[str, Any]=8_0			,					lowerCamelCase_    :       Any=0			,					lowerCamelCase_    :       str=1			,					lowerCamelCase_    :       Any=2			,					lowerCamelCase_    :       List[str]=0.5			,					**lowerCamelCase_    :       Tuple			,					):

					"""simple docstring"""






					super().__init__(**lowerCamelCase_			,					pad_token_id=lowerCamelCase_			,					bos_token_id=lowerCamelCase_			,					eos_token_id=lowerCamelCase_						)
					_lowercase :    Dict							=							hidden_size
					_lowercase :    Dict							=							feat_extract_norm
					_lowercase :    List[Any]							=							feat_extract_activation
					_lowercase :    Optional[int]							=							list(lowerCamelCase_						)
					_lowercase :    Any							=							list(lowerCamelCase_						)
					_lowercase :    Optional[int]							=							list(lowerCamelCase_						)
					_lowercase :    str							=							conv_bias
					_lowercase :    Any							=							num_conv_pos_embeddings
					_lowercase :    List[str]							=							num_conv_pos_embedding_groups
					_lowercase :    List[Any]							=							len(self.conv_dim						)
					_lowercase :    List[str]							=							num_hidden_layers
					_lowercase :    List[str]							=							intermediate_size
					_lowercase :    str							=							hidden_act
					_lowercase :    int							=							num_attention_heads
					_lowercase :    str							=							hidden_dropout
					_lowercase :    List[str]							=							attention_dropout
					_lowercase :    Tuple							=							activation_dropout
					_lowercase :    Optional[Any]							=							feat_proj_dropout
					_lowercase :    Optional[Any]							=							final_dropout
					_lowercase :    Union[str, Any]							=							layerdrop
					_lowercase :    int							=							layer_norm_eps
					_lowercase :    int							=							initializer_range
					_lowercase :    Any							=							num_ctc_classes
					_lowercase :    Optional[int]							=							vocab_size
					_lowercase :    Optional[Any]							=							do_stable_layer_norm
					_lowercase :    Union[str, Any]							=							use_weighted_layer_sum
					_lowercase :    Any							=							classifier_proj_size

					if (
					    (len(self.conv_stride						) != self.num_feat_extract_layers)
					    or (len(self.conv_kernel						) != self.num_feat_extract_layers)
					    or (len(self.conv_dim						) != self.num_feat_extract_layers)
					):
						raise ValueError(
						    'Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='
						    ' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='
						    F''' {len(self.conv_dim						)}`, `len(config.conv_stride) = {len(self.conv_stride						)}`,'''
						    F''' `len(config.conv_kernel) = {len(self.conv_kernel						)}`.'''						)

					# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
					_lowercase :    List[str]							=							apply_spec_augment
					_lowercase :    List[str]							=							mask_time_prob
					_lowercase :    List[Any]							=							mask_time_length
					_lowercase :    Any							=							mask_time_min_masks
					_lowercase :    Union[str, Any]							=							mask_feature_prob
					_lowercase :    Any							=							mask_feature_length
					_lowercase :    Any							=							mask_feature_min_masks

					# parameters for pretraining with codevector quantized representations
					_lowercase :    Any							=							num_codevectors_per_group
					_lowercase :    Dict							=							num_codevector_groups
					_lowercase :    Union[str, Any]							=							contrastive_logits_temperature
					_lowercase :    Tuple							=							feat_quantizer_dropout
					_lowercase :    Optional[int]							=							num_negatives
					_lowercase :    Union[str, Any]							=							codevector_dim
					_lowercase :    Tuple							=							proj_codevector_dim
					_lowercase :    Union[str, Any]							=							diversity_loss_weight

					# ctc loss
					_lowercase :    Any							=							ctc_loss_reduction
					_lowercase :    int							=							ctc_zero_infinity

					# pretraining loss
					_lowercase :    Optional[int]							=							replace_prob







				@property
				def 							__UpperCAmelCase					( self    :       Dict						):

					"""simple docstring"""






					return functools.reduce(operator.mul			,					self.conv_stride			,					1						)




"""simple docstring"""







from __future__ import annotations

SCREAMING_SNAKE_CASE									=						[
    [-1, 0],  # left
    [0, -1],  # down
    [1, 0],  # right
    [0, 1],  # up
]


def      __lowerCAmelCase(		__UpperCAmelCase     ,__UpperCAmelCase     ,__UpperCAmelCase     ,__UpperCAmelCase     ,__UpperCAmelCase     ,):






	"""simple docstring"""





	_lowercase :    List[str]							=							[
	    [0 for col in range(len(grid[0]			)			)] for row in range(len(__UpperCAmelCase			)			)
	]  # the reference grid
	_lowercase :    Optional[Any]							=							1
	_lowercase :    Any							=							[
	    [0 for col in range(len(grid[0]			)			)] for row in range(len(__UpperCAmelCase			)			)
	]  # the action grid

	_lowercase :    List[Any]							=							init[0]
	_lowercase :    Optional[Any]							=							init[1]
	_lowercase :    Union[str, Any]							=							0
	_lowercase :    Union[str, Any]							=							g + heuristic[x][y]  # cost from starting cell to destination cell
	_lowercase :    Dict							=							[[f, g, x, y]]

	_lowercase :    Tuple							=							False  # flag that is set when search is complete
	_lowercase :    Tuple							=							False  # flag set if we can't find expand

	while not found and not resign:
		if len(__UpperCAmelCase			) == 0:
			raise ValueError('Algorithm is unable to find solution'			)
		else:  # to choose the least costliest action so as to move closer to the goal
			cell.sort()
			cell.reverse()
			_lowercase :    List[Any]							=							cell.pop()
			_lowercase :    Optional[Any]							=							next_cell[2]
			_lowercase :    List[str]							=							next_cell[3]
			_lowercase :    Optional[int]							=							next_cell[1]

			if x == goal[0] and y == goal[1]:
				_lowercase :    Optional[Any]							=							True
			else:
				for i in range(len(__UpperCAmelCase			)			):  # to try out different valid actions
					_lowercase :    Any							=							x + DIRECTIONS[i][0]
					_lowercase :    Union[str, Any]							=							y + DIRECTIONS[i][1]
					if xa >= 0 and xa < len(__UpperCAmelCase			) and ya >= 0 and ya < len(grid[0]			):
						if closed[xa][ya] == 0 and grid[xa][ya] == 0:
							_lowercase :    int							=							g + cost
							_lowercase :    List[str]							=							ga + heuristic[xa][ya]
							cell.append([fa, ga, xa, ya]			)
							_lowercase :    List[Any]							=							1
							_lowercase :    Dict							=							i
	_lowercase :    Union[str, Any]							=							[]
	_lowercase :    Optional[int]							=							goal[0]
	_lowercase :    Any							=							goal[1]
	invpath.append([x, y]			)  # we get the reverse path from here
	while x != init[0] or y != init[1]:
		_lowercase :    str							=							x - DIRECTIONS[action[x][y]][0]
		_lowercase :    Any							=							y - DIRECTIONS[action[x][y]][1]
		_lowercase :    Dict							=							xa
		_lowercase :    Tuple							=							ya
		invpath.append([x, y]			)

	_lowercase :    List[str]							=							[]
	for i in range(len(__UpperCAmelCase			)			):
		path.append(invpath[len(__UpperCAmelCase			) - 1 - i]			)
	return path, action


if __name__ == "__main__":
						SCREAMING_SNAKE_CASE									=						[
						    [0, 1, 0, 0, 0, 0],
						    [0, 1, 0, 0, 0, 0],  # 0 are free path whereas 1's are obstacles
						    [0, 1, 0, 0, 0, 0],
						    [0, 1, 0, 0, 1, 0],
						    [0, 0, 0, 0, 1, 0],
						]

						SCREAMING_SNAKE_CASE									=						[0, 0]
						# all coordinates are given in format [y,x]
						SCREAMING_SNAKE_CASE									=						[len(grid) - 1, len(grid[0]) - 1]
						SCREAMING_SNAKE_CASE									=						1

						# the cost map which pushes the path closer to the goal
						SCREAMING_SNAKE_CASE									=						[[0 for row in range(len(grid[0]))] for col in range(len(grid))]
						for i in range(len(grid)):
												for j in range(len(grid[0])):
																		SCREAMING_SNAKE_CASE									=						abs(i - goal[0]) + abs(j - goal[1])
																		if grid[i][j] == 1:
																								# added extra penalty in the heuristic map
																								SCREAMING_SNAKE_CASE									=						99

						SCREAMING_SNAKE_CASE							,    SCREAMING_SNAKE_CASE									=						search(grid, init, goal, cost, heuristic)

						print('ACTION MAP')
						for i in range(len(action)):
												print(action[i])

						for i in range(len(path)):
												print(path[i])



