






'''simple docstring'''




import operator







def       __UpperCAmelCase						(  lowerCamelCase_     ,      lowerCamelCase_ = False     ,      lowerCamelCase_ = None)							->     list:
  UpperCamelCase__				:					Union[str, Any]					=					operator.lt if reverse else operator.gt
  UpperCamelCase__				:					List[str]					=					solution or []

  if not arr:
    return solution

  UpperCamelCase__				:					Tuple					=					[arr.pop(0)]
  for i, item in enumerate(lowerCamelCase_):
    if _operator(lowerCamelCase_     ,      sublist[-1]):
      sublist.append(lowerCamelCase_)
      arr.pop(lowerCamelCase_)

    #  merging sublist into solution list
  if not solution:
    solution.extend(lowerCamelCase_)
  else:
    while sublist:
      UpperCamelCase__				:					List[Any]					=					sublist.pop(0)
      for i, xx in enumerate(lowerCamelCase_):
        if not _operator(lowerCamelCase_     ,      lowerCamelCase_):
          solution.insert(lowerCamelCase_     ,      lowerCamelCase_)
          break
      else:
        solution.append(lowerCamelCase_)

  strand_sort(lowerCamelCase_     ,      lowerCamelCase_     ,      lowerCamelCase_)
  return solution


if __name__ == "__main__":
  assert strand_sort([4, 3, 5, 1, 2]) == [1, 2, 3, 4, 5]
  assert strand_sort([4, 3, 5, 1, 2], reverse=True) == [5, 4, 3, 2, 1]












'''simple docstring'''




import unittest

from transformers import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision, slow, torch_device


if is_torch_available():
		import torch

		from transformers import AutoModelForImageClassification

if is_vision_available():
		from transformers import AutoImageProcessor







@require_torch
@require_vision
class       __lowercase					(unittest.TestCase    ):

	@slow
	def      __UpperCamelCase							(      self   :						int):
			UpperCamelCase__				:					Union[str, Any]					=					AutoImageProcessor.from_pretrained('microsoft/dit-base-finetuned-rvlcdip')
			UpperCamelCase__				:					List[str]					=					AutoModelForImageClassification.from_pretrained('microsoft/dit-base-finetuned-rvlcdip')
			model.to(UpperCAmelCase_)

			from datasets import load_dataset

			UpperCamelCase__				:					Optional[Any]					=					load_dataset('nielsr/rvlcdip-demo')

			UpperCamelCase__				:					int					=					dataset['train'][0]['image'].convert('RGB')

			UpperCamelCase__				:					Union[str, Any]					=					image_processor(UpperCAmelCase_  ,					return_tensors='pt').to(UpperCAmelCase_)

			# forward pass
			with torch.no_grad():
					UpperCamelCase__				:					Optional[Any]					=					model(**UpperCAmelCase_)
					UpperCamelCase__				:					Tuple					=					outputs.logits

			UpperCamelCase__				:					str					=					torch.Size((1, 16))
			self.assertEqual(logits.shape  ,					UpperCAmelCase_)

			UpperCamelCase__				:					Tuple					=					torch.tensor(
			    [-0.41_58, -0.40_92, -0.43_47]  ,					device=UpperCAmelCase_  ,					dtype=torch.float  ,					)
			self.assertTrue(torch.allclose(logits[0, :3]  ,					UpperCAmelCase_  ,					atol=1e-4))




