


import pytest

from datasets.parallel import ParallelBackendConfig, parallel_backend
from datasets.utils.py_utils import map_nested

from .utils import require_dill_gt_0_3_2, require_joblibspark, require_not_windows






def 					UpperCamelCase   (      __magic_name__	:				List[str]	)  ->    Dict:  # picklable for multiprocessing
		"""simple docstring"""




		return i + 1






@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 					UpperCamelCase   (      )  ->    Optional[Any]:
		"""simple docstring"""




		with parallel_backend("""spark"""	):
				assert ParallelBackendConfig.backend_name == "spark"

		lowercase__	     =						[1, 2, 3]
		with pytest.raises(__magic_name__	):
				with parallel_backend("""unsupported backend"""	):
						map_nested(__magic_name__       ,       __magic_name__       ,       num_proc=2	)

		with pytest.raises(__magic_name__	):
				with parallel_backend("""unsupported backend"""	):
						map_nested(__magic_name__       ,       __magic_name__       ,       num_proc=-1	)







@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize("""num_proc"""       ,       [2, -1]	)
def 					UpperCamelCase   (      __magic_name__	:				int	)  ->    int:
		"""simple docstring"""




		lowercase__	     =						[1, 2]
		lowercase__	     =						{"""a""": 1, """b""": 2}
		lowercase__	     =						{"""a""": [1, 2], """b""": [3, 4]}
		lowercase__	     =						{"""a""": {"""1""": 1}, """b""": 2}
		lowercase__	     =						{"""a""": 1, """b""": 2, """c""": 3, """d""": 4}
		lowercase__	     =						[2, 3]
		lowercase__	     =						{"""a""": 2, """b""": 3}
		lowercase__	     =						{"""a""": [2, 3], """b""": [4, 5]}
		lowercase__	     =						{"""a""": {"""1""": 2}, """b""": 3}
		lowercase__	     =						{"""a""": 2, """b""": 3, """c""": 4, """d""": 5}

		with parallel_backend("""spark"""	):
				assert map_nested(__magic_name__       ,       __magic_name__       ,       num_proc=__magic_name__	) == expected_map_nested_sa
				assert map_nested(__magic_name__       ,       __magic_name__       ,       num_proc=__magic_name__	) == expected_map_nested_sa
				assert map_nested(__magic_name__       ,       __magic_name__       ,       num_proc=__magic_name__	) == expected_map_nested_sa
				assert map_nested(__magic_name__       ,       __magic_name__       ,       num_proc=__magic_name__	) == expected_map_nested_sa
				assert map_nested(__magic_name__       ,       __magic_name__       ,       num_proc=__magic_name__	) == expected_map_nested_sa








"""simple docstring"""





class 						lowercase   :





      def __init__(			self					)						->	Any:
            lowerCAmelCase    		=			""""""
            lowerCAmelCase    		=			""""""
            lowerCAmelCase    		=			[]





      def        _snake_case     (			self ,		lowercase ,		lowercase					)						->	int:
            if m == -1:
                  return n + 1
            elif n == -1:
                  return m + 1
            elif self.dp[m][n] > -1:
                  return self.dp[m][n]
            else:
                  if self.worda[m] == self.worda[n]:
                        lowerCAmelCase    		=			self.__min_dist_top_down_dp(m - 1 ,		n - 1					)
                  else:
                        lowerCAmelCase    		=			self.__min_dist_top_down_dp(lowercase ,		n - 1					)
                        lowerCAmelCase    		=			self.__min_dist_top_down_dp(m - 1 ,		lowercase					)
                        lowerCAmelCase    		=			self.__min_dist_top_down_dp(m - 1 ,		n - 1					)
                        lowerCAmelCase    		=			1 + min(lowercase ,		lowercase ,		lowercase					)

                  return self.dp[m][n]





      def        _snake_case     (			self ,		lowercase ,		lowercase					)						->	int:
            lowerCAmelCase    		=			worda
            lowerCAmelCase    		=			worda
            lowerCAmelCase    		=			[[-1 for _ in range(len(lowercase					)					)] for _ in range(len(lowercase					)					)]

            return self.__min_dist_top_down_dp(len(lowercase					) - 1 ,		len(lowercase					) - 1					)





      def        _snake_case     (			self ,		lowercase ,		lowercase					)						->	int:
            lowerCAmelCase    		=			worda
            lowerCAmelCase    		=			worda
            lowerCAmelCase    		=			len(lowercase					)
            lowerCAmelCase    		=			len(lowercase					)
            lowerCAmelCase    		=			[[0 for _ in range(n + 1					)] for _ in range(m + 1					)]

            for i in range(m + 1					):
                  for j in range(n + 1					):
                        if i == 0:  # first string is empty
                              lowerCAmelCase    		=			j
                        elif j == 0:  # second string is empty
                              lowerCAmelCase    		=			i
                        elif worda[i - 1] == worda[j - 1]:  # last characters are equal
                              lowerCAmelCase    		=			self.dp[i - 1][j - 1]
                        else:
                              lowerCAmelCase    		=			self.dp[i][j - 1]
                              lowerCAmelCase    		=			self.dp[i - 1][j]
                              lowerCAmelCase    		=			self.dp[i - 1][j - 1]
                              lowerCAmelCase    		=			1 + min(lowercase ,		lowercase ,		lowercase					)
            return self.dp[m][n]


if __name__ == "__main__":
       SCREAMING_SNAKE_CASE__   =  EditDistance()

       print("****************** Testing Edit Distance DP Algorithm ******************")
       print()

       SCREAMING_SNAKE_CASE__   =  input("Enter the first string: ").strip()
       SCREAMING_SNAKE_CASE__   =  input("Enter the second string: ").strip()

       print()
       print(f'The minimum edit distance is: {solver.min_dist_top_down(Sa, Sa)}')
       print(f'The minimum edit distance is: {solver.min_dist_bottom_up(Sa, Sa)}')
       print()
       print("*************** End of Testing Edit Distance DP Algorithm ***************")






