





import inspect
import unittest

from transformers import ViTConfig
from transformers.testing_utils import (
    require_accelerate,
    require_torch,
    require_torch_gpu,
    require_vision,
    slow,
    torch_device,
)
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch
    from torch import nn

    from transformers import ViTForImageClassification, ViTForMaskedImageModeling, ViTModel
    from transformers.models.vit.modeling_vit import VIT_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
    from PIL import Image

    from transformers import ViTImageProcessor



class       A__     :





      def __init__(				self ,							A_ ,							A_=13 ,							A_=30 ,							A_=2 ,							A_=3 ,							A_=True ,							A_=True ,							A_=32 ,							A_=5 ,							A_=4 ,							A_=37 ,							A_="gelu" ,							A_=0.1 ,							A_=0.1 ,							A_=10 ,							A_=0.02 ,							A_=None ,							A_=2 ,							):
       '''simple docstring'''




       UpperCamelCase			:      List[Any] 			=     parent
       UpperCamelCase			:      Optional[Any] 			=     batch_size
       UpperCamelCase			:      Optional[int] 			=     image_size
       UpperCamelCase			:      Optional[int] 			=     patch_size
       UpperCamelCase			:      str 			=     num_channels
       UpperCamelCase			:      List[str] 			=     is_training
       UpperCamelCase			:      int 			=     use_labels
       UpperCamelCase			:      Optional[Any] 			=     hidden_size
       UpperCamelCase			:      List[str] 			=     num_hidden_layers
       UpperCamelCase			:      Dict 			=     num_attention_heads
       UpperCamelCase			:      Tuple 			=     intermediate_size
       UpperCamelCase			:      Optional[Any] 			=     hidden_act
       UpperCamelCase			:      Optional[int] 			=     hidden_dropout_prob
       UpperCamelCase			:      Union[str, Any] 			=     attention_probs_dropout_prob
       UpperCamelCase			:      List[str] 			=     type_sequence_label_size
       UpperCamelCase			:      List[Any] 			=     initializer_range
       UpperCamelCase			:      Union[str, Any] 			=     scope
       UpperCamelCase			:      Union[str, Any] 			=     encoder_stride

       # in ViT, the seq length equals the number of patches + 1 (we add 1 for the [CLS] token)
       UpperCamelCase			:      Union[str, Any] 			=     (image_size // patch_size) ** 2
       UpperCamelCase			:      List[str] 			=     num_patches + 1





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Any 			=     floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

       UpperCamelCase			:      List[str] 			=     None
       if self.use_labels:
        UpperCamelCase			:      List[str] 			=     ids_tensor([self.batch_size] ,							self.type_sequence_label_size     )

       UpperCamelCase			:      str 			=     self.get_config()

       return config, pixel_values, labels





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       return ViTConfig(
           image_size=self.image_size ,							patch_size=self.patch_size ,							num_channels=self.num_channels ,							hidden_size=self.hidden_size ,							num_hidden_layers=self.num_hidden_layers ,							num_attention_heads=self.num_attention_heads ,							intermediate_size=self.intermediate_size ,							hidden_act=self.hidden_act ,							hidden_dropout_prob=self.hidden_dropout_prob ,							attention_probs_dropout_prob=self.attention_probs_dropout_prob ,							is_decoder=lowerCamelCase_ ,							initializer_range=self.initializer_range ,							encoder_stride=self.encoder_stride ,							)





      def  __UpperCamelCase(				self ,							A_ ,							A_ ,							A_     ):
       '''simple docstring'''




       UpperCamelCase			:      Union[str, Any] 			=     ViTModel(config=lowerCamelCase_     )
       model.to(lowerCamelCase_     )
       model.eval()
       UpperCamelCase			:      List[Any] 			=     model(lowerCamelCase_     )
       self.parent.assertEqual(result.last_hidden_state.shape ,							(self.batch_size, self.seq_length, self.hidden_size)     )





      def  __UpperCamelCase(				self ,							A_ ,							A_ ,							A_     ):
       '''simple docstring'''




       UpperCamelCase			:      List[str] 			=     ViTForMaskedImageModeling(config=lowerCamelCase_     )
       model.to(lowerCamelCase_     )
       model.eval()
       UpperCamelCase			:      Union[str, Any] 			=     model(lowerCamelCase_     )
       self.parent.assertEqual(
           result.reconstruction.shape ,							(self.batch_size, self.num_channels, self.image_size, self.image_size)     )

       # test greyscale images
       UpperCamelCase			:      int 			=     1
       UpperCamelCase			:      Union[str, Any] 			=     ViTForMaskedImageModeling(lowerCamelCase_     )
       model.to(lowerCamelCase_     )
       model.eval()

       UpperCamelCase			:      Optional[int] 			=     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
       UpperCamelCase			:      int 			=     model(lowerCamelCase_     )
       self.parent.assertEqual(result.reconstruction.shape ,							(self.batch_size, 1, self.image_size, self.image_size)     )





      def  __UpperCamelCase(				self ,							A_ ,							A_ ,							A_     ):
       '''simple docstring'''




       UpperCamelCase			:      Union[str, Any] 			=     self.type_sequence_label_size
       UpperCamelCase			:      Tuple 			=     ViTForImageClassification(lowerCamelCase_     )
       model.to(lowerCamelCase_     )
       model.eval()
       UpperCamelCase			:      List[Any] 			=     model(lowerCamelCase_ ,							labels=lowerCamelCase_     )
       self.parent.assertEqual(result.logits.shape ,							(self.batch_size, self.type_sequence_label_size)     )

       # test greyscale images
       UpperCamelCase			:      Union[str, Any] 			=     1
       UpperCamelCase			:      Union[str, Any] 			=     ViTForImageClassification(lowerCamelCase_     )
       model.to(lowerCamelCase_     )
       model.eval()

       UpperCamelCase			:      List[str] 			=     floats_tensor([self.batch_size, 1, self.image_size, self.image_size]     )
       UpperCamelCase			:      List[Any] 			=     model(lowerCamelCase_     )
       self.parent.assertEqual(result.logits.shape ,							(self.batch_size, self.type_sequence_label_size)     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Optional[int] 			=     self.prepare_config_and_inputs()
       (
           UpperCamelCase					
       )			:      List[Any] 			=     config_and_inputs
       UpperCamelCase			:      Optional[Any] 			=     {'''pixel_values''': pixel_values}
       return config, inputs_dict



@require_torch
class       A__     ( _UpperCAmelCase ,     _UpperCAmelCase ,     unittest.TestCase    ):
      _UpperCAmelCase			:List[str]							=     (
          (
              ViTModel,
              ViTForImageClassification,
              ViTForMaskedImageModeling,
          )
          if is_torch_available()
          else ()
      )
      _UpperCAmelCase			:str							=     (
          {'feature-extraction': ViTModel, 'image-classification': ViTForImageClassification}
          if is_torch_available()
          else {}
      )
      _UpperCAmelCase			:Any							=     True

      _UpperCAmelCase			:str							=     False
      _UpperCAmelCase			:List[Any]							=     False
      _UpperCAmelCase			:int							=     False





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Dict 			=     ViTModelTester(self     )
       UpperCamelCase			:      Any 			=     ConfigTester(self ,							config_class=lowerCamelCase_ ,							has_text_modality=lowerCamelCase_ ,							hidden_size=37     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       self.config_tester.run_common_tests()





      @unittest.skip(reason="ViT does not use inputs_embeds"     )
      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       pass





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      List[Any] 			=     self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
        UpperCamelCase			:      Dict 			=     model_class(lowerCamelCase_     )
        self.assertIsInstance(model.get_input_embeddings() ,							(nn.Module)     )
        UpperCamelCase			:      str 			=     model.get_output_embeddings()
        self.assertTrue(x is None or isinstance(lowerCamelCase_ ,							nn.Linear     )     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Dict 			=     self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
        UpperCamelCase			:      str 			=     model_class(lowerCamelCase_     )
        UpperCamelCase			:      Union[str, Any] 			=     inspect.signature(model.forward     )
        # signature.parameters is an OrderedDict => so arg_names order is deterministic
        UpperCamelCase			:      Tuple 			=     [*signature.parameters.keys()]

        UpperCamelCase			:      Optional[int] 			=     ['''pixel_values''']
        self.assertListEqual(arg_names[:1] ,							lowerCamelCase_     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      List[Any] 			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*lowerCamelCase_     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Dict 			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_masked_image_modeling(*lowerCamelCase_     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Optional[Any] 			=     self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*lowerCamelCase_     )





      @slow
      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       for model_name in VIT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
        UpperCamelCase			:      Any 			=     ViTModel.from_pretrained(lowerCamelCase_     )
        self.assertIsNotNone(lowerCamelCase_     )



def 	A_       (  ):
 UpperCamelCase			:      Union[str, Any] 			=     Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"  )
 return image



@require_torch
@require_vision
class       A__     ( unittest.TestCase    ):





      @cached_property
      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       return ViTImageProcessor.from_pretrained("google/vit-base-patch16-224"     ) if is_vision_available() else None





      @slow
      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Tuple 			=     ViTForImageClassification.from_pretrained("google/vit-base-patch16-224"     ).to(lowerCamelCase_     )

       UpperCamelCase			:      Union[str, Any] 			=     self.default_image_processor
       UpperCamelCase			:      Optional[Any] 			=     prepare_img()
       UpperCamelCase			:      Optional[int] 			=     image_processor(images=lowerCamelCase_ ,							return_tensors="pt"     ).to(lowerCamelCase_     )

       # forward pass
       with torch.no_grad():
        UpperCamelCase			:      int 			=     model(**lowerCamelCase_     )

       # verify the logits
       UpperCamelCase			:      List[str] 			=     torch.Size((1, 1000)     )
       self.assertEqual(outputs.logits.shape ,							lowerCamelCase_     )

       UpperCamelCase			:      int 			=     torch.tensor([-0.27_44, 0.82_15, -0.08_36]     ).to(lowerCamelCase_     )

       self.assertTrue(torch.allclose(outputs.logits[0, :3] ,							lowerCamelCase_ ,							atol=1e-4     )     )





      @slow
      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Dict 			=     ViTModel.from_pretrained("facebook/dino-vits8"     ).to(lowerCamelCase_     )

       UpperCamelCase			:      List[str] 			=     ViTImageProcessor.from_pretrained("facebook/dino-vits8" ,							size=480     )
       UpperCamelCase			:      int 			=     prepare_img()
       UpperCamelCase			:      int 			=     image_processor(images=lowerCamelCase_ ,							return_tensors="pt"     )
       UpperCamelCase			:      int 			=     inputs.pixel_values.to(lowerCamelCase_     )

       # forward pass
       with torch.no_grad():
        UpperCamelCase			:      List[str] 			=     model(lowerCamelCase_ ,							interpolate_pos_encoding=lowerCamelCase_     )

       # verify the logits
       UpperCamelCase			:      str 			=     torch.Size((1, 3601, 384)     )
       self.assertEqual(outputs.last_hidden_state.shape ,							lowerCamelCase_     )

       UpperCamelCase			:      List[Any] 			=     torch.tensor(
           [[4.23_40, 4.39_06, -6.66_92], [4.54_63, 1.89_28, -6.72_57], [4.44_29, 0.84_96, -5.85_85]]     ).to(lowerCamelCase_     )

       self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :3, :3] ,							lowerCamelCase_ ,							atol=1e-4     )     )





      @slow
      @require_accelerate
      @require_torch_gpu
      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Optional[Any] 			=     ViTModel.from_pretrained("facebook/dino-vits8" ,							torch_dtype=torch.floataa ,							device_map="auto"     )
       UpperCamelCase			:      str 			=     self.default_image_processor

       UpperCamelCase			:      Optional[int] 			=     prepare_img()
       UpperCamelCase			:      int 			=     image_processor(images=lowerCamelCase_ ,							return_tensors="pt"     )
       UpperCamelCase			:      Any 			=     inputs.pixel_values.to(lowerCamelCase_     )

       # forward pass to make sure inference works in fp16
       with torch.no_grad():
        UpperCamelCase			:      Any 			=     model(lowerCamelCase_     )







import time
from dataclasses import dataclass
from multiprocessing import Pool
from unittest import TestCase
from unittest.mock import patch

import multiprocess
import numpy as np
import pytest

from datasets.utils.py_utils import (
    NestedDataStructure,
    asdict,
    iflatmap_unordered,
    map_nested,
    temp_seed,
    temporary_assignment,
    zip_dict,
)

from .utils import require_tf, require_torch



def 	A_       (  _lowerCAmelCase  )		->				Union[str, Any]:  # picklable for multiprocessing
 return x.sum()



def 	A_       (  _lowerCAmelCase  )		->				Optional[Any]:  # picklable for multiprocessing
 return i + 1



@dataclass
class       A__     :
      _UpperCAmelCase			:int
      _UpperCAmelCase			:str



class       A__     ( __snake_case    ):





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Optional[int] 			=     {}
       UpperCamelCase			:      Optional[Any] 			=     []
       UpperCamelCase			:      List[Any] 			=     1
       UpperCamelCase			:      Tuple 			=     [1, 2]
       UpperCamelCase			:      Optional[Any] 			=     {"a": 1, "b": 2}
       UpperCamelCase			:      Optional[Any] 			=     {"a": [1, 2], "b": [3, 4]}
       UpperCamelCase			:      Any 			=     {"a": {"1": 1}, "b": 2}
       UpperCamelCase			:      List[str] 			=     {"a": 1, "b": 2, "c": 3, "d": 4}
       UpperCamelCase			:      Dict 			=     {}
       UpperCamelCase			:      Any 			=     []
       UpperCamelCase			:      Any 			=     2
       UpperCamelCase			:      Any 			=     [2, 3]
       UpperCamelCase			:      Optional[Any] 			=     {"a": 2, "b": 3}
       UpperCamelCase			:      List[Any] 			=     {"a": [2, 3], "b": [4, 5]}
       UpperCamelCase			:      Tuple 			=     {"a": {"1": 2}, "b": 3}
       UpperCamelCase			:      Dict 			=     {"a": 2, "b": 3, "c": 4, "d": 5}
       self.assertEqual(map_nested(A_ ,							A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_     ) ,							A_     )

       UpperCamelCase			:      List[str] 			=     2
       self.assertEqual(map_nested(A_ ,							A_ ,							num_proc=A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_ ,							num_proc=A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_ ,							num_proc=A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_ ,							num_proc=A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_ ,							num_proc=A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_ ,							num_proc=A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_ ,							num_proc=A_     ) ,							A_     )
       self.assertEqual(map_nested(A_ ,							A_ ,							num_proc=A_     ) ,							A_     )

       UpperCamelCase			:      List[str] 			=     {"a": np.eye(2     ), "b": np.zeros(3     ), "c": np.ones(2     )}
       UpperCamelCase			:      int 			=     {"a": 2, "b": 0, "c": 2}
       UpperCamelCase			:      Union[str, Any] 			=     {
           "a": np.eye(2     ).astype(A_     ),
           "b": np.zeros(3     ).astype(A_     ),
           "c": np.ones(2     ).astype(A_     ),
       }
       self.assertEqual(map_nested(A_ ,							A_ ,							map_numpy=A_     ) ,							A_     )
       self.assertEqual(
           {k: v.tolist() for k, v in map_nested(A_ ,							A_ ,							map_numpy=A_     ).items()} ,							{k: v.tolist() for k, v in expected_map_nested_sna_int.items()} ,							)
       self.assertEqual(map_nested(A_ ,							A_ ,							map_numpy=A_ ,							num_proc=A_     ) ,							A_     )
       self.assertEqual(
           {k: v.tolist() for k, v in map_nested(A_ ,							A_ ,							map_numpy=A_ ,							num_proc=A_     ).items()} ,							{k: v.tolist() for k, v in expected_map_nested_sna_int.items()} ,							)
       with self.assertRaises(A_     ):  # can't pickle a local lambda
        map_nested(lambda A_     : x + 1 ,							A_ ,							num_proc=A_     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       UpperCamelCase			:      Optional[Any] 			=     {"a": 1, "b": 2}
       UpperCamelCase			:      List[Any] 			=     {"a": 3, "b": 4}
       UpperCamelCase			:      Tuple 			=     {"a": 5, "b": 6}
       UpperCamelCase			:      Union[str, Any] 			=     sorted([("a", (1, 3, 5)), ("b", (2, 4, 6))]     )
       self.assertEqual(sorted(zip_dict(A_ ,							A_ ,							A_     )     ) ,							A_     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       class       A__     :
             _UpperCAmelCase			:str							=     'bar'


       UpperCamelCase			:      List[Any] 			=     Foo()
       self.assertEqual(foo.my_attr ,							"bar"     )
       with temporary_assignment(A_ ,							"my_attr" ,							"BAR"     ):
        self.assertEqual(foo.my_attr ,							"BAR"     )
       self.assertEqual(foo.my_attr ,							"bar"     )



@pytest.mark.parametrize(
    "iterable_length, num_proc, expected_num_proc"							,     [
        (1, None, 1),
        (1, 1, 1),
        (2, None, 1),
        (2, 1, 1),
        (2, 2, 1),
        (2, 3, 1),
        (3, 2, 1),
        (16, 16, 16),
        (16, 17, 16),
        (17, 16, 16),
    ]							,     )
def 	A_       (  _lowerCAmelCase							,     _lowerCAmelCase							,     _lowerCAmelCase  )		->				Optional[Any]:
 with patch("datasets.utils.py_utils._single_map_nested"  ) as mock_single_map_nested, patch(
     "datasets.parallel.parallel.Pool"  ) as mock_multiprocessing_pool:
  UpperCamelCase			:      Union[str, Any] 			=     {F"""{i}""": i for i in range(_lowerCAmelCase  )}
  UpperCamelCase			:      List[str] 			=     map_nested(lambda _lowerCAmelCase  : x + 10							,     _lowerCAmelCase							,     num_proc=_lowerCAmelCase							,     parallel_min_length=16  )
  if expected_num_proc == 1:
   assert mock_single_map_nested.called
   assert not mock_multiprocessing_pool.called
  else:
   assert not mock_single_map_nested.called
   assert mock_multiprocessing_pool.called
   assert mock_multiprocessing_pool.call_args[0][0] == expected_num_proc



class       A__     ( __snake_case    ):





      @require_tf
      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       import tensorflow as tf
       from tensorflow.keras import layers

       UpperCamelCase			:      int 			=     layers.Dense(2     )

       def gen_random_output():
        UpperCamelCase			:      Optional[Any] 			=     tf.random.uniform((1, 3)     )
        return model(A_     ).numpy()

       with temp_seed(42 ,							set_tensorflow=A_     ):
        UpperCamelCase			:      List[Any] 			=     gen_random_output()
       with temp_seed(42 ,							set_tensorflow=A_     ):
        UpperCamelCase			:      Dict 			=     gen_random_output()
       UpperCamelCase			:      Optional[int] 			=     gen_random_output()

       np.testing.assert_equal(A_ ,							A_     )
       self.assertGreater(np.abs(outa - outa     ).sum() ,							0     )





      @require_torch
      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       import torch

       def gen_random_output():
        UpperCamelCase			:      Optional[Any] 			=     torch.nn.Linear(3 ,							2     )
        UpperCamelCase			:      Dict 			=     torch.rand(1 ,							3     )
        return model(A_     ).detach().numpy()

       with temp_seed(42 ,							set_pytorch=A_     ):
        UpperCamelCase			:      Dict 			=     gen_random_output()
       with temp_seed(42 ,							set_pytorch=A_     ):
        UpperCamelCase			:      Optional[int] 			=     gen_random_output()
       UpperCamelCase			:      List[Any] 			=     gen_random_output()

       np.testing.assert_equal(A_ ,							A_     )
       self.assertGreater(np.abs(outa - outa     ).sum() ,							0     )





      def  __UpperCamelCase(				self     ):
       '''simple docstring'''




       def gen_random_output():
        return np.random.rand(1 ,							3     )

       with temp_seed(42     ):
        UpperCamelCase			:      Optional[Any] 			=     gen_random_output()
       with temp_seed(42     ):
        UpperCamelCase			:      Optional[Any] 			=     gen_random_output()
       UpperCamelCase			:      Optional[Any] 			=     gen_random_output()

       np.testing.assert_equal(A_ ,							A_     )
       self.assertGreater(np.abs(outa - outa     ).sum() ,							0     )



@pytest.mark.parametrize("input_data"							,     [{}]  )
def 	A_       (  _lowerCAmelCase  )		->				List[Any]:
 UpperCamelCase			:      Optional[Any] 			=     NestedDataStructure(_lowerCAmelCase  ).data
 assert output_data == input_data



@pytest.mark.parametrize(
    "data, expected_output"							,     [
        ({}, []),
        ([], []),
        ("foo", ["foo"]),
        (["foo", "bar"], ["foo", "bar"]),
        ([["foo", "bar"]], ["foo", "bar"]),
        ([[["foo"], ["bar"]]], ["foo", "bar"]),
        ([[["foo"], "bar"]], ["foo", "bar"]),
        ({"a": 1, "b": 2}, [1, 2]),
        ({"a": [1, 2], "b": [3, 4]}, [1, 2, 3, 4]),
        ({"a": [[1, 2]], "b": [[3, 4]]}, [1, 2, 3, 4]),
        ({"a": [[1, 2]], "b": [3, 4]}, [1, 2, 3, 4]),
        ({"a": [[[1], [2]]], "b": [[[3], [4]]]}, [1, 2, 3, 4]),
        ({"a": [[[1], [2]]], "b": [[3, 4]]}, [1, 2, 3, 4]),
        ({"a": [[[1], [2]]], "b": [3, 4]}, [1, 2, 3, 4]),
        ({"a": [[[1], [2]]], "b": [3, [4]]}, [1, 2, 3, 4]),
        ({"a": {"1": 1}, "b": 2}, [1, 2]),
        ({"a": {"1": [1]}, "b": 2}, [1, 2]),
        ({"a": {"1": [1]}, "b": [2]}, [1, 2]),
    ]							,     )
def 	A_       (  _lowerCAmelCase							,     _lowerCAmelCase  )		->				Tuple:
 UpperCamelCase			:      Dict 			=     NestedDataStructure(_lowerCAmelCase  ).flatten()
 assert output == expected_output



def 	A_       (  )		->				List[Any]:
 UpperCamelCase			:      str 			=     A(x=1							,     y="foobar"  )
 UpperCamelCase			:      Tuple 			=     {"x": 1, "y": "foobar"}
 assert asdict(_lowerCAmelCase  ) == expected_output

 UpperCamelCase			:      List[str] 			=     {"a": {"b": A(x=10							,     y="foo"  )}, "c": [A(x=20							,     y="bar"  )]}
 UpperCamelCase			:      Tuple 			=     {"a": {"b": {"x": 10, "y": "foo"}}, "c": [{"x": 20, "y": "bar"}]}
 assert asdict(_lowerCAmelCase  ) == expected_output

 with pytest.raises(_lowerCAmelCase  ):
  asdict([1, A(x=10							,     y="foo"  )]  )



def 	A_       (  _lowerCAmelCase  )		->				Tuple:
 return text.split()



def 	A_       (  _lowerCAmelCase  )		->				Dict:
 yield (time.time(), content)
 time.sleep(2  )
 yield (time.time(), content)



def 	A_       (  )		->				str:
 with Pool(2  ) as pool:
  UpperCamelCase			:      List[str] 			=     list(iflatmap_unordered(_lowerCAmelCase							,     _split_text							,     kwargs_iterable=[{"text": "hello there"}] * 10  )  )
  assert out.count("hello"  ) == 10
  assert out.count("there"  ) == 10
  assert len(_lowerCAmelCase  ) == 20

 # check multiprocess from pathos (uses dill for pickling)
 with multiprocess.Pool(2  ) as pool:
  UpperCamelCase			:      Dict 			=     list(iflatmap_unordered(_lowerCAmelCase							,     _split_text							,     kwargs_iterable=[{"text": "hello there"}] * 10  )  )
  assert out.count("hello"  ) == 10
  assert out.count("there"  ) == 10
  assert len(_lowerCAmelCase  ) == 20

 # check that we get items as fast as possible
 with Pool(2  ) as pool:
  UpperCamelCase			:      Any 			=     []
  for yield_time, content in iflatmap_unordered(
      _lowerCAmelCase							,     _aseconds_generator_of_aitems_with_timing							,     kwargs_iterable=[{"content": "a"}, {"content": "b"}]  ):
   assert yield_time < time.time() + 0.1, "we should each item directly after it was yielded"
   out.append(_lowerCAmelCase  )
  assert out.count("a"  ) == 2
  assert out.count("b"  ) == 2
  assert len(_lowerCAmelCase  ) == 4
