


'''simple docstring'''
from tempfile import TemporaryDirectory
from unittest import TestCase
from unittest.mock import MagicMock, patch

from transformers import AutoModel, TFAutoModel
from transformers.onnx import FeaturesManager
from transformers.testing_utils import SMALL_MODEL_IDENTIFIER, require_tf, require_torch

@require_torch
@require_tf
class 						_lowerCamelCase					(    snake_case_				):




 '''simple docstring'''


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Any       =			SMALL_MODEL_IDENTIFIER
  __A  :		Any       =			'pt'
  __A  :		str       =			'tf'


 def  snake_case__   (      self      ,      __lowercase						):

  """simple docstring"""







  __A  :		Optional[Any]       =			AutoModel.from_pretrained(self.test_model						)
  model_pt.save_pretrained(__lowercase						)


 def  snake_case__   (      self      ,      __lowercase						):

  """simple docstring"""







  __A  :		List[Any]       =			TFAutoModel.from_pretrained(self.test_model      ,      from_pt=__lowercase						)
  model_tf.save_pretrained(__lowercase						)


 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		Any       =			'mock_framework'

  # Framework provided - return whatever the user provides
  __A  :		int       =			FeaturesManager.determine_framework(self.test_model      ,      __lowercase						)
  self.assertEqual(__lowercase      ,      __lowercase						)

  # Local checkpoint and framework provided - return provided framework
  # PyTorch checkpoint
  with TemporaryDirectory() as local_pt_ckpt:
   self._setup_pt_ckpt(__lowercase						)
   __A  :		List[Any]       =			FeaturesManager.determine_framework(__lowercase      ,      __lowercase						)
   self.assertEqual(__lowercase      ,      __lowercase						)

  # TensorFlow checkpoint
  with TemporaryDirectory() as local_tf_ckpt:
   self._setup_tf_ckpt(__lowercase						)
   __A  :		Optional[int]       =			FeaturesManager.determine_framework(__lowercase      ,      __lowercase						)
   self.assertEqual(__lowercase      ,      __lowercase						)


 def  snake_case__   (      self						):

  """simple docstring"""







  with TemporaryDirectory() as local_pt_ckpt:
   self._setup_pt_ckpt(__lowercase						)
   __A  :		Optional[int]       =			FeaturesManager.determine_framework(__lowercase						)
   self.assertEqual(__lowercase      ,      self.framework_pt						)

  # TensorFlow checkpoint
  with TemporaryDirectory() as local_tf_ckpt:
   self._setup_tf_ckpt(__lowercase						)
   __A  :		Tuple       =			FeaturesManager.determine_framework(__lowercase						)
   self.assertEqual(__lowercase      ,      self.framework_tf						)

  # Invalid local checkpoint
  with TemporaryDirectory() as local_invalid_ckpt:
   with self.assertRaises(__lowercase						):
    __A  :		Dict       =			FeaturesManager.determine_framework(__lowercase						)







 def  snake_case__   (      self						):

  """simple docstring"""







  __A  :		int       =			MagicMock(return_value=__lowercase						)
  with patch('transformers.onnx.features.is_tf_available'      ,      __lowercase						):
   __A  :		Union[str, Any]       =			FeaturesManager.determine_framework(self.test_model						)
   self.assertEqual(__lowercase      ,      self.framework_pt						)

  # PyTorch not in environment -> use TensorFlow
  __A  :		int       =			MagicMock(return_value=__lowercase						)
  with patch('transformers.onnx.features.is_torch_available'      ,      __lowercase						):
   __A  :		Any       =			FeaturesManager.determine_framework(self.test_model						)
   self.assertEqual(__lowercase      ,      self.framework_tf						)

  # Both in environment -> use PyTorch
  __A  :		List[str]       =			MagicMock(return_value=__lowercase						)
  __A  :		Optional[int]       =			MagicMock(return_value=__lowercase						)
  with patch('transformers.onnx.features.is_tf_available'      ,      __lowercase						), patch(
      'transformers.onnx.features.is_torch_available'      ,      __lowercase						):
   __A  :		int       =			FeaturesManager.determine_framework(self.test_model						)
   self.assertEqual(__lowercase      ,      self.framework_pt						)

  # Both not in environment -> raise error
  __A  :		str       =			MagicMock(return_value=__lowercase						)
  __A  :		Optional[Any]       =			MagicMock(return_value=__lowercase						)
  with patch('transformers.onnx.features.is_tf_available'      ,      __lowercase						), patch(
      'transformers.onnx.features.is_torch_available'      ,      __lowercase						):
   with self.assertRaises(__lowercase						):
    __A  :		List[str]       =			FeaturesManager.determine_framework(self.test_model						)




'''simple docstring'''
from heapq import heappop, heappush

import numpy as np


def 			_lowercase       (				UpperCamelCase__       :					np.ndarray,				UpperCamelCase__       :					tuple[int, int],				UpperCamelCase__       :					tuple[int, int],				UpperCamelCase__       :					bool,				):
 __A     ,__A  :		Optional[Any]       =			grid.shape
 __A  :		List[Any]       =			[-1, 1, 0, 0]
 __A  :		Optional[int]       =			[0, 0, -1, 1]
 if allow_diagonal:
  dx += [-1, -1, 1, 1]
  dy += [-1, 1, -1, 1]

 __A     ,__A  :		int       =			[(0, source)], set()
 __A  :		Any       =			np.full((rows, cols),				np.inf			)
 __A  :		int       =			0
 __A  :		Any       =			np.empty((rows, cols),				dtype=UpperCamelCase__			)
 __A  :		List[Any]       =			None

 while queue:
  ((__A)     ,(__A))  :		List[Any]       =			heappop(UpperCamelCase__			)
  if (x, y) in visited:
   continue
  visited.add((x, y)			)

  if (x, y) == destination:
   __A  :		Tuple       =			[]
   while (x, y) != source:
    path.append((x, y)			)
    __A     ,__A  :		int       =			predecessors[x, y]
   path.append(UpperCamelCase__			)  # add the source manually
   path.reverse()
   return matrix[destination], path

  for i in range(len(UpperCamelCase__			)			):
   __A     ,__A  :		List[Any]       =			x + dx[i], y + dy[i]
   if 0 <= nx < rows and 0 <= ny < cols:
    __A  :		str       =			grid[nx][ny]
    if next_node == 1 and matrix[nx, ny] > dist + 1:
     heappush(UpperCamelCase__,				(dist + 1, (nx, ny))			)
     __A  :		int       =			dist + 1
     __A  :		List[str]       =			(x, y)

 return np.inf, []


if __name__ == "__main__":
 import doctest

 doctest.testmod()






