


'''simple docstring'''



import textwrap

import pyarrow as pa
import pytest

from datasets import Features, Value
from datasets.packaged_modules.json.json import Json




@pytest.fixture
def 	_a	(						_lowercase					:	Any  ):





     '''simple docstring'''






     __UpperCAmelCase	: Optional[Any]  							=			tmp_path / '''file.jsonl'''
     __UpperCAmelCase	: Dict  							=			textwrap.dedent(
         '''\
        {"col_1": -1}
        {"col_1": 1, "col_2": 2}
        {"col_1": 10, "col_2": 20}
        '''  )
     with open(_lowercase			,					'''w'''  ) as f:
          f.write(_lowercase  )
     return str(_lowercase  )




@pytest.fixture
def 	_a	(						_lowercase					:	int  ):





     '''simple docstring'''






     __UpperCAmelCase	: Optional[Any]  							=			tmp_path / '''file_utf16_encoded.jsonl'''
     __UpperCAmelCase	: int  							=			textwrap.dedent(
         '''\
        {"col_1": -1}
        {"col_1": 1, "col_2": 2}
        {"col_1": 10, "col_2": 20}
        '''  )
     with open(_lowercase			,					'''w'''			,					encoding='''utf-16'''  ) as f:
          f.write(_lowercase  )
     return str(_lowercase  )




@pytest.fixture
def 	_a	(						_lowercase					:	Optional[int]  ):





     '''simple docstring'''






     __UpperCAmelCase	: str  							=			tmp_path / '''file_with_list_of_dicts.json'''
     __UpperCAmelCase	: Dict  							=			textwrap.dedent(
         '''\
        [
            {"col_1": -1},
            {"col_1": 1, "col_2": 2},
            {"col_1": 10, "col_2": 20}
        ]
        '''  )
     with open(_lowercase			,					'''w'''  ) as f:
          f.write(_lowercase  )
     return str(_lowercase  )




@pytest.fixture
def 	_a	(						_lowercase					:	Tuple  ):





     '''simple docstring'''






     __UpperCAmelCase	: List[str]  							=			tmp_path / '''file_with_list_of_dicts_field.json'''
     __UpperCAmelCase	: List[Any]  							=			textwrap.dedent(
         '''\
        {
            "field1": 1,
            "field2": "aabb",
            "field3": [
                {"col_1": -1},
                {"col_1": 1, "col_2": 2},
                {"col_1": 10, "col_2": 20}
            ]
        }
        '''  )
     with open(_lowercase			,					'''w'''  ) as f:
          f.write(_lowercase  )
     return str(_lowercase  )




@pytest.mark.parametrize(
    '''file_fixture, config_kwargs'''			,					[
        ('''jsonl_file''', {}),
        ('''jsonl_file_utf16_encoded''', {'''encoding''': '''utf-16'''}),
        ('''json_file_with_list_of_dicts''', {}),
        ('''json_file_with_list_of_dicts_field''', {'''field''': '''field3'''}),
    ]			,					)
def 	_a	(						_lowercase					:	int			,					_lowercase					:	int			,					_lowercase					:	Dict  ):





     '''simple docstring'''






     __UpperCAmelCase	: Tuple  							=			Json(**_lowercase  )
     __UpperCAmelCase	: Any  							=			json._generate_tables([[request.getfixturevalue(_lowercase  )]]  )
     __UpperCAmelCase	: str  							=			pa.concat_tables([table for _, table in generator]  )
     assert pa_table.to_pydict() == {"col_1": [-1, 1, 10], "col_2": [None, 2, 20]}




@pytest.mark.parametrize(
    '''file_fixture, config_kwargs'''			,					[
        (
            '''jsonl_file''',
            {'''features''': Features({'''col_1''': Value('''int64'''  ), '''col_2''': Value('''int64'''  ), '''missing_col''': Value('''string'''  )}  )},
        ),
        (
            '''json_file_with_list_of_dicts''',
            {'''features''': Features({'''col_1''': Value('''int64'''  ), '''col_2''': Value('''int64'''  ), '''missing_col''': Value('''string'''  )}  )},
        ),
        (
            '''json_file_with_list_of_dicts_field''',
            {
                '''field''': '''field3''',
                '''features''': Features(
                    {'''col_1''': Value('''int64'''  ), '''col_2''': Value('''int64'''  ), '''missing_col''': Value('''string'''  )}  ),
            },
        ),
    ]			,					)
def 	_a	(						_lowercase					:	Dict			,					_lowercase					:	Tuple			,					_lowercase					:	Any  ):





     '''simple docstring'''






     __UpperCAmelCase	: Any  							=			Json(**_lowercase  )
     __UpperCAmelCase	: str  							=			json._generate_tables([[request.getfixturevalue(_lowercase  )]]  )
     __UpperCAmelCase	: Optional[Any]  							=			pa.concat_tables([table for _, table in generator]  )
     assert pa_table.to_pydict() == {"col_1": [-1, 1, 10], "col_2": [None, 2, 20], "missing_col": [None, None, None]}





import unittest

import numpy as np

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
				import tensorflow as tf

				from transformers.activations_tf import get_tf_activation





@require_tf
class 		A__				(   unittest.TestCase ):






	def  lowercase      (	self						)      ->   Dict:




						"""simple docstring"""






						__magic_name__					:							int		   =							tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 1_0_0.0]						)
						__magic_name__					:							List[str]		   =							get_tf_activation('''gelu'''						)
						__magic_name__					:							str		   =							get_tf_activation('''gelu_10'''						)

						__magic_name__					:							List[str]		   =							gelu(lowerCamelCase						)
						__magic_name__					:							Optional[Any]		   =							geluaa(lowerCamelCase						)

						__magic_name__					:							Optional[int]		   =							tf.where(y_gelu_aa < 1_0.0				,     1.0				,     0.0						)

						self.assertEqual(tf.math.reduce_max(lowerCamelCase						).numpy().item()				,     1_0.0						)
						self.assertTrue(np.allclose(y_gelu * clipped_mask				,     y_gelu_aa * clipped_mask						)						)






	def  lowercase      (	self						)      ->   Dict:




						"""simple docstring"""






						get_tf_activation('''gelu'''						)
						get_tf_activation('''gelu_10'''						)
						get_tf_activation('''gelu_fast'''						)
						get_tf_activation('''gelu_new'''						)
						get_tf_activation('''glu'''						)
						get_tf_activation('''mish'''						)
						get_tf_activation('''quick_gelu'''						)
						get_tf_activation('''relu'''						)
						get_tf_activation('''sigmoid'''						)
						get_tf_activation('''silu'''						)
						get_tf_activation('''swish'''						)
						get_tf_activation('''tanh'''						)
						with self.assertRaises(lowerCamelCase						):
											get_tf_activation('''bogus'''						)
						with self.assertRaises(lowerCamelCase						):
											get_tf_activation(lowerCamelCase						)



