"""simple docstring"""




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      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	List[Any]     )							-> Dict:  # picklable for multiprocessing







  """simple docstring"""





  return i + 1



@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def      __SCREAMING_SNAKE_CASE  ( )							-> Union[str, Any]:







  """simple docstring"""





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

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

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






@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize("""num_proc"""			,					[2, -1]     )
def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	Optional[Any]     )							-> int:







  """simple docstring"""





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

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

import PIL.Image
import PIL.ImageOps
from packaging import version
from PIL import Image


if version.parse(version.parse(PIL.__version__).base_version) >= version.parse('''9.1.0'''):
   __lowerCamelCase      :			Optional[Any]							       =		{
       '''linear''': PIL.Image.Resampling.BILINEAR,
       '''bilinear''': PIL.Image.Resampling.BILINEAR,
       '''bicubic''': PIL.Image.Resampling.BICUBIC,
       '''lanczos''': PIL.Image.Resampling.LANCZOS,
       '''nearest''': PIL.Image.Resampling.NEAREST,
   }
else:
   __lowerCamelCase      :			int							       =		{
       '''linear''': PIL.Image.LINEAR,
       '''bilinear''': PIL.Image.BILINEAR,
       '''bicubic''': PIL.Image.BICUBIC,
       '''lanczos''': PIL.Image.LANCZOS,
       '''nearest''': PIL.Image.NEAREST,
   }



def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	int     )							-> Optional[Any]:







  """simple docstring"""





  SCREAMING_SNAKE_CASE__      							=				(images / 2 + 0.5).clamp(0			,					1     )
  SCREAMING_SNAKE_CASE__      							=				images.cpu().permute(0			,					2			,					3			,					1     ).float().numpy()
  SCREAMING_SNAKE_CASE__      							=				numpy_to_pil(__UpperCamelCase     )
  return images






def      __SCREAMING_SNAKE_CASE  ( __UpperCamelCase   :	int     )							-> int:







  """simple docstring"""





  if images.ndim == 3:
    SCREAMING_SNAKE_CASE__      							=				images[None, ...]
  SCREAMING_SNAKE_CASE__      							=				(images * 2_55).round().astype("""uint8"""     )
  if images.shape[-1] == 1:
    # special case for grayscale (single channel) images
    SCREAMING_SNAKE_CASE__      							=				[Image.fromarray(image.squeeze()			,					mode="""L"""     ) for image in images]
  else:
    SCREAMING_SNAKE_CASE__      							=				[Image.fromarray(__UpperCamelCase     ) for image in images]

  return pil_images
