


import inspect
import re
from hashlib import shaaaa
from typing import Dict, List

from .arrow import arrow
from .audiofolder import audiofolder
from .csv import csv
from .imagefolder import imagefolder
from .json import json
from .pandas import pandas
from .parquet import parquet
from .sql import sql  # noqa F401
from .text import text






def 	__lowerCamelCase						(							lowerCamelCase__		:						List[str]      ):





			'''simple docstring'''




			lowerCamelCase    		=  []
			for line in lines:
						lowerCamelCase    		=  re.sub(R"""#.*"""  ,							""""""  ,							lowerCamelCase__      )  # remove comments
						if line:
									filtered_lines.append(lowerCamelCase__      )
			lowerCamelCase    		=  """\n""".join(lowerCamelCase__      )

			# Make a hash from all this code
			lowerCamelCase    		=  full_str.encode("""utf-8"""      )
			return shaaaa(lowerCamelCase__      ).hexdigest()


# get importable module names and hash for caching
UpperCAmelCase   :    Optional[Any]     =		{
    "csv": (csv.__name__, _hash_python_lines(inspect.getsource(csv).splitlines())),
    "json": (json.__name__, _hash_python_lines(inspect.getsource(json).splitlines())),
    "pandas": (pandas.__name__, _hash_python_lines(inspect.getsource(pandas).splitlines())),
    "parquet": (parquet.__name__, _hash_python_lines(inspect.getsource(parquet).splitlines())),
    "arrow": (arrow.__name__, _hash_python_lines(inspect.getsource(arrow).splitlines())),
    "text": (text.__name__, _hash_python_lines(inspect.getsource(text).splitlines())),
    "imagefolder": (imagefolder.__name__, _hash_python_lines(inspect.getsource(imagefolder).splitlines())),
    "audiofolder": (audiofolder.__name__, _hash_python_lines(inspect.getsource(audiofolder).splitlines())),
}

# Used to infer the module to use based on the data files extensions
UpperCAmelCase   :    List[str]     =		{
    ".csv": ("csv", {}),
    ".tsv": ("csv", {"sep": "\t"}),
    ".json": ("json", {}),
    ".jsonl": ("json", {}),
    ".parquet": ("parquet", {}),
    ".arrow": ("arrow", {}),
    ".txt": ("text", {}),
}
_EXTENSION_TO_MODULE.update({ext: ("imagefolder", {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ("imagefolder", {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext: ("audiofolder", {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ("audiofolder", {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
UpperCAmelCase   :    List[Any]     =		{"imagefolder", "audiofolder"}

# Used to filter data files based on extensions given a module name
UpperCAmelCase   :    Dict[str, List[str]]     =		{}
for _ext, (_module, _) in _EXTENSION_TO_MODULE.items():
		_MODULE_TO_EXTENSIONS.setdefault(_module, []).append(_ext)

_MODULE_TO_EXTENSIONS["imagefolder"].append(".zip")



_MODULE_TO_EXTENSIONS["audiofolder"].append(".zip")





import math

import tensorflow as tf
from packaging import version






def 	__lowerCamelCase						(							lowerCamelCase__		:						Any      ):





			'''simple docstring'''




			lowerCamelCase    		=  tf.convert_to_tensor(lowerCamelCase__      )
			lowerCamelCase    		=  0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0      )  ,							x.dtype      )      ))

			return x * cdf






def 	__lowerCamelCase						(							lowerCamelCase__		:						List[str]      ):





			'''simple docstring'''




			lowerCamelCase    		=  tf.convert_to_tensor(lowerCamelCase__      )
			lowerCamelCase    		=  tf.cast(math.pi  ,							x.dtype      )
			lowerCamelCase    		=  tf.cast(0.0_4_4_7_1_5  ,							x.dtype      )
			lowerCamelCase    		=  0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi      ) * (x + coeff * tf.pow(lowerCamelCase__  ,							3      ))      ))

			return x * cdf






def 	__lowerCamelCase						(							lowerCamelCase__		:						int      ):





			'''simple docstring'''




			lowerCamelCase    		=  tf.convert_to_tensor(lowerCamelCase__      )

			return x * tf.tanh(tf.math.softplus(lowerCamelCase__      )      )






def 	__lowerCamelCase						(							lowerCamelCase__		:						Union[str, Any]      ):





			'''simple docstring'''




			lowerCamelCase    		=  tf.convert_to_tensor(lowerCamelCase__      )
			lowerCamelCase    		=  tf.cast(0.0_4_4_7_1_5  ,							x.dtype      )
			lowerCamelCase    		=  tf.cast(0.7_9_7_8_8_4_5_6_0_8  ,							x.dtype      )

			return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)      ))






def 	__lowerCamelCase						(							lowerCamelCase__		:						Optional[int]      ):





			'''simple docstring'''




			lowerCamelCase    		=  tf.convert_to_tensor(lowerCamelCase__      )
			lowerCamelCase    		=  tf.cast(1.7_0_2  ,							x.dtype      )
			return x * tf.math.sigmoid(coeff * x      )






def 	__lowerCamelCase						(							lowerCamelCase__		:						Dict      ):





			'''simple docstring'''




			return tf.clip_by_value(_gelu(lowerCamelCase__      )  ,							-10  ,							10      )






def 	__lowerCamelCase						(							lowerCamelCase__		:						int  ,							lowerCamelCase__		:						Dict=-1      ):





			'''simple docstring'''




			lowerCamelCase		,		lowerCamelCase    		=  tf.split(lowerCamelCase__  ,							2  ,							axis=lowerCamelCase__      )
			return a * tf.math.sigmoid(lowerCamelCase__      )


if version.parse(tf.version.VERSION) >= version.parse("2.4"):






		def 	__lowerCamelCase						(							lowerCamelCase__		:						Union[str, Any]      ):





					'''simple docstring'''




					return tf.keras.activations.gelu(lowerCamelCase__  ,							approximate=lowerCamelCase__      )

		UpperCAmelCase   :    Union[str, Any]     =		tf.keras.activations.gelu



		UpperCAmelCase   :    int     =		approximate_gelu_wrap
else:
		UpperCAmelCase   :    Dict     =		_gelu
		UpperCAmelCase   :    Dict     =		_gelu_new


UpperCAmelCase   :    List[str]     =		{
    "gelu": gelu,
    "gelu_10": gelu_aa,
    "gelu_fast": gelu_fast,
    "gelu_new": gelu_new,
    "glu": glu,
    "mish": mish,
    "quick_gelu": quick_gelu,
    "relu": tf.keras.activations.relu,
    "sigmoid": tf.keras.activations.sigmoid,
    "silu": tf.keras.activations.swish,
    "swish": tf.keras.activations.swish,
    "tanh": tf.keras.activations.tanh,
}






def 	__lowerCamelCase						(							lowerCamelCase__		:						Tuple      ):





			'''simple docstring'''




			if activation_string in ACTaFN:
						return ACTaFN[activation_string]
			else:
						raise KeyError(f'function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()      )}'      )

