





"""simple docstring"""
import math
import unittest






def 					A__				(			UpperCamelCase       ):
							assert isinstance(UpperCamelCase					,  UpperCamelCase       ) and (
							    number >= 0
							), "'number' must been an int and positive"

							if 1 < number < 4:
														# 2 and 3 are primes
														return True
							elif number < 2 or number % 2 == 0 or number % 3 == 0:
														# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
														return False

							# All primes number are in format of 6k +/- 1
							for i in range(5					,  int(math.sqrt(UpperCamelCase       ) + 1       )					,  6       ):
														if number % i == 0 or number % (i + 2) == 0:
																					return False
							return True






class 					_UpperCAmelCase   (	unittest.TestCase ):


					def 	lowerCamelCase       (					self			:int		):
												self.assertTrue(is_prime(2		)		)
												self.assertTrue(is_prime(3		)		)
												self.assertTrue(is_prime(5		)		)
												self.assertTrue(is_prime(7		)		)
												self.assertTrue(is_prime(11		)		)
												self.assertTrue(is_prime(13		)		)
												self.assertTrue(is_prime(17		)		)
												self.assertTrue(is_prime(19		)		)
												self.assertTrue(is_prime(23		)		)
												self.assertTrue(is_prime(29		)		)


					def 	lowerCamelCase       (					self			:str		):
												with self.assertRaises(__UpperCamelCase		):
																			is_prime(-19		)
												self.assertFalse(
												    is_prime(0		)     ,       "Zero doesn't have any positive factors, primes must have exactly two."     ,       )
												self.assertFalse(
												    is_prime(1		)     ,       "One only has 1 positive factor, primes must have exactly two."     ,       )
												self.assertFalse(is_prime(2 * 2		)		)
												self.assertFalse(is_prime(2 * 3		)		)
												self.assertFalse(is_prime(3 * 3		)		)
												self.assertFalse(is_prime(3 * 5		)		)
												self.assertFalse(is_prime(3 * 5 * 7		)		)


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









"""simple docstring"""
import hashlib
import unittest

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

from .test_pipelines_common import ANY


if is_torch_available():
		import torch

if is_vision_available():
		from PIL import Image
else:






		class 					_UpperCAmelCase   :


							@staticmethod
							def 	lowerCamelCase       (					*__UpperCamelCase			:List[Any]     ,       **__UpperCamelCase			:List[Any]		):
														pass






def 					A__				(			UpperCamelCase       ):
							A		=  hashlib.mda(image.tobytes()       )
							return m.hexdigest()






@is_pipeline_test
@require_vision
@require_timm
@require_torch
class 					_UpperCAmelCase   (	unittest.TestCase ):
					UpperCamelCase      =							MODEL_FOR_DEPTH_ESTIMATION_MAPPING


					def 	lowerCamelCase       (					self			:Optional[Any]     ,       __UpperCamelCase			:Union[str, Any]     ,       __UpperCamelCase			:List[str]     ,       __UpperCamelCase			:Optional[int]		):
												A		=  DepthEstimationPipeline(model=__UpperCamelCase     ,       image_processor=__UpperCamelCase		)
												return depth_estimator, [
												    "./tests/fixtures/tests_samples/COCO/000000039769.png",
												    "./tests/fixtures/tests_samples/COCO/000000039769.png",
												]


					def 	lowerCamelCase       (					self			:Dict     ,       __UpperCamelCase			:Optional[int]     ,       __UpperCamelCase			:Optional[Any]		):
												A		=  depth_estimator("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
												self.assertEqual({"predicted_depth": ANY(torch.Tensor		), "depth": ANY(Image.Image		)}     ,       __UpperCamelCase		)
												import datasets

												A		=  datasets.load_dataset("hf-internal-testing/fixtures_image_utils"     ,       "image"     ,       split="test"		)
												A		=  depth_estimator(
												    [
												        Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		),
												        "http://images.cocodataset.org/val2017/000000039769.jpg",
												        # RGBA
												        dataset[0]["file"],
												        # LA
												        dataset[1]["file"],
												        # L
												        dataset[2]["file"],
												    ]		)
												self.assertEqual(
												    [
												        {"predicted_depth": ANY(torch.Tensor		), "depth": ANY(Image.Image		)},
												        {"predicted_depth": ANY(torch.Tensor		), "depth": ANY(Image.Image		)},
												        {"predicted_depth": ANY(torch.Tensor		), "depth": ANY(Image.Image		)},
												        {"predicted_depth": ANY(torch.Tensor		), "depth": ANY(Image.Image		)},
												        {"predicted_depth": ANY(torch.Tensor		), "depth": ANY(Image.Image		)},
												    ]     ,       __UpperCamelCase     ,       )


					@require_tf
					@unittest.skip("Depth estimation is not implemented in TF"		)
					def 	lowerCamelCase       (					self			:Optional[Any]		):
												pass


					@slow
					@require_torch
					def 	lowerCamelCase       (					self			:Optional[Any]		):
												A		=  "Intel/dpt-large"
												A		=  pipeline("depth-estimation"     ,       model=__UpperCamelCase		)
												A		=  depth_estimator("http://images.cocodataset.org/val2017/000000039769.jpg"		)
												A		=  hashimage(outputs["depth"]		)

												# This seems flaky.
												# self.assertEqual(outputs["depth"], "1a39394e282e9f3b0741a90b9f108977")
												self.assertEqual(nested_simplify(outputs["predicted_depth"].max().item()		)     ,       29.304		)
												self.assertEqual(nested_simplify(outputs["predicted_depth"].min().item()		)     ,       2.662		)


					@require_torch
					def 	lowerCamelCase       (					self			:Optional[Any]		):
												# This is highly irregular to have no small tests.
												self.skipTest("There is not hf-internal-testing tiny model for either GLPN nor DPT"		)


