




import logging

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

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

def lowercase    (  SCREAMING_SNAKE_CASE )			->							np.ndarray:


			'''simple docstring'''







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

def lowercase    (  SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE )			->							np.ndarray:


			'''simple docstring'''







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

			return covariance_sum / features.shape[1]

def lowercase    (  SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE )			->							np.ndarray:


			'''simple docstring'''







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

			return covariance_sum / features.shape[1]

def lowercase    (  SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE )			->							np.ndarray:


			'''simple docstring'''







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

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

def lowercase    (  SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE )			->							np.ndarray:


			'''simple docstring'''







			assert classes > dimensions

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

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

def lowercase    (  )			->							None:


			'''simple docstring'''







			SCREAMING_SNAKE_CASE_								=						np.array([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7]] )
			SCREAMING_SNAKE_CASE_								=						np.array([0, 0, 0, 1, 1] )
			SCREAMING_SNAKE_CASE_								=						2
			SCREAMING_SNAKE_CASE_								=						2

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

def lowercase    (  )			->							None:


			'''simple docstring'''







			SCREAMING_SNAKE_CASE_								=						np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]] )
			SCREAMING_SNAKE_CASE_								=						2
			SCREAMING_SNAKE_CASE_								=						np.array([[6.92820323, 8.66025404, 10.39230485], [3.0, 3.0, 3.0]] )

			with pytest.raises(SCREAMING_SNAKE_CASE ) as error_info:
						SCREAMING_SNAKE_CASE_								=						principal_component_analysis(SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE )
						if not np.allclose(SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE ):
									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_bert import BertTokenizer


SCREAMING_SNAKE_CASE__     :     Dict		    =       logging.get_logger(__name__)

SCREAMING_SNAKE_CASE__     :     int		    =       {"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

SCREAMING_SNAKE_CASE__     :     Dict		    =       {
    "vocab_file": {
        "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt",
        "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt",
        "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/vocab.txt",
        "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/vocab.txt",
        "bert-base-multilingual-uncased": (
            "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt"
        ),
        "bert-base-multilingual-cased": "https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt",
        "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt",
        "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt",
        "bert-large-uncased-whole-word-masking": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt"
        ),
        "bert-large-cased-whole-word-masking": (
            "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt"
        ),
        "bert-large-uncased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"
        ),
        "bert-large-cased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"
        ),
        "bert-base-cased-finetuned-mrpc": (
            "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt"
        ),
        "bert-base-german-dbmdz-cased": "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt",
        "bert-base-german-dbmdz-uncased": (
            "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt"
        ),
        "TurkuNLP/bert-base-finnish-cased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt"
        ),
        "TurkuNLP/bert-base-finnish-uncased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt"
        ),
        "wietsedv/bert-base-dutch-cased": (
            "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt"
        ),
    },
    "tokenizer_file": {
        "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json",
        "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json",
        "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json",
        "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json",
        "bert-base-multilingual-uncased": (
            "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json"
        ),
        "bert-base-multilingual-cased": (
            "https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json"
        ),
        "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json",
        "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json",
        "bert-large-uncased-whole-word-masking": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json"
        ),
        "bert-large-cased-whole-word-masking": (
            "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json"
        ),
        "bert-large-uncased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"
        ),
        "bert-large-cased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"
        ),
        "bert-base-cased-finetuned-mrpc": (
            "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json"
        ),
        "bert-base-german-dbmdz-cased": (
            "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json"
        ),
        "bert-base-german-dbmdz-uncased": (
            "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json"
        ),
        "TurkuNLP/bert-base-finnish-cased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json"
        ),
        "TurkuNLP/bert-base-finnish-uncased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json"
        ),
        "wietsedv/bert-base-dutch-cased": (
            "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json"
        ),
    },
}

SCREAMING_SNAKE_CASE__     :     List[Any]		    =       {
    "bert-base-uncased": 5_12,
    "bert-large-uncased": 5_12,
    "bert-base-cased": 5_12,
    "bert-large-cased": 5_12,
    "bert-base-multilingual-uncased": 5_12,
    "bert-base-multilingual-cased": 5_12,
    "bert-base-chinese": 5_12,
    "bert-base-german-cased": 5_12,
    "bert-large-uncased-whole-word-masking": 5_12,
    "bert-large-cased-whole-word-masking": 5_12,
    "bert-large-uncased-whole-word-masking-finetuned-squad": 5_12,
    "bert-large-cased-whole-word-masking-finetuned-squad": 5_12,
    "bert-base-cased-finetuned-mrpc": 5_12,
    "bert-base-german-dbmdz-cased": 5_12,
    "bert-base-german-dbmdz-uncased": 5_12,
    "TurkuNLP/bert-base-finnish-cased-v1": 5_12,
    "TurkuNLP/bert-base-finnish-uncased-v1": 5_12,
    "wietsedv/bert-base-dutch-cased": 5_12,
}

SCREAMING_SNAKE_CASE__     :     Union[str, Any]		    =       {
    "bert-base-uncased": {"do_lower_case": True},
    "bert-large-uncased": {"do_lower_case": True},
    "bert-base-cased": {"do_lower_case": False},
    "bert-large-cased": {"do_lower_case": False},
    "bert-base-multilingual-uncased": {"do_lower_case": True},
    "bert-base-multilingual-cased": {"do_lower_case": False},
    "bert-base-chinese": {"do_lower_case": False},
    "bert-base-german-cased": {"do_lower_case": False},
    "bert-large-uncased-whole-word-masking": {"do_lower_case": True},
    "bert-large-cased-whole-word-masking": {"do_lower_case": False},
    "bert-large-uncased-whole-word-masking-finetuned-squad": {"do_lower_case": True},
    "bert-large-cased-whole-word-masking-finetuned-squad": {"do_lower_case": False},
    "bert-base-cased-finetuned-mrpc": {"do_lower_case": False},
    "bert-base-german-dbmdz-cased": {"do_lower_case": False},
    "bert-base-german-dbmdz-uncased": {"do_lower_case": True},
    "TurkuNLP/bert-base-finnish-cased-v1": {"do_lower_case": False},
    "TurkuNLP/bert-base-finnish-uncased-v1": {"do_lower_case": True},
    "wietsedv/bert-base-dutch-cased": {"do_lower_case": False},
}



class       a_       (     SCREAMING_SNAKE_CASE__     ):
	A    							= VOCAB_FILES_NAMES
	A    							= PRETRAINED_VOCAB_FILES_MAP
	A    							= PRETRAINED_INIT_CONFIGURATION
	A    							= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	A    							= BertTokenizer





	def __init__(							self      ,     SCREAMING_SNAKE_CASE=None      ,     SCREAMING_SNAKE_CASE=None      ,     SCREAMING_SNAKE_CASE=True      ,     SCREAMING_SNAKE_CASE="[UNK]"      ,     SCREAMING_SNAKE_CASE="[SEP]"      ,     SCREAMING_SNAKE_CASE="[PAD]"      ,     SCREAMING_SNAKE_CASE="[CLS]"      ,     SCREAMING_SNAKE_CASE="[MASK]"      ,     SCREAMING_SNAKE_CASE=True      ,     SCREAMING_SNAKE_CASE=None      ,     **SCREAMING_SNAKE_CASE      ,     )  ->					List[str]:




				"""simple docstring"""



				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      ,     tokenize_chinese_chars=SCREAMING_SNAKE_CASE      ,     strip_accents=SCREAMING_SNAKE_CASE      ,     **SCREAMING_SNAKE_CASE      ,     )

				SCREAMING_SNAKE_CASE_								=						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
				):
							SCREAMING_SNAKE_CASE_								=						getattr(SCREAMING_SNAKE_CASE      ,     normalizer_state.pop('type'      )      )
							SCREAMING_SNAKE_CASE_								=						do_lower_case
							SCREAMING_SNAKE_CASE_								=						strip_accents
							SCREAMING_SNAKE_CASE_								=						tokenize_chinese_chars
							SCREAMING_SNAKE_CASE_								=						normalizer_class(**SCREAMING_SNAKE_CASE      )

				SCREAMING_SNAKE_CASE_								=						do_lower_case





	def 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE=None      )  ->					Union[str, Any]:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						[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 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE = None      )  ->					List[int]:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						[self.sep_token_id]
				SCREAMING_SNAKE_CASE_								=						[self.cls_token_id]
				if token_ids_a is None:
							return len(cls + token_ids_a + sep      ) * [0]
				return len(cls + token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]





	def 						A_(							self      ,     SCREAMING_SNAKE_CASE      ,     SCREAMING_SNAKE_CASE = None      )  ->					Tuple[str]:




				"""simple docstring"""



				SCREAMING_SNAKE_CASE_								=						self._tokenizer.model.save(SCREAMING_SNAKE_CASE      ,     name=SCREAMING_SNAKE_CASE      )
				return tuple(SCREAMING_SNAKE_CASE      )
