





import numpy as np



def        __lowercase       (				_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE     )			->       Dict:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						int(np.ceil((x_end - xa) / h     )     )
      SCREAMING_SNAKE_CASE		=						np.zeros((n + 1,)     )
      SCREAMING_SNAKE_CASE		=						ya
      SCREAMING_SNAKE_CASE		=						xa

      for k in range(_SCREAMING_SNAKE_CASE     ):
            SCREAMING_SNAKE_CASE		=						f(_SCREAMING_SNAKE_CASE			,						y[k]     )
            SCREAMING_SNAKE_CASE		=						f(x + 0.5 * h			,						y[k] + 0.5 * h * ka     )
            SCREAMING_SNAKE_CASE		=						f(x + 0.5 * h			,						y[k] + 0.5 * h * ka     )
            SCREAMING_SNAKE_CASE		=						f(x + h			,						y[k] + h * ka     )
            SCREAMING_SNAKE_CASE		=						y[k] + (1 / 6) * h * (ka + 2 * ka + 2 * ka + ka)
            x += h

      return y


if __name__ == "__main__":
      import doctest

      doctest.testmod()









import unittest

import numpy as np

from transformers.file_utils import is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_vision

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
      import torch

if is_vision_available():
      from PIL import Image

      from transformers import DPTImageProcessor

class 		UpperCamelCase__			(				unittest.TestCase       ):



     '''simple docstring'''

     def __init__(							self						:   Optional[Any]						,lowerCamelCase__						:   List[str]						,lowerCamelCase__						:   Optional[Any]=7						,lowerCamelCase__						:   Optional[Any]=3						,lowerCamelCase__						:   Union[str, Any]=18						,lowerCamelCase__						:   Optional[int]=30						,lowerCamelCase__						:   int=400						,lowerCamelCase__						:   List[str]=True						,lowerCamelCase__						:   Union[str, Any]=None						,lowerCamelCase__						:   Union[str, Any]=True						,lowerCamelCase__						:   Optional[int]=[0.5, 0.5, 0.5]						,lowerCamelCase__						:   Any=[0.5, 0.5, 0.5]						,)					->		List[str]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						size if size is not None else {"""height""": 18, """width""": 18}
           SCREAMING_SNAKE_CASE		=						parent
           SCREAMING_SNAKE_CASE		=						batch_size
           SCREAMING_SNAKE_CASE		=						num_channels
           SCREAMING_SNAKE_CASE		=						image_size
           SCREAMING_SNAKE_CASE		=						min_resolution
           SCREAMING_SNAKE_CASE		=						max_resolution
           SCREAMING_SNAKE_CASE		=						do_resize
           SCREAMING_SNAKE_CASE		=						size
           SCREAMING_SNAKE_CASE		=						do_normalize
           SCREAMING_SNAKE_CASE		=						image_mean
           SCREAMING_SNAKE_CASE		=						image_std






     def     SCREAMING_SNAKE_CASE__  (							self						:   Any	)					->		Union[str, Any]:




           '''simple docstring'''


           return {
               "image_mean": self.image_mean,
               "image_std": self.image_std,
               "do_normalize": self.do_normalize,
               "do_resize": self.do_resize,
               "size": self.size,
           }

@require_torch
@require_vision
class 		UpperCamelCase__			(				lowerCAmelCase_							,				unittest.TestCase       ):



     '''simple docstring'''

     __snake_case   :     Tuple		     =      DPTImageProcessor if is_vision_available() else None






     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]	)					->		Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						DPTImageProcessingTester(self	)






     @property
     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]	)					->		int:




           '''simple docstring'''


           return self.image_processor_tester.prepare_image_processor_dict()






     def     SCREAMING_SNAKE_CASE__  (							self						:   Dict	)					->		List[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.image_processing_class(**self.image_processor_dict	)
           self.assertTrue(hasattr(lowerCamelCase__						,"""image_mean"""	)	)
           self.assertTrue(hasattr(lowerCamelCase__						,"""image_std"""	)	)
           self.assertTrue(hasattr(lowerCamelCase__						,"""do_normalize"""	)	)
           self.assertTrue(hasattr(lowerCamelCase__						,"""do_resize"""	)	)
           self.assertTrue(hasattr(lowerCamelCase__						,"""size"""	)	)






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.image_processing_class.from_dict(self.image_processor_dict	)
           self.assertEqual(image_processor.size						,{"""height""": 18, """width""": 18}	)

           SCREAMING_SNAKE_CASE		=						self.image_processing_class.from_dict(self.image_processor_dict						,size=42	)
           self.assertEqual(image_processor.size						,{"""height""": 42, """width""": 42}	)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Union[str, Any]	)					->		Optional[int]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.image_processing_class(**self.image_processor_dict	)
           # create random PIL images
           SCREAMING_SNAKE_CASE		=						prepare_image_inputs(self.image_processor_tester						,equal_resolution=lowerCamelCase__	)
           for image in image_inputs:
                 self.assertIsInstance(lowerCamelCase__						,Image.Image	)

           # Test not batched input
           SCREAMING_SNAKE_CASE		=						image_processing(image_inputs[0]						,return_tensors="""pt"""	).pixel_values
           self.assertEqual(
               encoded_images.shape						,(
                   1,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.size["""height"""],
                   self.image_processor_tester.size["""width"""],
               )						,)

           # Test batched
           SCREAMING_SNAKE_CASE		=						image_processing(lowerCamelCase__						,return_tensors="""pt"""	).pixel_values
           self.assertEqual(
               encoded_images.shape						,(
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.size["""height"""],
                   self.image_processor_tester.size["""width"""],
               )						,)






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




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.image_processing_class(**self.image_processor_dict	)
           # create random numpy tensors
           SCREAMING_SNAKE_CASE		=						prepare_image_inputs(self.image_processor_tester						,equal_resolution=lowerCamelCase__						,numpify=lowerCamelCase__	)
           for image in image_inputs:
                 self.assertIsInstance(lowerCamelCase__						,np.ndarray	)

           # Test not batched input
           SCREAMING_SNAKE_CASE		=						image_processing(image_inputs[0]						,return_tensors="""pt"""	).pixel_values
           self.assertEqual(
               encoded_images.shape						,(
                   1,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.size["""height"""],
                   self.image_processor_tester.size["""width"""],
               )						,)

           # Test batched
           SCREAMING_SNAKE_CASE		=						image_processing(lowerCamelCase__						,return_tensors="""pt"""	).pixel_values
           self.assertEqual(
               encoded_images.shape						,(
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.size["""height"""],
                   self.image_processor_tester.size["""width"""],
               )						,)






     def     SCREAMING_SNAKE_CASE__  (							self						:   Tuple	)					->		Optional[int]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE		=						self.image_processing_class(**self.image_processor_dict	)
           # create random PyTorch tensors
           SCREAMING_SNAKE_CASE		=						prepare_image_inputs(self.image_processor_tester						,equal_resolution=lowerCamelCase__						,torchify=lowerCamelCase__	)
           for image in image_inputs:
                 self.assertIsInstance(lowerCamelCase__						,torch.Tensor	)

           # Test not batched input
           SCREAMING_SNAKE_CASE		=						image_processing(image_inputs[0]						,return_tensors="""pt"""	).pixel_values
           self.assertEqual(
               encoded_images.shape						,(
                   1,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.size["""height"""],
                   self.image_processor_tester.size["""width"""],
               )						,)

           # Test batched
           SCREAMING_SNAKE_CASE		=						image_processing(lowerCamelCase__						,return_tensors="""pt"""	).pixel_values
           self.assertEqual(
               encoded_images.shape						,(
                   self.image_processor_tester.batch_size,
                   self.image_processor_tester.num_channels,
                   self.image_processor_tester.size["""height"""],
                   self.image_processor_tester.size["""width"""],
               )						,)


