





'''simple docstring'''







import unittest
from unittest.util import safe_repr

from transformers import AutoTokenizer, RwkvConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    RWKV_PRETRAINED_MODEL_ARCHIVE_LIST,
					    RwkvForCausalLM,
					    RwkvModel,
					)
					from transformers.pytorch_utils import is_torch_greater_or_equal_than_2_0
else:
					snake_case_  :							Union[str, Any]            =	False


class        __a   :

							def __init__(				self				:  Optional[Any]							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  Dict=14							,  __magic_name__				:  Dict=7							,  __magic_name__				:  Union[str, Any]=True							,  __magic_name__				:  Tuple=False							,  __magic_name__				:  Optional[int]=True							,  __magic_name__				:  List[Any]=True							,  __magic_name__				:  int=True							,  __magic_name__				:  str=99							,  __magic_name__				:  Optional[int]=32							,  __magic_name__				:  Optional[int]=5							,  __magic_name__				:  Optional[Any]=37							,  __magic_name__				:  Union[str, Any]="gelu"							,  __magic_name__				:  Dict=0.1							,  __magic_name__				:  Dict=0.1							,  __magic_name__				:  Optional[int]=5_12							,  __magic_name__				:  Optional[Any]=16							,  __magic_name__				:  Tuple=2							,  __magic_name__				:  List[Any]=3							,  __magic_name__				:  Dict=4							,  __magic_name__				:  Dict=None							,  )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   str      =	parent
													UpperCAmelCase_      :   List[Any]      =	batch_size
													UpperCAmelCase_      :   List[Any]      =	seq_length
													UpperCAmelCase_      :   Tuple      =	is_training
													UpperCAmelCase_      :   Optional[int]      =	use_token_type_ids
													UpperCAmelCase_      :   Union[str, Any]      =	use_input_mask
													UpperCAmelCase_      :   List[str]      =	use_labels
													UpperCAmelCase_      :   str      =	use_mc_token_ids
													UpperCAmelCase_      :   Dict      =	vocab_size
													UpperCAmelCase_      :   Optional[int]      =	hidden_size
													UpperCAmelCase_      :   int      =	num_hidden_layers
													UpperCAmelCase_      :   Optional[Any]      =	intermediate_size
													UpperCAmelCase_      :   List[Any]      =	hidden_act
													UpperCAmelCase_      :   List[Any]      =	hidden_dropout_prob
													UpperCAmelCase_      :   Union[str, Any]      =	attention_probs_dropout_prob
													UpperCAmelCase_      :   str      =	max_position_embeddings
													UpperCAmelCase_      :   List[Any]      =	type_vocab_size
													UpperCAmelCase_      :   Optional[Any]      =	type_sequence_label_size
													UpperCAmelCase_      :   Optional[int]      =	num_labels
													UpperCAmelCase_      :   Optional[Any]      =	num_choices
													UpperCAmelCase_      :   Tuple      =	scope
													UpperCAmelCase_      :   List[str]      =	vocab_size - 1
													UpperCAmelCase_      :   List[Any]      =	vocab_size - 1
													UpperCAmelCase_      :   Any      =	vocab_size - 1

							def      UpperCAmelCase__						(				self				:  int )       ->							str:







													"""simple docstring"""
													return RwkvConfig.from_pretrained('''sgugger/rwkv-4-pile-7b''' )

							def      UpperCAmelCase__						(				self				:  List[Any]							,  __magic_name__				:  Optional[Any]=False							,  __magic_name__				:  str=False							,  __magic_name__				:  Dict=False )       ->							Tuple:







													"""simple docstring"""
													UpperCAmelCase_      :   Union[str, Any]      =	ids_tensor([self.batch_size, self.seq_length]							,  self.vocab_size )

													UpperCAmelCase_      :   List[Any]      =	None
													if self.use_input_mask:
																			UpperCAmelCase_      :   Any      =	random_attention_mask([self.batch_size, self.seq_length] )

													UpperCAmelCase_      :   List[Any]      =	None
													if self.use_token_type_ids:
																			UpperCAmelCase_      :   int      =	ids_tensor([self.batch_size, self.seq_length]							,  self.type_vocab_size )

													UpperCAmelCase_      :   Optional[Any]      =	None
													if self.use_mc_token_ids:
																			UpperCAmelCase_      :   List[Any]      =	ids_tensor([self.batch_size, self.num_choices]							,  self.seq_length )

													UpperCAmelCase_      :   List[str]      =	None
													UpperCAmelCase_      :   List[Any]      =	None
													UpperCAmelCase_      :   str      =	None
													if self.use_labels:
																			UpperCAmelCase_      :   Any      =	ids_tensor([self.batch_size]							,  self.type_sequence_label_size )
																			UpperCAmelCase_      :   Any      =	ids_tensor([self.batch_size, self.seq_length]							,  self.num_labels )
																			UpperCAmelCase_      :   Tuple      =	ids_tensor([self.batch_size]							,  self.num_choices )

													UpperCAmelCase_      :   Union[str, Any]      =	self.get_config(
													    gradient_checkpointing=__magic_name__							,  scale_attn_by_inverse_layer_idx=__magic_name__							,  reorder_and_upcast_attn=__magic_name__							,  )

													return (
													    config,
													    input_ids,
													    input_mask,
													    None,
													    token_type_ids,
													    mc_token_ids,
													    sequence_labels,
													    token_labels,
													    choice_labels,
													)

							def      UpperCAmelCase__						(				self				:  Optional[int]							,  __magic_name__				:  Union[str, Any]=False							,  __magic_name__				:  Optional[Any]=False							,  __magic_name__				:  Union[str, Any]=False )       ->							Union[str, Any]:







													"""simple docstring"""
													return RwkvConfig(
													    vocab_size=self.vocab_size							,  hidden_size=self.hidden_size							,  num_hidden_layers=self.num_hidden_layers							,  intermediate_size=self.intermediate_size							,  activation_function=self.hidden_act							,  resid_pdrop=self.hidden_dropout_prob							,  attn_pdrop=self.attention_probs_dropout_prob							,  n_positions=self.max_position_embeddings							,  type_vocab_size=self.type_vocab_size							,  use_cache=__magic_name__							,  bos_token_id=self.bos_token_id							,  eos_token_id=self.eos_token_id							,  pad_token_id=self.pad_token_id							,  gradient_checkpointing=__magic_name__							,  scale_attn_by_inverse_layer_idx=__magic_name__							,  reorder_and_upcast_attn=__magic_name__							,  )

							def      UpperCAmelCase__						(				self				:  str )       ->							Dict:







													"""simple docstring"""
													UpperCAmelCase_      :   List[Any]      =	self.get_config()
													UpperCAmelCase_      :   int      =	3_00
													return config

							def      UpperCAmelCase__						(				self				:  Optional[int] )       ->							Union[str, Any]:







													"""simple docstring"""
													(
													    (
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							
													)      :   List[str]      =	self.prepare_config_and_inputs()

													UpperCAmelCase_      :   str      =	floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
													UpperCAmelCase_      :   Optional[Any]      =	ids_tensor([self.batch_size, self.seq_length]							,  vocab_size=2 )

													return (
													    config,
													    input_ids,
													    input_mask,
													    head_mask,
													    token_type_ids,
													    sequence_labels,
													    token_labels,
													    choice_labels,
													    encoder_hidden_states,
													    encoder_attention_mask,
													)

							def      UpperCAmelCase__						(				self				:  int							,  __magic_name__				:  Optional[Any]							,  __magic_name__				:  List[Any]							,  __magic_name__				:  str							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  Optional[Any]							,  *__magic_name__				:  Union[str, Any] )       ->							str:







													"""simple docstring"""
													UpperCAmelCase_      :   Tuple      =	True
													UpperCAmelCase_      :   Any      =	RwkvModel(config=__magic_name__ )
													model.to(__magic_name__ )
													model.eval()

													UpperCAmelCase_      :   Optional[int]      =	model(__magic_name__ )

													self.parent.assertEqual(result.last_hidden_state.shape							,  (self.batch_size, self.seq_length, self.hidden_size) )
													self.parent.assertEqual(len(result.hidden_states )							,  config.num_hidden_layers + 1 )

							def      UpperCAmelCase__						(				self				:  Union[str, Any]							,  __magic_name__				:  List[str]							,  __magic_name__				:  List[str]							,  __magic_name__				:  List[str]							,  __magic_name__				:  int							,  __magic_name__				:  Tuple							,  *__magic_name__				:  Optional[int] )       ->							str:







													"""simple docstring"""
													UpperCAmelCase_      :   List[Any]      =	RwkvForCausalLM(__magic_name__ )
													model.to(__magic_name__ )
													model.eval()

													UpperCAmelCase_      :   List[str]      =	model(__magic_name__							,  labels=__magic_name__ )
													self.parent.assertEqual(result.loss.shape							,  () )
													self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.vocab_size) )

							def      UpperCAmelCase__						(				self				:  Tuple							,  __magic_name__				:  int							,  __magic_name__				:  str							,  __magic_name__				:  str							,  __magic_name__				:  Any							,  __magic_name__				:  Any							,  *__magic_name__				:  Union[str, Any] )       ->							Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	RwkvModel(config=__magic_name__ )
													model.to(__magic_name__ )
													model.eval()

													UpperCAmelCase_      :   Optional[int]      =	model(__magic_name__ )
													UpperCAmelCase_      :   Dict      =	outputs.last_hidden_state

													UpperCAmelCase_      :   Any      =	model(input_ids[:, :2] )
													UpperCAmelCase_      :   int      =	outputs.last_hidden_state

													# Using the state computed on the first inputs, we will get the same output
													UpperCAmelCase_      :   Optional[Any]      =	model(input_ids[:, 2:]							,  state=outputs.state )
													UpperCAmelCase_      :   int      =	outputs.last_hidden_state

													self.parent.assertTrue(torch.allclose(torch.cat([output_one, output_two]							,  dim=1 )							,  __magic_name__							,  atol=1E-5 ) )

							def      UpperCAmelCase__						(				self				:  int							,  __magic_name__				:  Optional[Any]							,  __magic_name__				:  List[str]							,  __magic_name__				:  Any							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  List[Any]							,  *__magic_name__				:  List[Any]							,  __magic_name__				:  List[str]=False )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	RwkvForCausalLM(__magic_name__ )
													model.to(__magic_name__ )
													if gradient_checkpointing:
																			model.gradient_checkpointing_enable()

													UpperCAmelCase_      :   Any      =	model(__magic_name__							,  labels=__magic_name__ )
													self.parent.assertEqual(result.loss.shape							,  () )
													self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.vocab_size) )
													result.loss.backward()



							def      UpperCAmelCase__						(				self				:  str )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   List[str]      =	self.prepare_config_and_inputs()

													(
													    (
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							
													)      :   str      =	config_and_inputs

													UpperCAmelCase_      :   Any      =	{'''input_ids''': input_ids}

													return config, inputs_dict





@unittest.skipIf(
    not is_torch_greater_or_equal_than_2_0							,		reason="See https://github.com/huggingface/transformers/pull/24204"  )
@require_torch
class        __a   (lowerCamelCase							,		lowerCamelCase							,		lowerCamelCase							,		unittest.TestCase  ):
							__a       : List[Any]          =							(RwkvModel, RwkvForCausalLM) if is_torch_available() else ()
							__a       : List[str]          =							(
							    {"feature-extraction": RwkvModel, "text-generation": RwkvForCausalLM} if is_torch_available() else {}
							)
							# all_generative_model_classes = (RwkvForCausalLM,) if is_torch_available() else ()
							__a       : List[Any]          =							False
							__a       : Union[str, Any]          =							False
							__a       : List[str]          =							False
							__a       : List[Any]          =							False
							__a       : List[Any]          =							False  # Rwkv does not support head masking

							def      UpperCAmelCase__						(				self				:  Tuple )       ->							List[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Dict      =	RwkvModelTester(self )
													UpperCAmelCase_      :   Union[str, Any]      =	ConfigTester(
													    self							,  config_class=__magic_name__							,  n_embd=37							,  common_properties=['''hidden_size''', '''num_hidden_layers'''] )

							def      UpperCAmelCase__						(				self				:  Optional[int]							,  __magic_name__				:  int							,  __magic_name__				:  Optional[int]							,  __magic_name__				:  Dict=None )       ->							List[str]:







													"""simple docstring"""
													if isinstance(__magic_name__							,  torch.Tensor ):
																			UpperCAmelCase_    ,							UpperCAmelCase_      :   int      =	member.max().item(), member.min().item()
													elif isinstance(__magic_name__							,  __magic_name__ ) or isinstance(__magic_name__							,  __magic_name__ ):
																			UpperCAmelCase_    ,							UpperCAmelCase_      :   int      =	max(__magic_name__ ), min(__magic_name__ )

													if not isinstance(__magic_name__							,  __magic_name__ ):
																			raise TypeError('''container should be a list or tuple''' )
													elif len(__magic_name__ ) != 2:
																			raise ValueError('''container should have 2 elements''' )

													UpperCAmelCase_    ,							UpperCAmelCase_      :   Tuple      =	container

													UpperCAmelCase_      :   int      =	(min_value >= expected_min) and (max_value <= expected_max)

													if not is_inside_interval:
																			UpperCAmelCase_      :   Optional[Any]      =	'''%s not found in %s''' % (safe_repr(__magic_name__ ), safe_repr(__magic_name__ ))
																			self.fail(self._formatMessage(__magic_name__							,  __magic_name__ ) )

							def      UpperCAmelCase__						(				self				:  Any )       ->							List[Any]:







													"""simple docstring"""
													self.config_tester.run_common_tests()

							def      UpperCAmelCase__						(				self				:  List[str] )       ->							List[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[int]      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_rwkv_model(*__magic_name__ )

							def      UpperCAmelCase__						(				self				:  Tuple )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[int]      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_causl_lm(*__magic_name__ )

							def      UpperCAmelCase__						(				self				:  str )       ->							List[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Union[str, Any]      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_state_equivalency(*__magic_name__ )

							def      UpperCAmelCase__						(				self				:  List[str] )       ->							Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_    ,							UpperCAmelCase_      :   List[str]      =	self.model_tester.prepare_config_and_inputs_for_common()

													for model_class in self.all_model_classes:
																			UpperCAmelCase_      :   int      =	model_class(config=__magic_name__ )
																			for name, param in model.named_parameters():
																									if "time_decay" in name:
																															if param.requires_grad:
																																					self.assertTrue(param.data.max().item() == 3.0 )
																																					self.assertTrue(param.data.min().item() == -5.0 )
																									elif "time_first" in name:
																															if param.requires_grad:
																																					# check if it's a ones like
																																					self.assertTrue(torch.allclose(param.data							,  torch.ones_like(param.data )							,  atol=1E-5							,  rtol=1E-5 ) )
																									elif any(x in name for x in ['''time_mix_key''', '''time_mix_receptance'''] ):
																															if param.requires_grad:
																																					self.assertInterval(
																																					    param.data							,  [0.0, 1.0]							,  msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""							,  )
																									elif "time_mix_value" in name:
																															if param.requires_grad:
																																					self.assertInterval(
																																					    param.data							,  [0.0, 1.3]							,  msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""							,  )

							def      UpperCAmelCase__						(				self				:  Dict )       ->							Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_    ,							UpperCAmelCase_      :   Union[str, Any]      =	self.model_tester.prepare_config_and_inputs_for_common()
													UpperCAmelCase_      :   str      =	True

													UpperCAmelCase_      :   Optional[int]      =	getattr(self.model_tester							,  '''seq_length'''							,  __magic_name__ )

													for model_class in self.all_model_classes:
																			UpperCAmelCase_      :   Union[str, Any]      =	True
																			UpperCAmelCase_      :   Dict      =	False
																			UpperCAmelCase_      :   List[str]      =	True
																			UpperCAmelCase_      :   Tuple      =	model_class(__magic_name__ )
																			model.to(__magic_name__ )
																			model.eval()

																			UpperCAmelCase_      :   Tuple      =	self._prepare_for_class(__magic_name__							,  __magic_name__ )
																			UpperCAmelCase_      :   Optional[Any]      =	inputs['''input_ids'''].shape[0]
																			with torch.no_grad():
																									UpperCAmelCase_      :   Optional[Any]      =	model(**__magic_name__ )
																			UpperCAmelCase_      :   List[Any]      =	outputs.attentions
																			self.assertEqual(len(__magic_name__ )							,  self.model_tester.num_hidden_layers )

																			# check that output_attentions also work using config
																			del inputs_dict["output_attentions"]
																			UpperCAmelCase_      :   Union[str, Any]      =	True
																			UpperCAmelCase_      :   Tuple      =	model_class(__magic_name__ )
																			model.to(__magic_name__ )
																			model.eval()

																			UpperCAmelCase_      :   List[Any]      =	self._prepare_for_class(__magic_name__							,  __magic_name__ )
																			UpperCAmelCase_      :   Dict      =	inputs['''input_ids'''].shape[0]
																			with torch.no_grad():
																									UpperCAmelCase_      :   Tuple      =	model(**__magic_name__ )
																			UpperCAmelCase_      :   Any      =	outputs.attentions
																			self.assertEqual(len(__magic_name__ )							,  self.model_tester.num_hidden_layers )

																			self.assertListEqual(
																			    list(attentions[0].shape[-3:] )							,  [batch_size, seq_len, config.hidden_size]							,  )
																			UpperCAmelCase_      :   Dict      =	len(__magic_name__ )

																			# Check attention is always last and order is fine
																			UpperCAmelCase_      :   Union[str, Any]      =	True
																			UpperCAmelCase_      :   List[str]      =	True
																			UpperCAmelCase_      :   Any      =	model_class(__magic_name__ )
																			model.to(__magic_name__ )
																			model.eval()

																			UpperCAmelCase_      :   Optional[Any]      =	self._prepare_for_class(__magic_name__							,  __magic_name__ )
																			UpperCAmelCase_      :   Tuple      =	inputs['''input_ids'''].shape[0]
																			with torch.no_grad():
																									UpperCAmelCase_      :   str      =	model(**__magic_name__ )

																			UpperCAmelCase_      :   int      =	1
																			self.assertEqual(out_len + added_hidden_states							,  len(__magic_name__ ) )

																			UpperCAmelCase_      :   Optional[int]      =	outputs.attentions

																			self.assertEqual(len(__magic_name__ )							,  self.model_tester.num_hidden_layers )
																			self.assertListEqual(
																			    list(self_attentions[0].shape[-3:] )							,  [batch_size, seq_len, config.hidden_size]							,  )



							@slow
							def      UpperCAmelCase__						(				self				:  Tuple )       ->							str:







													"""simple docstring"""
													for model_name in RWKV_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_      :   Optional[Any]      =	RwkvModel.from_pretrained(__magic_name__ )
																			self.assertIsNotNone(__magic_name__ )





@unittest.skipIf(
    not is_torch_greater_or_equal_than_2_0							,		reason="See https://github.com/huggingface/transformers/pull/24204"  )
@slow
class        __a   (unittest.TestCase  ):

							def      UpperCAmelCase__						(				self				:  Any )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	'''RWKV/rwkv-4-169m-pile'''
													UpperCAmelCase_      :   int      =	AutoTokenizer.from_pretrained(self.model_id )

							def      UpperCAmelCase__						(				self				:  Dict )       ->							str:







													"""simple docstring"""
													UpperCAmelCase_      :   int      =	'''Hello my name is Jasmine and I am a newbie to the'''
													UpperCAmelCase_      :   Optional[Any]      =	RwkvForCausalLM.from_pretrained(self.model_id ).to(__magic_name__ )

													UpperCAmelCase_      :   List[Any]      =	self.tokenizer('''Hello my name is'''							,  return_tensors='''pt''' ).input_ids.to(__magic_name__ )
													UpperCAmelCase_      :   Optional[int]      =	model.generate(__magic_name__							,  max_new_tokens=10 )
													UpperCAmelCase_      :   Dict      =	self.tokenizer.decode(output[0].tolist() )

													self.assertEqual(__magic_name__							,  __magic_name__ )



							def      UpperCAmelCase__						(				self				:  List[str] )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	'''Hello my name is Jasmine and I am a newbie to the'''

													UpperCAmelCase_      :   List[str]      =	self.tokenizer('''Hello my name is'''							,  return_tensors='''pt''' ).input_ids.to(__magic_name__ )
													UpperCAmelCase_      :   int      =	RwkvForCausalLM.from_pretrained(self.model_id							,  torch_dtype=torch.bfloataa ).to(__magic_name__ )

													UpperCAmelCase_      :   List[str]      =	model.generate(__magic_name__							,  max_new_tokens=10 )
													UpperCAmelCase_      :   List[str]      =	self.tokenizer.decode(output[0].tolist() )

													self.assertEqual(__magic_name__							,  __magic_name__ )













'''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     :						Tuple					,					lowercase__     :						Dict=None					,					**lowercase__     :						List[Any]       )	->							str:
           super().__init__(features=lowercase__       )
           __A		 =   np_array_kwargs






     def      _UpperCamelCase (self     :						int					,					lowercase__     :						Tuple       )	->							List[Any]:
           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
                       __A		 =   np.empty(len(lowercase__       )					,					dtype=lowercase__       )
                       __A		 =   column
                       return out
           return column






     def      _UpperCamelCase (self     :						Optional[Any]					,					lowercase__     :						Optional[int]       )	->							Tuple:
           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

           __A		 =   {}

           if isinstance(lowercase__					,					np.ndarray       ) and np.issubdtype(value.dtype					,					np.integer       ):
                 __A		 =   {"dtype": np.intaa}
           elif isinstance(lowercase__					,					np.ndarray       ) and np.issubdtype(value.dtype					,					np.floating       ):
                 __A		 =   {"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      _UpperCamelCase (self     :						List[Any]					,					lowercase__     :						str       )	->							Optional[Any]:
           # 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)       ):
                 __A		 =   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      _UpperCamelCase (self     :						Optional[Any]					,					lowercase__     :						dict       )	->							Dict:
           return map_nested(self._recursive_tensorize					,					lowercase__					,					map_list=lowercase__       )






     def      _UpperCamelCase (self     :						Optional[int]					,					lowercase__     :						pa.Table       )	->							Mapping:
           __A		 =   self.numpy_arrow_extractor().extract_row(lowercase__       )
           __A		 =   self.python_features_decoder.decode_row(lowercase__       )
           return self.recursive_tensorize(lowercase__       )






     def      _UpperCamelCase (self     :						List[Any]					,					lowercase__     :						pa.Table       )	->							np.ndarray:
           __A		 =   self.numpy_arrow_extractor().extract_column(lowercase__       )
           __A		 =   self.python_features_decoder.decode_column(lowercase__					,					pa_table.column_names[0]       )
           __A		 =   self.recursive_tensorize(lowercase__       )
           __A		 =   self._consolidate(lowercase__       )
           return column






     def      _UpperCamelCase (self     :						Optional[Any]					,					lowercase__     :						pa.Table       )	->							Mapping:
           __A		 =   self.numpy_arrow_extractor().extract_batch(lowercase__       )
           __A		 =   self.python_features_decoder.decode_batch(lowercase__       )
           __A		 =   self.recursive_tensorize(lowercase__       )
           for column_name in batch:
                 __A		 =   self._consolidate(batch[column_name]       )
           return batch


