


'''simple docstring'''

import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


class    a__					(			TensorFormatter[Mapping, np.ndarray, Mapping]   ):







				"""simple docstring"""



				def __init__(self							,      __lowercase=None							,      **__lowercase		):
										super().__init__(features=__lowercase		)
										__lowerCAmelCase											=					np_array_kwargs




				def        _snake_case	(self							,      __lowercase		):
										if isinstance(__lowercase							,      __lowercase		):
																if column and all(
																    isinstance(__lowercase							,      np.ndarray		) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column		):
																						return np.stack(__lowercase		)
																else:
																						# don't use np.array(column, dtype=object)
																						# since it fails in certain cases
																						# see https://stackoverflow.com/q/51005699
																						__lowerCAmelCase											=					np.empty(len(__lowercase		)							,      dtype=__lowercase		)
																						__lowerCAmelCase											=					column
																						return out
										return column




				def        _snake_case	(self							,      __lowercase		):
										if isinstance(__lowercase							,      (str, bytes, type(__lowercase		))		):
																return value
										elif isinstance(__lowercase							,      (np.character, np.ndarray)		) and np.issubdtype(value.dtype							,      np.character		):
																return value
										elif isinstance(__lowercase							,      np.number		):
																return value

										__lowerCAmelCase											=					{}

										if isinstance(__lowercase							,      np.ndarray		) and np.issubdtype(value.dtype							,      np.integer		):
																__lowerCAmelCase											=					{'''dtype''': np.intaa}
										elif isinstance(__lowercase							,      np.ndarray		) and np.issubdtype(value.dtype							,      np.floating		):
																__lowerCAmelCase											=					{'''dtype''': np.floataa}
										elif config.PIL_AVAILABLE and "PIL" in sys.modules:
																import PIL.Image

																if isinstance(__lowercase							,      PIL.Image.Image		):
																						return np.asarray(__lowercase							,      **self.np_array_kwargs		)

										return np.asarray(__lowercase							,      **{**default_dtype, **self.np_array_kwargs}		)




				def        _snake_case	(self							,      __lowercase		):
										# support for torch, tf, jax etc.
										if config.TORCH_AVAILABLE and "torch" in sys.modules:
																import torch

																if isinstance(__lowercase							,      torch.Tensor		):
																						return self._tensorize(data_struct.detach().cpu().numpy()[()]		)
										if hasattr(__lowercase							,      '''__array__'''		) and not isinstance(__lowercase							,      (np.ndarray, np.character, np.number)		):
																__lowerCAmelCase											=					data_struct.__array__()
										# support for nested types like struct of list of struct
										if isinstance(__lowercase							,      np.ndarray		):
																if data_struct.dtype == object:
																						return self._consolidate([self.recursive_tensorize(__lowercase		) for substruct in data_struct]		)
										if isinstance(__lowercase							,      (list, tuple)		):
																return self._consolidate([self.recursive_tensorize(__lowercase		) for substruct in data_struct]		)
										return self._tensorize(__lowercase		)




				def        _snake_case	(self							,      __lowercase		):
										return map_nested(self._recursive_tensorize							,      __lowercase							,      map_list=__lowercase		)




				def        _snake_case	(self							,      __lowercase		):
										__lowerCAmelCase											=					self.numpy_arrow_extractor().extract_row(__lowercase		)
										__lowerCAmelCase											=					self.python_features_decoder.decode_row(__lowercase		)
										return self.recursive_tensorize(__lowercase		)




				def        _snake_case	(self							,      __lowercase		):
										__lowerCAmelCase											=					self.numpy_arrow_extractor().extract_column(__lowercase		)
										__lowerCAmelCase											=					self.python_features_decoder.decode_column(__lowercase							,      pa_table.column_names[0]		)
										__lowerCAmelCase											=					self.recursive_tensorize(__lowercase		)
										__lowerCAmelCase											=					self._consolidate(__lowercase		)
										return column




				def        _snake_case	(self							,      __lowercase		):
										__lowerCAmelCase											=					self.numpy_arrow_extractor().extract_batch(__lowercase		)
										__lowerCAmelCase											=					self.python_features_decoder.decode_batch(__lowercase		)
										__lowerCAmelCase											=					self.recursive_tensorize(__lowercase		)
										for column_name in batch:
																__lowerCAmelCase											=					self._consolidate(batch[column_name]		)
										return batch





'''simple docstring'''

from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available


@dataclass
class    a__					(			__A   ):







				"""simple docstring"""



				__UpperCamelCase     :		Tuple						=						{
				    'sld_warmup_steps': 15,
				    'sld_guidance_scale': 20,
				    'sld_threshold': 0.0,
				    'sld_momentum_scale': 0.0,
				    'sld_mom_beta': 0.0,
				}
				__UpperCamelCase     :		Optional[Any]						=						{
				    'sld_warmup_steps': 10,
				    'sld_guidance_scale': 1_000,
				    'sld_threshold': 0.01,
				    'sld_momentum_scale': 0.3,
				    'sld_mom_beta': 0.4,
				}
				__UpperCamelCase     :		Tuple						=						{
				    'sld_warmup_steps': 7,
				    'sld_guidance_scale': 2_000,
				    'sld_threshold': 0.025,
				    'sld_momentum_scale': 0.5,
				    'sld_mom_beta': 0.7,
				}
				__UpperCamelCase     :		str						=						{
				    'sld_warmup_steps': 0,
				    'sld_guidance_scale': 5_000,
				    'sld_threshold': 1.0,
				    'sld_momentum_scale': 0.5,
				    'sld_mom_beta': 0.7,
				}


@dataclass
class    a__					(			__A   ):







				"""simple docstring"""



				__UpperCamelCase     :		Union[List[PIL.Image.Image], np.ndarray]
				__UpperCamelCase     :		Optional[List[bool]]
				__UpperCamelCase     :		Optional[Union[List[PIL.Image.Image], np.ndarray]]
				__UpperCamelCase     :		Optional[str]


if is_transformers_available() and is_torch_available():
	from .pipeline_stable_diffusion_safe import StableDiffusionPipelineSafe
	from .safety_checker import SafeStableDiffusionSafetyChecker

