





from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve





def  __UpperCamelCase   (     a,  a,  a)			->np.ndarray:
					lowerCamelCase__      =							np.stack((horizontal_flow, vertical_flow),  2)

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

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

					lowerCamelCase__      =							image[grid[:, :, 1], grid[:, :, 0]]

					# Set pixels at invalid locations to 0
					lowerCamelCase__      =							0

					return warped





def  __UpperCamelCase   (     a,  a,  a,  a = None,  )			->tuple[np.ndarray, np.ndarray]:
					if alpha is None:
										lowerCamelCase__      =							0.1

					# Initialize flow
					lowerCamelCase__      =							np.zeros_like(a)
					lowerCamelCase__      =							np.zeros_like(a)

					# Prepare kernels for the calculation of the derivatives and the average velocity
					lowerCamelCase__      =							np.array([[-1, 1], [-1, 1]]) * 0.2_5
					lowerCamelCase__      =							np.array([[-1, -1], [1, 1]]) * 0.2_5
					lowerCamelCase__      =							np.array([[1, 1], [1, 1]]) * 0.2_5
					lowerCamelCase__      =							np.array(
					    [[1 / 12, 1 / 6, 1 / 12], [1 / 6, 0, 1 / 6], [1 / 12, 1 / 6, 1 / 12]])

					# Iteratively refine the flow
					for _ in range(a):
										lowerCamelCase__      =							warp(a,  a,  a)
										lowerCamelCase__      =							convolve(a,  a) + convolve(a,  a)
										lowerCamelCase__      =							convolve(a,  a) + convolve(a,  a)
										lowerCamelCase__      =							convolve(a,  a) + convolve(a,  -kernel_t)

										lowerCamelCase__      =							convolve(a,  a)
										lowerCamelCase__      =							convolve(a,  a)

										# This updates the flow as proposed in the paper (Step 12)
										lowerCamelCase__      =							(
										    derivative_x * avg_horizontal_velocity
										    + derivative_y * avg_vertical_velocity
										    + derivative_t
										)
										lowerCamelCase__      =							update / (alpha**2 + derivative_x**2 + derivative_y**2)

										lowerCamelCase__      =							avg_horizontal_velocity - derivative_x * update
										lowerCamelCase__      =							avg_vertical_velocity - derivative_y * update

					return horizontal_flow, vertical_flow


if __name__ == "__main__":
						import doctest

						doctest.testmod()








def  __UpperCamelCase   (     a = 998001)			->int:

					# fetches the next number
					for number in range(n - 1,  9999,  -1):
										lowerCamelCase__      =							str(a)

										# checks whether 'str_number' is a palindrome.
										if str_number == str_number[::-1]:
															lowerCamelCase__      =							999

															# if 'number' is a product of two 3-digit numbers
															# then number is the answer otherwise fetch next number.
															while divisor != 99:
																				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() = }""")

