"""simple docstring"""







import shutil
import tempfile
import unittest

import numpy as np

from transformers.testing_utils import (
    is_pt_tf_cross_test,
    require_tf,
    require_torch,
    require_torchvision,
    require_vision,
)
from transformers.utils import is_tf_available, is_torch_available, is_vision_available


if is_vision_available():
						from PIL import Image

						from transformers import AutoProcessor, SamImageProcessor, SamProcessor

if is_torch_available():
						import torch

if is_tf_available():
						import tensorflow as tf



@require_vision
@require_torchvision
class  _lowerCamelCase			(unittest.TestCase     ):







							def 							__UpperCAmelCase					( self    :       Dict						):

								"""simple docstring"""






								_lowercase :    int							=							tempfile.mkdtemp()
								_lowercase :    Dict							=							SamImageProcessor()
								_lowercase :    Union[str, Any]							=							SamProcessor(lowerCamelCase_						)
								processor.save_pretrained(self.tmpdirname						)







							def 							__UpperCAmelCase					( self    :       Union[str, Any]			,					**lowerCamelCase_    :       List[str]						):

								"""simple docstring"""






								return AutoProcessor.from_pretrained(self.tmpdirname			,					**lowerCamelCase_						).image_processor







							def 							__UpperCAmelCase					( self    :       Dict						):

								"""simple docstring"""






								shutil.rmtree(self.tmpdirname						)







							def 							__UpperCAmelCase					( self    :       int						):

								"""simple docstring"""






								_lowercase :    List[Any]							=							[np.random.randint(2_5_5			,					size=(3, 3_0, 4_0_0)			,					dtype=np.uinta						)]

								_lowercase :    Optional[Any]							=							[Image.fromarray(np.moveaxis(lowerCamelCase_			,					0			,					-1						)						) for x in image_inputs]

								return image_inputs







							def 							__UpperCAmelCase					( self    :       Optional[int]						):

								"""simple docstring"""






								_lowercase :    Optional[Any]							=							SamProcessor(image_processor=self.get_image_processor()						)
								processor.save_pretrained(self.tmpdirname						)

								_lowercase :    Tuple							=							self.get_image_processor(do_normalize=lowerCamelCase_			,					padding_value=1.0						)

								_lowercase :    List[str]							=							SamProcessor.from_pretrained(self.tmpdirname			,					do_normalize=lowerCamelCase_			,					padding_value=1.0						)

								self.assertEqual(processor.image_processor.to_json_string()			,					image_processor_add_kwargs.to_json_string()						)
								self.assertIsInstance(processor.image_processor			,					lowerCamelCase_						)







							def 							__UpperCAmelCase					( self    :       int						):

								"""simple docstring"""






								_lowercase :    str							=							self.get_image_processor()

								_lowercase :    Any							=							SamProcessor(image_processor=lowerCamelCase_						)

								_lowercase :    Optional[int]							=							self.prepare_image_inputs()

								_lowercase :    Union[str, Any]							=							image_processor(lowerCamelCase_			,					return_tensors='np'						)
								_lowercase :    Tuple							=							processor(images=lowerCamelCase_			,					return_tensors='np'						)

								input_feat_extract.pop('original_sizes'						)  # pop original_sizes as it is popped in the processor
								input_feat_extract.pop('reshaped_input_sizes'						)  # pop original_sizes as it is popped in the processor

								for key in input_feat_extract.keys():
									self.assertAlmostEqual(input_feat_extract[key].sum()			,					input_processor[key].sum()			,					delta=1E-2						)







							@require_torch
							def 							__UpperCAmelCase					( self    :       List[Any]						):

								"""simple docstring"""






								_lowercase :    Optional[int]							=							self.get_image_processor()

								_lowercase :    List[str]							=							SamProcessor(image_processor=lowerCamelCase_						)
								_lowercase :    List[Any]							=							[torch.ones((1, 3, 5, 5)						)]

								_lowercase :    List[str]							=							[[1_7_6_4, 2_6_4_6]]

								_lowercase :    Optional[int]							=							[[6_8_3, 1_0_2_4]]
								_lowercase :    str							=							processor.post_process_masks(lowerCamelCase_			,					lowerCamelCase_			,					lowerCamelCase_						)
								self.assertEqual(masks[0].shape			,					(1, 3, 1_7_6_4, 2_6_4_6)						)

								_lowercase :    Union[str, Any]							=							processor.post_process_masks(
								    lowerCamelCase_			,					torch.tensor(lowerCamelCase_						)			,					torch.tensor(lowerCamelCase_						)						)
								self.assertEqual(masks[0].shape			,					(1, 3, 1_7_6_4, 2_6_4_6)						)

								# should also work with np
								_lowercase :    str							=							[np.ones((1, 3, 5, 5)						)]
								_lowercase :    str							=							processor.post_process_masks(lowerCamelCase_			,					np.array(lowerCamelCase_						)			,					np.array(lowerCamelCase_						)						)

								self.assertEqual(masks[0].shape			,					(1, 3, 1_7_6_4, 2_6_4_6)						)

								_lowercase :    Union[str, Any]							=							[[1, 0], [0, 1]]
								with self.assertRaises(lowerCamelCase_						):
									_lowercase :    int							=							processor.post_process_masks(lowerCamelCase_			,					np.array(lowerCamelCase_						)			,					np.array(lowerCamelCase_						)						)



@require_vision
@require_tf
class  _lowerCamelCase			(unittest.TestCase     ):







							def 							__UpperCAmelCase					( self    :       Optional[int]						):

								"""simple docstring"""






								_lowercase :    Any							=							tempfile.mkdtemp()
								_lowercase :    List[Any]							=							SamImageProcessor()
								_lowercase :    Union[str, Any]							=							SamProcessor(lowerCamelCase_						)
								processor.save_pretrained(self.tmpdirname						)







							def 							__UpperCAmelCase					( self    :       List[str]			,					**lowerCamelCase_    :       Dict						):

								"""simple docstring"""






								return AutoProcessor.from_pretrained(self.tmpdirname			,					**lowerCamelCase_						).image_processor







							def 							__UpperCAmelCase					( self    :       str						):

								"""simple docstring"""






								shutil.rmtree(self.tmpdirname						)







							def 							__UpperCAmelCase					( self    :       Union[str, Any]						):

								"""simple docstring"""






								_lowercase :    Tuple							=							[np.random.randint(2_5_5			,					size=(3, 3_0, 4_0_0)			,					dtype=np.uinta						)]

								_lowercase :    str							=							[Image.fromarray(np.moveaxis(lowerCamelCase_			,					0			,					-1						)						) for x in image_inputs]

								return image_inputs







							def 							__UpperCAmelCase					( self    :       Any						):

								"""simple docstring"""






								_lowercase :    Tuple							=							SamProcessor(image_processor=self.get_image_processor()						)
								processor.save_pretrained(self.tmpdirname						)

								_lowercase :    int							=							self.get_image_processor(do_normalize=lowerCamelCase_			,					padding_value=1.0						)

								_lowercase :    Union[str, Any]							=							SamProcessor.from_pretrained(self.tmpdirname			,					do_normalize=lowerCamelCase_			,					padding_value=1.0						)

								self.assertEqual(processor.image_processor.to_json_string()			,					image_processor_add_kwargs.to_json_string()						)
								self.assertIsInstance(processor.image_processor			,					lowerCamelCase_						)







							def 							__UpperCAmelCase					( self    :       Any						):

								"""simple docstring"""






								_lowercase :    str							=							self.get_image_processor()

								_lowercase :    Any							=							SamProcessor(image_processor=lowerCamelCase_						)

								_lowercase :    List[Any]							=							self.prepare_image_inputs()

								_lowercase :    Tuple							=							image_processor(lowerCamelCase_			,					return_tensors='np'						)
								_lowercase :    List[Any]							=							processor(images=lowerCamelCase_			,					return_tensors='np'						)

								input_feat_extract.pop('original_sizes'						)  # pop original_sizes as it is popped in the processor
								input_feat_extract.pop('reshaped_input_sizes'						)  # pop reshaped_input_sizes as it is popped in the processor

								for key in input_feat_extract.keys():
									self.assertAlmostEqual(input_feat_extract[key].sum()			,					input_processor[key].sum()			,					delta=1E-2						)







							@require_tf
							def 							__UpperCAmelCase					( self    :       str						):

								"""simple docstring"""






								_lowercase :    Optional[int]							=							self.get_image_processor()

								_lowercase :    str							=							SamProcessor(image_processor=lowerCamelCase_						)
								_lowercase :    int							=							[tf.ones((1, 3, 5, 5)						)]

								_lowercase :    str							=							[[1_7_6_4, 2_6_4_6]]

								_lowercase :    List[Any]							=							[[6_8_3, 1_0_2_4]]
								_lowercase :    Union[str, Any]							=							processor.post_process_masks(lowerCamelCase_			,					lowerCamelCase_			,					lowerCamelCase_			,					return_tensors='tf'						)
								self.assertEqual(masks[0].shape			,					(1, 3, 1_7_6_4, 2_6_4_6)						)

								_lowercase :    List[str]							=							processor.post_process_masks(
								    lowerCamelCase_			,					tf.convert_to_tensor(lowerCamelCase_						)			,					tf.convert_to_tensor(lowerCamelCase_						)			,					return_tensors='tf'			,					)
								self.assertEqual(masks[0].shape			,					(1, 3, 1_7_6_4, 2_6_4_6)						)

								# should also work with np
								_lowercase :    Dict							=							[np.ones((1, 3, 5, 5)						)]
								_lowercase :    Tuple							=							processor.post_process_masks(
								    lowerCamelCase_			,					np.array(lowerCamelCase_						)			,					np.array(lowerCamelCase_						)			,					return_tensors='tf'						)

								self.assertEqual(masks[0].shape			,					(1, 3, 1_7_6_4, 2_6_4_6)						)

								_lowercase :    List[str]							=							[[1, 0], [0, 1]]
								with self.assertRaises(tf.errors.InvalidArgumentError						):
									_lowercase :    Optional[int]							=							processor.post_process_masks(
									    lowerCamelCase_			,					np.array(lowerCamelCase_						)			,					np.array(lowerCamelCase_						)			,					return_tensors='tf'						)



@require_vision
@require_torchvision
class  _lowerCamelCase			(unittest.TestCase     ):







							def 							__UpperCAmelCase					( self    :       Tuple						):

								"""simple docstring"""






								_lowercase :    str							=							tempfile.mkdtemp()
								_lowercase :    int							=							SamImageProcessor()
								_lowercase :    List[str]							=							SamProcessor(lowerCamelCase_						)
								processor.save_pretrained(self.tmpdirname						)







							def 							__UpperCAmelCase					( self    :       Dict			,					**lowerCamelCase_    :       Optional[int]						):

								"""simple docstring"""






								return AutoProcessor.from_pretrained(self.tmpdirname			,					**lowerCamelCase_						).image_processor







							def 							__UpperCAmelCase					( self    :       List[str]						):

								"""simple docstring"""






								shutil.rmtree(self.tmpdirname						)







							def 							__UpperCAmelCase					( self    :       Any						):

								"""simple docstring"""






								_lowercase :    Optional[int]							=							[np.random.randint(2_5_5			,					size=(3, 3_0, 4_0_0)			,					dtype=np.uinta						)]

								_lowercase :    Optional[Any]							=							[Image.fromarray(np.moveaxis(lowerCamelCase_			,					0			,					-1						)						) for x in image_inputs]

								return image_inputs







							@is_pt_tf_cross_test
							def 							__UpperCAmelCase					( self    :       int						):

								"""simple docstring"""






								_lowercase :    List[str]							=							self.get_image_processor()

								_lowercase :    Dict							=							SamProcessor(image_processor=lowerCamelCase_						)
								_lowercase :    Optional[Any]							=							np.random.randint(0			,					2			,					size=(1, 3, 5, 5)						).astype(np.floataa						)
								_lowercase :    Any							=							[tf.convert_to_tensor(lowerCamelCase_						)]
								_lowercase :    int							=							[torch.tensor(lowerCamelCase_						)]

								_lowercase :    Optional[Any]							=							[[1_7_6_4, 2_6_4_6]]

								_lowercase :    List[str]							=							[[6_8_3, 1_0_2_4]]
								_lowercase :    Tuple							=							processor.post_process_masks(
								    lowerCamelCase_			,					lowerCamelCase_			,					lowerCamelCase_			,					return_tensors='tf'						)
								_lowercase :    Tuple							=							processor.post_process_masks(
								    lowerCamelCase_			,					lowerCamelCase_			,					lowerCamelCase_			,					return_tensors='pt'						)

								self.assertTrue(np.all(tf_masks[0].numpy() == pt_masks[0].numpy()						)						)







							@is_pt_tf_cross_test
							def 							__UpperCAmelCase					( self    :       Optional[int]						):

								"""simple docstring"""






								_lowercase :    List[Any]							=							self.get_image_processor()

								_lowercase :    str							=							SamProcessor(image_processor=lowerCamelCase_						)

								_lowercase :    List[Any]							=							self.prepare_image_inputs()

								_lowercase :    int							=							image_processor(lowerCamelCase_			,					return_tensors='pt'						)['pixel_values'].numpy()
								_lowercase :    int							=							processor(images=lowerCamelCase_			,					return_tensors='pt'						)['pixel_values'].numpy()

								_lowercase :    int							=							image_processor(lowerCamelCase_			,					return_tensors='tf'						)['pixel_values'].numpy()
								_lowercase :    Optional[Any]							=							processor(images=lowerCamelCase_			,					return_tensors='tf'						)['pixel_values'].numpy()

								self.assertTrue(np.allclose(lowerCamelCase_			,					lowerCamelCase_						)						)
								self.assertTrue(np.allclose(lowerCamelCase_			,					lowerCamelCase_						)						)
								self.assertTrue(np.allclose(lowerCamelCase_			,					lowerCamelCase_						)						)




"""simple docstring"""







import functools


def      __lowerCAmelCase(		__UpperCAmelCase     ,__UpperCAmelCase			):






	"""simple docstring"""





	if not isinstance(__UpperCAmelCase     ,__UpperCAmelCase			) or not all(isinstance(__UpperCAmelCase     ,__UpperCAmelCase			) for day in days			):
		raise ValueError('The parameter days should be a list of integers'			)

	if len(__UpperCAmelCase			) != 3 or not all(isinstance(__UpperCAmelCase     ,__UpperCAmelCase			) for cost in costs			):
		raise ValueError('The parameter costs should be a list of three integers'			)

	if len(__UpperCAmelCase			) == 0:
		return 0

	if min(__UpperCAmelCase			) <= 0:
		raise ValueError('All days elements should be greater than 0'			)

	if max(__UpperCAmelCase			) >= 366:
		raise ValueError('All days elements should be less than 366'			)

	_lowercase :    List[Any]							=							set(__UpperCAmelCase			)

	@functools.cache
	def dynamic_programming(__UpperCAmelCase			) -> int:
		if index > 365:
			return 0

		if index not in days_set:
			return dynamic_programming(index + 1			)

		return min(
		    costs[0] + dynamic_programming(index + 1			)     ,costs[1] + dynamic_programming(index + 7			)     ,costs[2] + dynamic_programming(index + 30			)     ,)

	return dynamic_programming(1			)


if __name__ == "__main__":
						import doctest

						doctest.testmod()



