
'''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'''







import math
def       snake_case_	(       __SCREAMING_SNAKE_CASE      :				int							):



						"""simple docstring"""





						if 1 < number < 4:
												# 2 and 3 are primes
												return True
						elif number < 2 or number % 2 == 0 or number % 3 == 0:
												# Negatives, 0, 1, all even numbers, all multiples of 3 are not primes
												return False

						# All primes number are in format of 6k +/- 1
						for i in range(5   ,   int(math.sqrt(__SCREAMING_SNAKE_CASE							) + 1							)   ,   6							):
												if number % i == 0 or number % (i + 2) == 0:
																		return False
						return True
def       snake_case_	(       __SCREAMING_SNAKE_CASE      :				int = 600851475143							):



						"""simple docstring"""





						try:
												lowercase_			:  List[str]									= int(__SCREAMING_SNAKE_CASE							)
						except (TypeError, ValueError):
												raise TypeError('''Parameter n must be int or castable to int.'''							)
						if n <= 0:
												raise ValueError('''Parameter n must be greater than or equal to one.'''							)
						lowercase_			:  Tuple									= 0
						if is_prime(__SCREAMING_SNAKE_CASE							):
												return n
						while n % 2 == 0:
												n //= 2
						if is_prime(__SCREAMING_SNAKE_CASE							):
												return n
						for i in range(3   ,   int(math.sqrt(__SCREAMING_SNAKE_CASE							)							) + 1   ,   2							):
												if n % i == 0:
																		if is_prime(n // i							):
																								lowercase_			:  str									= n // i
																								break
																		elif is_prime(__SCREAMING_SNAKE_CASE							):
																								lowercase_			:  Optional[Any]									= i
						return max_number


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



