



'''simple docstring'''





from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve



def     UpperCAmelCase     (    a_      ,		a_      ,		a_		)   ->       np.ndarray:



   """simple docstring"""






   A_  :		Tuple						=					np.stack((horizontal_flow, vertical_flow)      ,		2		)

   # Create a grid of all pixel coordinates and subtract the flow to get the
   # target pixels coordinates
   A_  :		Any						=					np.stack(
       np.meshgrid(np.arange(0      ,		image.shape[1]		)      ,		np.arange(0      ,		image.shape[0]		)		)      ,		2		)
   A_  :		Any						=					np.round(grid - flow		).astype(np.intaa		)

   # Find the locations outside of the original image
   A_  :		List[str]						=					(grid < 0) | (grid >= np.array([image.shape[1], image.shape[0]]		))
   A_  :		Dict						=					0

   A_  :		int						=					image[grid[:, :, 1], grid[:, :, 0]]

   # Set pixels at invalid locations to 0
   A_  :		Dict						=					0

   return warped



def     UpperCAmelCase     (    a_      ,		a_      ,		a_      ,		a_ = None      ,		)   ->       tuple[np.ndarray, np.ndarray]:



   """simple docstring"""






   if alpha is None:
      A_  :		int						=					0.1

   # Initialize flow
   A_  :		int						=					np.zeros_like(a_		)
   A_  :		Tuple						=					np.zeros_like(a_		)

   # Prepare kernels for the calculation of the derivatives and the average velocity
   A_  :		Any						=					np.array([[-1, 1], [-1, 1]]		) * 0.25
   A_  :		Optional[int]						=					np.array([[-1, -1], [1, 1]]		) * 0.25
   A_  :		List[Any]						=					np.array([[1, 1], [1, 1]]		) * 0.25
   A_  :		Any						=					np.array(
       [[1 / 1_2, 1 / 6, 1 / 1_2], [1 / 6, 0, 1 / 6], [1 / 1_2, 1 / 6, 1 / 1_2]]		)

   # Iteratively refine the flow
   for _ in range(a_		):
      A_  :		Any						=					warp(a_      ,		a_      ,		a_		)
      A_  :		int						=					convolve(a_      ,		a_		) + convolve(a_      ,		a_		)
      A_  :		Optional[int]						=					convolve(a_      ,		a_		) + convolve(a_      ,		a_		)
      A_  :		Optional[Any]						=					convolve(a_      ,		a_		) + convolve(a_      ,		-kernel_t		)

      A_  :		List[Any]						=					convolve(a_      ,		a_		)
      A_  :		List[str]						=					convolve(a_      ,		a_		)

      # This updates the flow as proposed in the paper (Step 12)
      A_  :		int						=					(
          derivative_x * avg_horizontal_velocity
          + derivative_y * avg_vertical_velocity
          + derivative_t
      )
      A_  :		List[Any]						=					update / (alpha**2 + derivative_x**2 + derivative_y**2)

      A_  :		Tuple						=					avg_horizontal_velocity - derivative_x * update
      A_  :		Dict						=					avg_vertical_velocity - derivative_y * update

   return horizontal_flow, vertical_flow


if __name__ == "__main__":
  import doctest

  doctest.testmod()





'''simple docstring'''





def     UpperCAmelCase     (    a_ = 9_9_8_0_0_1		)   ->       int:



   """simple docstring"""






   for number in range(n - 1      ,		9_9_9_9      ,		-1		):
      A_  :		Optional[Any]						=					str(a_		)

      # checks whether 'str_number' is a palindrome.
      if str_number == str_number[::-1]:
         A_  :		int						=					9_9_9

         # if 'number' is a product of two 3-digit numbers
         # then number is the answer otherwise fetch next number.
         while divisor != 9_9:
            if (number % divisor == 0) and (len(str(number // divisor		)		) == 3.0):
               return number
            divisor -= 1
   raise ValueError("""That number is larger than our acceptable range."""		)


if __name__ == "__main__":
  print(f'{solution() = }')
