



"""simple docstring"""






import unittest

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
	from PIL import Image
else:



	class     A__     :




		'''simple docstring'''





		@staticmethod
		def 							_SCREAMING_SNAKE_CASE     (  *_SCREAMING_SNAKE_CASE:	Optional[Any] ,    **_SCREAMING_SNAKE_CASE:	str)       -> int:

					"""simple docstring"""

					pass



@is_pipeline_test
@require_vision
class     A__     (						unittest.TestCase							):




	'''simple docstring'''





	@require_torch
	def 							_SCREAMING_SNAKE_CASE     (  self:	List[Any])       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						int				= pipeline(
				    model="hf-internal-testing/tiny-random-clip-zero-shot-image-classification" ,    )
				__lowerCAmelCase   :						List[str]				= Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
				__lowerCAmelCase   :						Optional[Any]				= image_classifier(_SCREAMING_SNAKE_CASE ,    candidate_labels=["a", "b", "c"])

				# The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
				# python and torch versions.
				self.assertIn(
				    nested_simplify(_SCREAMING_SNAKE_CASE) ,    [
				        [{"score": 0.333, "label": "a"}, {"score": 0.333, "label": "b"}, {"score": 0.333, "label": "c"}],
				        [{"score": 0.333, "label": "a"}, {"score": 0.333, "label": "c"}, {"score": 0.333, "label": "b"}],
				    ] ,    )

				__lowerCAmelCase   :						str				= image_classifier([image] * 5 ,    candidate_labels=["A", "B", "C"] ,    batch_size=2)
				self.assertEqual(
				    nested_simplify(_SCREAMING_SNAKE_CASE) ,    [
				        [
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				        ],
				        [
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				        ],
				        [
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				        ],
				        [
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				        ],
				        [
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				        ],
				    ] ,    )

	@require_tf
	def 							_SCREAMING_SNAKE_CASE     (  self:	Dict)       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						int				= pipeline(
				    model="hf-internal-testing/tiny-random-clip-zero-shot-image-classification" ,    framework="tf")
				__lowerCAmelCase   :						Dict				= Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
				__lowerCAmelCase   :						Union[str, Any]				= image_classifier(_SCREAMING_SNAKE_CASE ,    candidate_labels=["a", "b", "c"])

				self.assertEqual(
				    nested_simplify(_SCREAMING_SNAKE_CASE) ,    [{"score": 0.333, "label": "a"}, {"score": 0.333, "label": "b"}, {"score": 0.333, "label": "c"}] ,    )

				__lowerCAmelCase   :						Any				= image_classifier([image] * 5 ,    candidate_labels=["A", "B", "C"] ,    batch_size=2)
				self.assertEqual(
				    nested_simplify(_SCREAMING_SNAKE_CASE) ,    [
				        [
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				        ],
				        [
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				        ],
				        [
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				        ],
				        [
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				        ],
				        [
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				            {"score": 0.333, "label": ANY(_SCREAMING_SNAKE_CASE)},
				        ],
				    ] ,    )

	@slow
	@require_torch
	def 							_SCREAMING_SNAKE_CASE     (  self:	List[str])       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						Optional[int]				= pipeline(
				    task="zero-shot-image-classification" ,    model="openai/clip-vit-base-patch32" ,    )
				# This is an image of 2 cats with remotes and no planes
				__lowerCAmelCase   :						Union[str, Any]				= Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
				__lowerCAmelCase   :						Tuple				= image_classifier(_SCREAMING_SNAKE_CASE ,    candidate_labels=["cat", "plane", "remote"])

				self.assertEqual(
				    nested_simplify(_SCREAMING_SNAKE_CASE) ,    [
				        {"score": 0.511, "label": "remote"},
				        {"score": 0.485, "label": "cat"},
				        {"score": 0.004, "label": "plane"},
				    ] ,    )

				__lowerCAmelCase   :						Union[str, Any]				= image_classifier([image] * 5 ,    candidate_labels=["cat", "plane", "remote"] ,    batch_size=2)
				self.assertEqual(
				    nested_simplify(_SCREAMING_SNAKE_CASE) ,    [
				        [
				            {"score": 0.511, "label": "remote"},
				            {"score": 0.485, "label": "cat"},
				            {"score": 0.004, "label": "plane"},
				        ],
				    ]
				    * 5 ,    )







	@slow
	@require_tf
	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[Any])       -> Any:

				"""simple docstring"""

				__lowerCAmelCase   :						Optional[Any]				= pipeline(
				    task="zero-shot-image-classification" ,    model="openai/clip-vit-base-patch32" ,    framework="tf")
				# This is an image of 2 cats with remotes and no planes
				__lowerCAmelCase   :						Tuple				= Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
				__lowerCAmelCase   :						List[Any]				= image_classifier(_SCREAMING_SNAKE_CASE ,    candidate_labels=["cat", "plane", "remote"])
				self.assertEqual(
				    nested_simplify(_SCREAMING_SNAKE_CASE) ,    [
				        {"score": 0.511, "label": "remote"},
				        {"score": 0.485, "label": "cat"},
				        {"score": 0.004, "label": "plane"},
				    ] ,    )

				__lowerCAmelCase   :						Tuple				= image_classifier([image] * 5 ,    candidate_labels=["cat", "plane", "remote"] ,    batch_size=2)
				self.assertEqual(
				    nested_simplify(_SCREAMING_SNAKE_CASE) ,    [
				        [
				            {"score": 0.511, "label": "remote"},
				            {"score": 0.485, "label": "cat"},
				            {"score": 0.004, "label": "plane"},
				        ],
				    ]
				    * 5 ,    )




"""simple docstring"""






import unittest

from knapsack import knapsack as k



class     A__     (						unittest.TestCase							):




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[int])       -> List[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[Any]				= 0
				__lowerCAmelCase   :						str				= [0]
				__lowerCAmelCase   :						Union[str, Any]				= [0]
				__lowerCAmelCase   :						List[Any]				= len(_SCREAMING_SNAKE_CASE)
				self.assertEqual(k.knapsack(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE) ,    0)

				__lowerCAmelCase   :						Dict				= [60]
				__lowerCAmelCase   :						Optional[int]				= [10]
				__lowerCAmelCase   :						Tuple				= len(_SCREAMING_SNAKE_CASE)
				self.assertEqual(k.knapsack(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE) ,    0)

	def 							_SCREAMING_SNAKE_CASE     (  self:	Any)       -> int:

				"""simple docstring"""

				__lowerCAmelCase   :						Dict				= 3
				__lowerCAmelCase   :						Dict				= [1, 2, 3]
				__lowerCAmelCase   :						str				= [3, 2, 1]
				__lowerCAmelCase   :						Optional[int]				= len(_SCREAMING_SNAKE_CASE)
				self.assertEqual(k.knapsack(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE) ,    5)







	def 							_SCREAMING_SNAKE_CASE     (  self:	Optional[int])       -> Optional[Any]:

				"""simple docstring"""

				__lowerCAmelCase   :						List[str]				= 50
				__lowerCAmelCase   :						Dict				= [60, 100, 120]
				__lowerCAmelCase   :						List[Any]				= [10, 20, 30]
				__lowerCAmelCase   :						int				= len(_SCREAMING_SNAKE_CASE)
				self.assertEqual(k.knapsack(_SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE ,    _SCREAMING_SNAKE_CASE) ,    220)


if __name__ == "__main__":
	unittest.main()