


import logging

import numpy as np
import pytest
from scipy.linalg import eigh

logging.basicConfig(level=logging.INFO, format='''%(message)s''')






def 					lowerCamelCase_   (	_a	):




		"""simple docstring"""






		return input_array.reshape((input_array.size, 1)	)






def 					lowerCamelCase_   (	_a     ,       _a     ,       _a	):




		"""simple docstring"""






		lowerCAmelCase__       :      Union[str, Any]   					= np.nan
		for i in range(_a	):
				lowerCAmelCase__       :      List[str]   					= features[:, labels == i]
				lowerCAmelCase__       :      Union[str, Any]   					= data.mean(1	)
				# Centralize the data of class i
				lowerCAmelCase__       :      Optional[Any]   					= data - column_reshape(_a	)
				if i > 0:
						# If covariance_sum is not None
						covariance_sum += np.dot(_a     ,       centered_data.T	)
				else:
						# If covariance_sum is np.nan (i.e. first loop)
						lowerCAmelCase__       :      Optional[Any]   					= np.dot(_a     ,       centered_data.T	)

		return covariance_sum / features.shape[1]






def 					lowerCamelCase_   (	_a     ,       _a     ,       _a	):




		"""simple docstring"""






		lowerCAmelCase__       :      Tuple   					= features.mean(1	)
		lowerCAmelCase__       :      List[str]   					= np.nan
		for i in range(_a	):
				lowerCAmelCase__       :      str   					= features[:, labels == i]
				lowerCAmelCase__       :      Any   					= data.shape[1]
				lowerCAmelCase__       :      int   					= data.mean(1	)
				if i > 0:
						# If covariance_sum is not None
						covariance_sum += device_data * np.dot(
						    column_reshape(_a	) - column_reshape(_a	)     ,       (column_reshape(_a	) - column_reshape(_a	)).T     ,       )
				else:
						# If covariance_sum is np.nan (i.e. first loop)
						lowerCAmelCase__       :      Optional[Any]   					= device_data * np.dot(
						    column_reshape(_a	) - column_reshape(_a	)     ,       (column_reshape(_a	) - column_reshape(_a	)).T     ,       )

		return covariance_sum / features.shape[1]






def 					lowerCamelCase_   (	_a     ,       _a	):




		"""simple docstring"""






		if features.any():
				lowerCAmelCase__       :      Any   					= features.mean(1	)
				# Center the dataset
				lowerCAmelCase__       :      Optional[int]   					= features - np.reshape(_a     ,       (data_mean.size, 1)	)
				lowerCAmelCase__       :      List[Any]   					= np.dot(_a     ,       centered_data.T	) / features.shape[1]
				lowerCAmelCase__					,     lowerCAmelCase__       :      int   					= np.linalg.eigh(_a	)
				# Take all the columns in the reverse order (-1), and then takes only the first
				lowerCAmelCase__       :      Tuple   					= eigenvectors[:, ::-1][:, 0:dimensions]
				# Project the database on the new space
				lowerCAmelCase__       :      Any   					= np.dot(filtered_eigenvectors.T     ,       _a	)
				logging.info('''Principal Component Analysis computed'''	)

				return projected_data
		else:
				logging.basicConfig(level=logging.ERROR     ,       format='''%(message)s'''     ,       force=_a	)
				logging.error('''Dataset empty'''	)
				raise AssertionError






def 					lowerCamelCase_   (	_a     ,       _a     ,       _a     ,       _a	):




		"""simple docstring"""






		assert classes > dimensions

		# Check if features have been already loaded
		if features.any:
				lowerCAmelCase__					,     lowerCAmelCase__       :      Dict   					= eigh(
				    covariance_between_classes(_a     ,       _a     ,       _a	)     ,       covariance_within_classes(_a     ,       _a     ,       _a	)     ,       )
				lowerCAmelCase__       :      Dict   					= eigenvectors[:, ::-1][:, :dimensions]
				lowerCAmelCase__					,     lowerCAmelCase__					,     lowerCAmelCase__       :      List[Any]   					= np.linalg.svd(_a	)
				lowerCAmelCase__       :      Any   					= svd_matrix[:, 0:dimensions]
				lowerCAmelCase__       :      Tuple   					= np.dot(filtered_svd_matrix.T     ,       _a	)
				logging.info('''Linear Discriminant Analysis computed'''	)

				return projected_data
		else:
				logging.basicConfig(level=logging.ERROR     ,       format='''%(message)s'''     ,       force=_a	)
				logging.error('''Dataset empty'''	)
				raise AssertionError






def 					lowerCamelCase_   (	):




		"""simple docstring"""






		lowerCAmelCase__       :      int   					= np.array([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7]]	)
		lowerCAmelCase__       :      List[str]   					= np.array([0, 0, 0, 1, 1]	)
		lowerCAmelCase__       :      Optional[int]   					= 2
		lowerCAmelCase__       :      str   					= 2

		# Assert that the function raises an AssertionError if dimensions > classes
		with pytest.raises(_a	) as error_info:
				lowerCAmelCase__       :      Dict   					= linear_discriminant_analysis(
				    _a     ,       _a     ,       _a     ,       _a	)
				if isinstance(_a     ,       np.ndarray	):
						raise AssertionError(
						    '''Did not raise AssertionError for dimensions > classes'''	)
				assert error_info.type is AssertionError






def 					lowerCamelCase_   (	):




		"""simple docstring"""






		lowerCAmelCase__       :      Optional[int]   					= np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]	)
		lowerCAmelCase__       :      str   					= 2
		lowerCAmelCase__       :      int   					= np.array([[6.92_82_03_23, 8.66_02_54_04, 10.39_23_04_85], [3.0, 3.0, 3.0]]	)

		with pytest.raises(_a	) as error_info:
				lowerCAmelCase__       :      str   					= principal_component_analysis(_a     ,       _a	)
				if not np.allclose(_a     ,       _a	):
						raise AssertionError
				assert error_info.type is AssertionError


if __name__ == "__main__":
		import doctest

		doctest.testmod()








import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_funnel import FunnelTokenizer


lowerCamelCase						=		logging.get_logger(__name__)

lowerCamelCase						=		{'''vocab_file''': '''vocab.txt''', '''tokenizer_file''': '''tokenizer.json'''}

lowerCamelCase						=		[
    '''small''',
    '''small-base''',
    '''medium''',
    '''medium-base''',
    '''intermediate''',
    '''intermediate-base''',
    '''large''',
    '''large-base''',
    '''xlarge''',
    '''xlarge-base''',
]

lowerCamelCase						=		{
    '''vocab_file''': {
        '''funnel-transformer/small''': '''https://huggingface.co/funnel-transformer/small/resolve/main/vocab.txt''',
        '''funnel-transformer/small-base''': '''https://huggingface.co/funnel-transformer/small-base/resolve/main/vocab.txt''',
        '''funnel-transformer/medium''': '''https://huggingface.co/funnel-transformer/medium/resolve/main/vocab.txt''',
        '''funnel-transformer/medium-base''': (
            '''https://huggingface.co/funnel-transformer/medium-base/resolve/main/vocab.txt'''
        ),
        '''funnel-transformer/intermediate''': (
            '''https://huggingface.co/funnel-transformer/intermediate/resolve/main/vocab.txt'''
        ),
        '''funnel-transformer/intermediate-base''': (
            '''https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/vocab.txt'''
        ),
        '''funnel-transformer/large''': '''https://huggingface.co/funnel-transformer/large/resolve/main/vocab.txt''',
        '''funnel-transformer/large-base''': '''https://huggingface.co/funnel-transformer/large-base/resolve/main/vocab.txt''',
        '''funnel-transformer/xlarge''': '''https://huggingface.co/funnel-transformer/xlarge/resolve/main/vocab.txt''',
        '''funnel-transformer/xlarge-base''': (
            '''https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/vocab.txt'''
        ),
    },
    '''tokenizer_file''': {
        '''funnel-transformer/small''': '''https://huggingface.co/funnel-transformer/small/resolve/main/tokenizer.json''',
        '''funnel-transformer/small-base''': (
            '''https://huggingface.co/funnel-transformer/small-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/medium''': '''https://huggingface.co/funnel-transformer/medium/resolve/main/tokenizer.json''',
        '''funnel-transformer/medium-base''': (
            '''https://huggingface.co/funnel-transformer/medium-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/intermediate''': (
            '''https://huggingface.co/funnel-transformer/intermediate/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/intermediate-base''': (
            '''https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/large''': '''https://huggingface.co/funnel-transformer/large/resolve/main/tokenizer.json''',
        '''funnel-transformer/large-base''': (
            '''https://huggingface.co/funnel-transformer/large-base/resolve/main/tokenizer.json'''
        ),
        '''funnel-transformer/xlarge''': '''https://huggingface.co/funnel-transformer/xlarge/resolve/main/tokenizer.json''',
        '''funnel-transformer/xlarge-base''': (
            '''https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/tokenizer.json'''
        ),
    },
}
lowerCamelCase						=		{f'''funnel-transformer/{name}''': 512 for name in _model_names}
lowerCamelCase						=		{f'''funnel-transformer/{name}''': {'''do_lower_case''': True} for name in _model_names}





class  _a							(    _lowercase):
	_a  :  Tuple				   =							VOCAB_FILES_NAMES
	_a  :  Dict				   =							PRETRAINED_VOCAB_FILES_MAP
	_a  :  Dict				   =							PRETRAINED_INIT_CONFIGURATION
	_a  :  Union[str, Any]				   =							FunnelTokenizer
	_a  :  int				   =							PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	_a  :  int				   =							2




	def __init__( self						:		List[Any]		, _SCREAMING_SNAKE_CASE						:		str=None		, _SCREAMING_SNAKE_CASE						:		str=None		, _SCREAMING_SNAKE_CASE						:		Any=True		, _SCREAMING_SNAKE_CASE						:		Any="<unk>"		, _SCREAMING_SNAKE_CASE						:		Dict="<sep>"		, _SCREAMING_SNAKE_CASE						:		Optional[int]="<pad>"		, _SCREAMING_SNAKE_CASE						:		str="<cls>"		, _SCREAMING_SNAKE_CASE						:		List[str]="<mask>"		, _SCREAMING_SNAKE_CASE						:		Optional[int]="<s>"		, _SCREAMING_SNAKE_CASE						:		Dict="</s>"		, _SCREAMING_SNAKE_CASE						:		Any=True		, _SCREAMING_SNAKE_CASE						:		Dict=True		, _SCREAMING_SNAKE_CASE						:		Tuple=None		, _SCREAMING_SNAKE_CASE						:		str="##"		, **_SCREAMING_SNAKE_CASE						:		List[str]		, )->	List[str]:
			super().__init__(
			    _SCREAMING_SNAKE_CASE		, tokenizer_file=_SCREAMING_SNAKE_CASE		, do_lower_case=_SCREAMING_SNAKE_CASE		, unk_token=_SCREAMING_SNAKE_CASE		, sep_token=_SCREAMING_SNAKE_CASE		, pad_token=_SCREAMING_SNAKE_CASE		, cls_token=_SCREAMING_SNAKE_CASE		, mask_token=_SCREAMING_SNAKE_CASE		, bos_token=_SCREAMING_SNAKE_CASE		, eos_token=_SCREAMING_SNAKE_CASE		, clean_text=_SCREAMING_SNAKE_CASE		, tokenize_chinese_chars=_SCREAMING_SNAKE_CASE		, strip_accents=_SCREAMING_SNAKE_CASE		, wordpieces_prefix=_SCREAMING_SNAKE_CASE		, **_SCREAMING_SNAKE_CASE		, )

			lowerCAmelCase__       :      Any   					= json.loads(self.backend_tokenizer.normalizer.__getstate__()		)
			if (
			    normalizer_state.get('''lowercase'''		, _SCREAMING_SNAKE_CASE		) != do_lower_case
			    or normalizer_state.get('''strip_accents'''		, _SCREAMING_SNAKE_CASE		) != strip_accents
			    or normalizer_state.get('''handle_chinese_chars'''		, _SCREAMING_SNAKE_CASE		) != tokenize_chinese_chars
			):
					lowerCAmelCase__       :      int   					= getattr(_SCREAMING_SNAKE_CASE		, normalizer_state.pop('''type'''		)		)
					lowerCAmelCase__       :      Dict   					= do_lower_case
					lowerCAmelCase__       :      str   					= strip_accents
					lowerCAmelCase__       :      Dict   					= tokenize_chinese_chars
					lowerCAmelCase__       :      str   					= normalizer_class(**_SCREAMING_SNAKE_CASE		)

			lowerCAmelCase__       :      List[Any]   					= do_lower_case




	def 							UpperCAmelCase__( self						:		Any		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]		, _SCREAMING_SNAKE_CASE						:		Union[str, Any]=None		)->	Optional[int]:
			lowerCAmelCase__       :      Tuple   					= [self.cls_token_id] + token_ids_a + [self.sep_token_id]

			if token_ids_a:
					output += token_ids_a + [self.sep_token_id]

			return output




	def 							UpperCAmelCase__( self						:		Optional[Any]		, _SCREAMING_SNAKE_CASE						:		List[int]		, _SCREAMING_SNAKE_CASE						:		Optional[List[int]] = None		)->	List[int]:
			lowerCAmelCase__       :      str   					= [self.sep_token_id]
			lowerCAmelCase__       :      Optional[int]   					= [self.cls_token_id]
			if token_ids_a is None:
					return len(cls		) * [self.cls_token_type_id] + len(token_ids_a + sep		) * [0]
			return len(cls		) * [self.cls_token_type_id] + len(token_ids_a + sep		) * [0] + len(token_ids_a + sep		) * [1]




	def 							UpperCAmelCase__( self						:		str		, _SCREAMING_SNAKE_CASE						:		str		, _SCREAMING_SNAKE_CASE						:		Optional[str] = None		)->	Tuple[str]:
			lowerCAmelCase__       :      Any   					= self._tokenizer.model.save(_SCREAMING_SNAKE_CASE		, name=_SCREAMING_SNAKE_CASE		)
			return tuple(_SCREAMING_SNAKE_CASE		)




