

'''simple docstring'''





import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
							import torch

							from transformers.activations import gelu_new, gelu_python, get_activation





@require_torch
class 		__SCREAMING_SNAKE_CASE							(			unittest.TestCase      ):







				def  lowerCamelCase_	(       self     :		List[str]   ):
										'''simple docstring'''
										lowercase :							Dict    		=torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]   )
										lowercase :							int    		=get_activation('''gelu'''   )
										self.assertTrue(torch.allclose(gelu_python(UpperCAmelCase__   )		,					torch_builtin(UpperCAmelCase__   )   )   )
										self.assertFalse(torch.allclose(gelu_python(UpperCAmelCase__   )		,					gelu_new(UpperCAmelCase__   )   )   )







				def  lowerCamelCase_	(       self     :		List[str]   ):
										'''simple docstring'''
										lowercase :							Union[str, Any]    		=torch.tensor([-100, -1, -0.1, 0, 0.1, 1.0, 100]   )
										lowercase :							List[str]    		=get_activation('''gelu'''   )
										lowercase :							Optional[int]    		=get_activation('''gelu_10'''   )

										lowercase :							Union[str, Any]    		=torch_builtin(UpperCAmelCase__   )
										lowercase :							int    		=geluaa(UpperCAmelCase__   )

										lowercase :							Dict    		=torch.where(y_gelu_aa < 10.0		,					1		,					0   )

										self.assertTrue(torch.max(UpperCAmelCase__   ).item() == 10.0   )
										self.assertTrue(torch.allclose(y_gelu * clipped_mask		,					y_gelu_aa * clipped_mask   )   )







				def  lowerCamelCase_	(       self     :		str   ):
										'''simple docstring'''
										get_activation('''gelu'''   )
										get_activation('''gelu_10'''   )
										get_activation('''gelu_fast'''   )
										get_activation('''gelu_new'''   )
										get_activation('''gelu_python'''   )
										get_activation('''gelu_pytorch_tanh'''   )
										get_activation('''linear'''   )
										get_activation('''mish'''   )
										get_activation('''quick_gelu'''   )
										get_activation('''relu'''   )
										get_activation('''sigmoid'''   )
										get_activation('''silu'''   )
										get_activation('''swish'''   )
										get_activation('''tanh'''   )
										with self.assertRaises(UpperCAmelCase__   ):
																get_activation('''bogus'''   )
										with self.assertRaises(UpperCAmelCase__   ):
																get_activation(UpperCAmelCase__   )







				def  lowerCamelCase_	(       self     :		Optional[Any]   ):
										'''simple docstring'''
										lowercase :							Tuple    		=get_activation('''gelu'''   )
										lowercase :							Optional[int]    		=1
										lowercase :							List[Any]    		=get_activation('''gelu'''   )
										self.assertEqual(acta.a		,					1   )
										with self.assertRaises(UpperCAmelCase__   ):
																lowercase :							Tuple    		=acta.a








'''simple docstring'''





import numpy as np
from cva import destroyAllWindows, imread, imshow, waitKey





class 		__SCREAMING_SNAKE_CASE							:







				def __init__(       self     :		Union[str, Any]		,					UpperCAmelCase__     :		Union[str, Any]		,					UpperCAmelCase__     :		int		,					UpperCAmelCase__     :		int   ):
										'''simple docstring'''
										if dst_width < 0 or dst_height < 0:
																raise ValueError('''Destination width/height should be > 0'''   )

										lowercase :							Union[str, Any]    		=img
										lowercase :							Union[str, Any]    		=img.shape[1]
										lowercase :							str    		=img.shape[0]
										lowercase :							Union[str, Any]    		=dst_width
										lowercase :							str    		=dst_height

										lowercase :							str    		=self.src_w / self.dst_w
										lowercase :							Optional[Any]    		=self.src_h / self.dst_h

										lowercase :							int    		=(
										    np.ones((self.dst_h, self.dst_w, 3)		,					np.uinta   ) * 255
										)







				def  lowerCamelCase_	(       self     :		List[Any]   ):
										'''simple docstring'''
										for i in range(self.dst_h   ):
																for j in range(self.dst_w   ):
																						lowercase :							List[Any]    		=self.img[self.get_y(UpperCAmelCase__   )][self.get_x(UpperCAmelCase__   )]







				def  lowerCamelCase_	(       self     :		Tuple		,					UpperCAmelCase__     :		int   ):
										'''simple docstring'''
										return int(self.ratio_x * x   )







				def  lowerCamelCase_	(       self     :		List[Any]		,					UpperCAmelCase__     :		int   ):
										'''simple docstring'''
										return int(self.ratio_y * y   )


if __name__ == "__main__":
							UpperCamelCase_						,   UpperCamelCase_    						=       800, 600
							UpperCamelCase_    						=       imread("""image_data/lena.jpg""", 1)
							UpperCamelCase_    						=       NearestNeighbour(im, dst_w, dst_h)
							n.process()

							imshow(
							    f'''Image resized from: {im.shape[1]}x{im.shape[0]} to {dst_w}x{dst_h}''', n.output
							)
							waitKey(0)
							destroyAllWindows()





