





'''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  lowerCamelCase__				(						TensorFormatter[Mapping, np.ndarray, Mapping]						):


	"""simple docstring"""





	def __init__(					self   ,     UpperCAmelCase__=None   ,     **UpperCAmelCase__			)       ->				int:
					super().__init__(features=UpperCAmelCase__			)
					_A :				Optional[Any]				=  np_array_kwargs




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




	def 				_lowerCamelCase				(					self   ,     UpperCAmelCase__			)       ->				int:
					if isinstance(UpperCAmelCase__   ,     (str, bytes, type(UpperCAmelCase__			))			):
									return value
					elif isinstance(UpperCAmelCase__   ,     (np.character, np.ndarray)			) and np.issubdtype(value.dtype   ,     np.character			):
									return value
					elif isinstance(UpperCAmelCase__   ,     np.number			):
									return value

					_A :				Any				=  {}

					if isinstance(UpperCAmelCase__   ,     np.ndarray			) and np.issubdtype(value.dtype   ,     np.integer			):
									_A :				Dict				=  {'''dtype''': np.intaa}
					elif isinstance(UpperCAmelCase__   ,     np.ndarray			) and np.issubdtype(value.dtype   ,     np.floating			):
									_A :				List[Any]				=  {'''dtype''': np.floataa}
					elif config.PIL_AVAILABLE and "PIL" in sys.modules:
									import PIL.Image

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

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




	def 				_lowerCamelCase				(					self   ,     UpperCAmelCase__			)       ->				List[str]:
					# support for torch, tf, jax etc.
					if config.TORCH_AVAILABLE and "torch" in sys.modules:
									import torch

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




	def 				_lowerCamelCase				(					self   ,     UpperCAmelCase__			)       ->				Optional[int]:
					return map_nested(self._recursive_tensorize   ,     UpperCAmelCase__   ,     map_list=UpperCAmelCase__			)




	def 				_lowerCamelCase				(					self   ,     UpperCAmelCase__			)       ->				Mapping:
					_A :				Any				=  self.numpy_arrow_extractor().extract_row(UpperCAmelCase__			)
					_A :				List[str]				=  self.python_features_decoder.decode_row(UpperCAmelCase__			)
					return self.recursive_tensorize(UpperCAmelCase__			)




	def 				_lowerCamelCase				(					self   ,     UpperCAmelCase__			)       ->				np.ndarray:
					_A :				str				=  self.numpy_arrow_extractor().extract_column(UpperCAmelCase__			)
					_A :				Dict				=  self.python_features_decoder.decode_column(UpperCAmelCase__   ,     pa_table.column_names[0]			)
					_A :				int				=  self.recursive_tensorize(UpperCAmelCase__			)
					_A :				int				=  self._consolidate(UpperCAmelCase__			)
					return column




	def 				_lowerCamelCase				(					self   ,     UpperCAmelCase__			)       ->				Mapping:
					_A :				Optional[Any]				=  self.numpy_arrow_extractor().extract_batch(UpperCAmelCase__			)
					_A :				str				=  self.python_features_decoder.decode_batch(UpperCAmelCase__			)
					_A :				int				=  self.recursive_tensorize(UpperCAmelCase__			)
					for column_name in batch:
									_A :				List[Any]				=  self._consolidate(batch[column_name]			)
					return batch







'''simple docstring'''






from typing import TYPE_CHECKING

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


__UpperCamelCase      :   List[str]								=     {'''configuration_gptj''': ['''GPTJ_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''GPTJConfig''', '''GPTJOnnxConfig''']}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__UpperCamelCase      :   List[Any]								=     [
	    '''GPTJ_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''GPTJForCausalLM''',
	    '''GPTJForQuestionAnswering''',
	    '''GPTJForSequenceClassification''',
	    '''GPTJModel''',
	    '''GPTJPreTrainedModel''',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__UpperCamelCase      :   Optional[int]								=     [
	    '''TFGPTJForCausalLM''',
	    '''TFGPTJForQuestionAnswering''',
	    '''TFGPTJForSequenceClassification''',
	    '''TFGPTJModel''',
	    '''TFGPTJPreTrainedModel''',
	]

try:
	if not is_flax_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__UpperCamelCase      :   Union[str, Any]								=     [
	    '''FlaxGPTJForCausalLM''',
	    '''FlaxGPTJModel''',
	    '''FlaxGPTJPreTrainedModel''',
	]


if TYPE_CHECKING:
	from .configuration_gptj import GPTJ_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTJConfig, GPTJOnnxConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_gptj import (
		    GPTJ_PRETRAINED_MODEL_ARCHIVE_LIST,
		    GPTJForCausalLM,
		    GPTJForQuestionAnswering,
		    GPTJForSequenceClassification,
		    GPTJModel,
		    GPTJPreTrainedModel,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_gptj import (
		    TFGPTJForCausalLM,
		    TFGPTJForQuestionAnswering,
		    TFGPTJForSequenceClassification,
		    TFGPTJModel,
		    TFGPTJPreTrainedModel,
		)

	try:
		if not is_flax_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_flax_gptj import FlaxGPTJForCausalLM, FlaxGPTJModel, FlaxGPTJPreTrainedModel

else:
	import sys

	__UpperCamelCase      :   List[str]								=     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)
