
from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve


def       UpperCAmelCase_					(  __lowerCAmelCase		,   __lowerCAmelCase		,   __lowerCAmelCase		)	->  np.ndarray:
    __lowercase						:     Dict		      =    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						:     Tuple		      =    np.stack(
        np.meshgrid(np.arange(0		,   image.shape[1]		)		,   np.arange(0		,   image.shape[0]		)		)		,   2		)
    __lowercase						:     Dict		      =    np.round(grid - flow		).astype(np.intaa		)

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

    __lowercase						:     Optional[int]		      =    image[grid[:, :, 1], grid[:, :, 0]]

    # Set pixels at invalid locations to 0
    __lowercase						:     Optional[Any]		      =    0

    return warped


def       UpperCAmelCase_					(  __lowerCAmelCase		,   __lowerCAmelCase		,   __lowerCAmelCase		,   __lowerCAmelCase = None		,   )	->  tuple[np.ndarray, np.ndarray]:
    if alpha is None:
        __lowercase						:     Optional[int]		      =    0.1

    # Initialize flow
    __lowercase						:     Dict		      =    np.zeros_like(__lowerCAmelCase		)
    __lowercase						:     Dict		      =    np.zeros_like(__lowerCAmelCase		)

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

        __lowercase						:     int		      =    convolve(__lowerCAmelCase		,   __lowerCAmelCase		)
        __lowercase						:     Any		      =    convolve(__lowerCAmelCase		,   __lowerCAmelCase		)

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

        __lowercase						:     int		      =    avg_horizontal_velocity - derivative_x * update
        __lowercase						:     Optional[Any]		      =    avg_vertical_velocity - derivative_y * update

    return horizontal_flow, vertical_flow


if __name__ == "__main__":
 import doctest

 doctest.testmod()




from __future__ import annotations

import math
from itertools import permutations


def       UpperCAmelCase_					(  __lowerCAmelCase		)	->  bool:

    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(__lowerCAmelCase		) + 1		)		,   6		):
        if number % i == 0 or number % (i + 2) == 0:
            return False
    return True


def       UpperCAmelCase_					(  __lowerCAmelCase = 7		)	->  int:
    __lowercase						:     Union[str, Any]		      =    ''''''.join(str(__lowerCAmelCase		) for i in range(1		,   n + 1		)		)
    __lowercase						:     Dict		      =    [int(''''''.join(__lowerCAmelCase		)		) for i in permutations(__lowerCAmelCase		,   __lowerCAmelCase		)]
    __lowercase						:     int		      =    [num for num in perm_list if is_prime(__lowerCAmelCase		)]
    return max(__lowerCAmelCase		) if pandigitals else 0


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


