





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  (_SCREAMING_SNAKE_CASE		)    ->       List[Any]:  # picklable for multiprocessing
  return i + 1




@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 					__UpperCamelCase  ()    ->       Optional[int]:
  with parallel_backend('spark'		):
    assert ParallelBackendConfig.backend_name == "spark"

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

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




@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize('num_proc'		,						[2, -1]		)
def 					__UpperCamelCase  (_SCREAMING_SNAKE_CASE		)    ->       Optional[int]:
  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(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						num_proc=_SCREAMING_SNAKE_CASE		) == expected_map_nested_sa
    assert map_nested(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						num_proc=_SCREAMING_SNAKE_CASE		) == expected_map_nested_sa
    assert map_nested(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						num_proc=_SCREAMING_SNAKE_CASE		) == expected_map_nested_sa
    assert map_nested(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						num_proc=_SCREAMING_SNAKE_CASE		) == expected_map_nested_sa
    assert map_nested(_SCREAMING_SNAKE_CASE		,						_SCREAMING_SNAKE_CASE		,						num_proc=_SCREAMING_SNAKE_CASE		) == expected_map_nested_sa









from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


lowercase_          =		{
    """configuration_efficientformer""": [
        """EFFICIENTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """EfficientFormerConfig""",
    ]
}

try:
      if not is_vision_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_          =		["""EfficientFormerImageProcessor"""]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_          =		[
          """EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """EfficientFormerForImageClassification""",
          """EfficientFormerForImageClassificationWithTeacher""",
          """EfficientFormerModel""",
          """EfficientFormerPreTrainedModel""",
      ]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_          =		[
          """TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """TFEfficientFormerForImageClassification""",
          """TFEfficientFormerForImageClassificationWithTeacher""",
          """TFEfficientFormerModel""",
          """TFEfficientFormerPreTrainedModel""",
      ]

if TYPE_CHECKING:
      from .configuration_efficientformer import EFFICIENTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, EfficientFormerConfig

      try:
            if not is_vision_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .image_processing_efficientformer import EfficientFormerImageProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_efficientformer import (
                EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                EfficientFormerForImageClassification,
                EfficientFormerForImageClassificationWithTeacher,
                EfficientFormerModel,
                EfficientFormerPreTrainedModel,
            )
      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_efficientformer import (
                TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFEfficientFormerForImageClassification,
                TFEfficientFormerForImageClassificationWithTeacher,
                TFEfficientFormerModel,
                TFEfficientFormerPreTrainedModel,
            )

else:
      import sys

      lowercase_          =		_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


