
'''simple docstring'''







from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve
def       snake_case_	(       __SCREAMING_SNAKE_CASE      :				np.ndarray   ,   __SCREAMING_SNAKE_CASE      :				np.ndarray   ,   __SCREAMING_SNAKE_CASE      :				np.ndarray							):



						"""simple docstring"""





						lowercase_			:  Optional[Any]									= np.stack((horizontal_flow, vertical_flow)   ,   2							)

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

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

						lowercase_			:  Union[str, Any]									= image[grid[:, :, 1], grid[:, :, 0]]

						# Set pixels at invalid locations to 0
						lowercase_			:  Any									= 0

						return warped
def       snake_case_	(       __SCREAMING_SNAKE_CASE      :				np.ndarray   ,   __SCREAMING_SNAKE_CASE      :				np.ndarray   ,   __SCREAMING_SNAKE_CASE      :				SupportsIndex   ,   __SCREAMING_SNAKE_CASE      :				float | None = None   ,   ):



						"""simple docstring"""





						if alpha is None:
												lowercase_			:  Dict									= 0.1

						# Initialize flow
						lowercase_			:  List[Any]									= np.zeros_like(__SCREAMING_SNAKE_CASE							)
						lowercase_			:  Union[str, Any]									= np.zeros_like(__SCREAMING_SNAKE_CASE							)

						# Prepare kernels for the calculation of the derivatives and the average velocity
						lowercase_			:  List[str]									= np.array([[-1, 1], [-1, 1]]							) * 0.25
						lowercase_			:  Optional[Any]									= np.array([[-1, -1], [1, 1]]							) * 0.25
						lowercase_			:  Tuple									= np.array([[1, 1], [1, 1]]							) * 0.25
						lowercase_			:  Optional[int]									= 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(__SCREAMING_SNAKE_CASE							):
												lowercase_			:  Dict									= warp(__SCREAMING_SNAKE_CASE   ,   __SCREAMING_SNAKE_CASE   ,   __SCREAMING_SNAKE_CASE							)
												lowercase_			:  Optional[Any]									= convolve(__SCREAMING_SNAKE_CASE   ,   __SCREAMING_SNAKE_CASE							) + convolve(__SCREAMING_SNAKE_CASE   ,   __SCREAMING_SNAKE_CASE							)
												lowercase_			:  Tuple									= convolve(__SCREAMING_SNAKE_CASE   ,   __SCREAMING_SNAKE_CASE							) + convolve(__SCREAMING_SNAKE_CASE   ,   __SCREAMING_SNAKE_CASE							)
												lowercase_			:  int									= convolve(__SCREAMING_SNAKE_CASE   ,   __SCREAMING_SNAKE_CASE							) + convolve(__SCREAMING_SNAKE_CASE   ,   -kernel_t							)

												lowercase_			:  Optional[int]									= convolve(__SCREAMING_SNAKE_CASE   ,   __SCREAMING_SNAKE_CASE							)
												lowercase_			:  Optional[int]									= convolve(__SCREAMING_SNAKE_CASE   ,   __SCREAMING_SNAKE_CASE							)

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

												lowercase_			:  List[Any]									= avg_horizontal_velocity - derivative_x * update
												lowercase_			:  Any									= avg_vertical_velocity - derivative_y * update

						return horizontal_flow, vertical_flow


if __name__ == "__main__":
							import doctest

							doctest.testmod()








'''simple docstring'''







def       snake_case_	(       __SCREAMING_SNAKE_CASE      :				int = 1000							):



						"""simple docstring"""





						lowercase_			:  List[Any]									= 0
						for i in range(__SCREAMING_SNAKE_CASE							):
												if i % 3 == 0 or i % 5 == 0:
																		result += i
						return result


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



