



from typing import SupportsIndex

import numpy as np
from scipy.ndimage import convolve

def       A_   (						__a  :					np.ndarray			,		__a  :					np.ndarray			,		__a  :					np.ndarray		):

				"""simple docstring"""
				a__					   =		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__					   =		np.stack(
				    np.meshgrid(np.arange(0			,		image.shape[1]		)			,		np.arange(0			,		image.shape[0]		)		)			,		2		)
				a__					   =		np.round(grid - flow		).astype(np.intaa		)

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

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

				# Set pixels at invalid locations to 0
				a__					   =		0

				return warped

def       A_   (						__a  :					np.ndarray			,		__a  :					np.ndarray			,		__a  :					SupportsIndex			,		__a  :					float | None = None			,		):

				"""simple docstring"""
				if alpha is None:
								a__					   =		0.1

				# Initialize flow
				a__					   =		np.zeros_like(__a		)
				a__					   =		np.zeros_like(__a		)

				# Prepare kernels for the calculation of the derivatives and the average velocity
				a__					   =		np.array([[-1, 1], [-1, 1]]		) * 0.2_5
				a__					   =		np.array([[-1, -1], [1, 1]]		) * 0.2_5
				a__					   =		np.array([[1, 1], [1, 1]]		) * 0.2_5
				a__					   =		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		):
								a__					   =		warp(__a			,		__a			,		__a		)
								a__					   =		convolve(__a			,		__a		) + convolve(__a			,		__a		)
								a__					   =		convolve(__a			,		__a		) + convolve(__a			,		__a		)
								a__					   =		convolve(__a			,		__a		) + convolve(__a			,		-kernel_t		)

								a__					   =		convolve(__a			,		__a		)
								a__					   =		convolve(__a			,		__a		)

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

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

				return horizontal_flow, vertical_flow


if __name__ == "__main__":
	import doctest

	doctest.testmod()


import unittest

from transformers import is_torch_available, load_tool

from .test_tools_common import ToolTesterMixin


if is_torch_available():
   import torch







class __snake_case							(		unittest.TestCase  ,						lowerCamelCase_						):




   def       __a		(       self     :							Dict ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= load_tool("""speech-to-text""" )
     self.tool.setup()




   def       __a		(       self     :							Tuple ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= self.tool(torch.ones(30_00 ) )
     self.assertEqual(_lowercase			,      """ you""" )




   def       __a		(       self     :							Any ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__     				= self.tool(audio=torch.ones(30_00 ) )
     self.assertEqual(_lowercase			,      """ you""" )
