
"""simple docstring"""




import numpy as np
from scipy.spatial.distance import cdist
from sklearn.metrics import fa_score

import datasets


UpperCAmelCase__      :    Any    							= '\\n    @inproceedings{kakwani2020indicnlpsuite,\n    title={{IndicNLPSuite: Monolingual Corpora, Evaluation Benchmarks and Pre-trained Multilingual Language Models for Indian Languages}},\n    author={Divyanshu Kakwani and Anoop Kunchukuttan and Satish Golla and Gokul N.C. and Avik Bhattacharyya and Mitesh M. Khapra and Pratyush Kumar},\n    year={2020},\n    booktitle={Findings of EMNLP},\n}\n'

UpperCAmelCase__      :    Dict    							= '\\n    IndicGLUE is a natural language understanding benchmark for Indian languages. It contains a wide\n    variety of tasks and covers 11 major Indian languages - as, bn, gu, hi, kn, ml, mr, or, pa, ta, te.\n'

UpperCAmelCase__      :    int    							= '\nCompute IndicGLUE evaluation metric associated to each IndicGLUE dataset.\nArgs:\n    predictions: list of predictions to score (as int64),\n        except for \'cvit-mkb-clsr\' where each prediction is a vector (of float32).\n    references: list of ground truth labels corresponding to the predictions (as int64),\n        except for \'cvit-mkb-clsr\' where each reference is a vector (of float32).\nReturns: depending on the IndicGLUE subset, one or several of:\n    "accuracy": Accuracy\n    "f1": F1 score\n    "precision": Precision@10\nExamples:\n\n    >>> indic_glue_metric = datasets.load_metric(\'indic_glue\', \'wnli\')  # \'wnli\' or any of ["copa", "sna", "csqa", "wstp", "inltkh", "bbca", "iitp-mr", "iitp-pr", "actsa-sc", "md"]\n    >>> references = [0, 1]\n    >>> predictions = [0, 1]\n    >>> results = indic_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'accuracy\': 1.0}\n\n    >>> indic_glue_metric = datasets.load_metric(\'indic_glue\', \'wiki-ner\')\n    >>> references = [0, 1]\n    >>> predictions = [0, 1]\n    >>> results = indic_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'accuracy\': 1.0, \'f1\': 1.0}\n\n    >>> indic_glue_metric = datasets.load_metric(\'indic_glue\', \'cvit-mkb-clsr\')\n    >>> references = [[0.5, 0.5, 0.5], [0.1, 0.2, 0.3]]\n    >>> predictions = [[0.5, 0.5, 0.5], [0.1, 0.2, 0.3]]\n    >>> results = indic_glue_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'precision@10\': 1.0}\n\n'

def lowercase_  (   _snake_case   ,_snake_case						):
							return float((preds == labels).mean()						)

def lowercase_  (   _snake_case   ,_snake_case						):
							SCREAMING_SNAKE_CASE__						:       List[Any]           =   simple_accuracy(__UpperCamelCase   ,__UpperCamelCase						)
							SCREAMING_SNAKE_CASE__						:       List[str]           =   float(fa_score(y_true=__UpperCamelCase   ,y_pred=__UpperCamelCase						)						)
							return {
							    "accuracy": acc,
							    "f1": fa,
							}

def lowercase_  (   _snake_case   ,_snake_case						):
							SCREAMING_SNAKE_CASE__						:       Union[str, Any]           =   np.array(__UpperCamelCase						)
							SCREAMING_SNAKE_CASE__						:       Optional[int]           =   np.array(__UpperCamelCase						)
							SCREAMING_SNAKE_CASE__						:       str           =   en_sentvecs.shape[0]

							# mean centering
							SCREAMING_SNAKE_CASE__						:       Tuple           =   en_sentvecs - np.mean(__UpperCamelCase   ,axis=0						)
							SCREAMING_SNAKE_CASE__						:       List[str]           =   in_sentvecs - np.mean(__UpperCamelCase   ,axis=0						)

							SCREAMING_SNAKE_CASE__						:       Dict           =   cdist(__UpperCamelCase   ,__UpperCamelCase   ,"""cosine"""						)
							SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   np.array(range(__UpperCamelCase						)						)
							SCREAMING_SNAKE_CASE__						:       int           =   sim.argsort(axis=1						)[:, :10]
							SCREAMING_SNAKE_CASE__						:       int           =   np.any(preds == actual[:, None]   ,axis=1						)
							return float(matches.mean()						)



@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION ,					_KWARGS_DESCRIPTION  )
class 	lowerCAmelCase_						(datasets.Metric  ):


				"""simple docstring"""



				def 	__magic_name__    (self    )					->		str:



											"""simple docstring"""




											if self.config_name not in [
											    "wnli",
											    "copa",
											    "sna",
											    "csqa",
											    "wstp",
											    "inltkh",
											    "bbca",
											    "cvit-mkb-clsr",
											    "iitp-mr",
											    "iitp-pr",
											    "actsa-sc",
											    "md",
											    "wiki-ner",
											]:
																		raise KeyError(
																		    """You should supply a configuration name selected in """
																		    """[\"wnli\", \"copa\", \"sna\", \"csqa\", \"wstp\", \"inltkh\", \"bbca\", """
																		    """\"cvit-mkb-clsr\", \"iitp-mr\", \"iitp-pr\", \"actsa-sc\", \"md\", """
																		    """\"wiki-ner\"]"""    )
											return datasets.MetricInfo(
											    description=_DESCRIPTION   ,       citation=_CITATION   ,       inputs_description=_KWARGS_DESCRIPTION   ,       features=datasets.Features(
											        {
											            """predictions""": datasets.Value("""int64"""    )
											            if self.config_name != """cvit-mkb-clsr"""
											            else datasets.Sequence(datasets.Value("""float32"""    )    ),
											            """references""": datasets.Value("""int64"""    )
											            if self.config_name != """cvit-mkb-clsr"""
											            else datasets.Sequence(datasets.Value("""float32"""    )    ),
											        }    )   ,       codebase_urls=[]   ,       reference_urls=[]   ,       format="""numpy""" if self.config_name != """cvit-mkb-clsr""" else None   ,       )



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__    )					->		int:



											"""simple docstring"""




											if self.config_name == "cvit-mkb-clsr":
																		return {"precision@10": precision_at_aa(_lowerCamelCase   ,       _lowerCamelCase    )}
											elif self.config_name in ["wiki-ner"]:
																		return acc_and_fa(_lowerCamelCase   ,       _lowerCamelCase    )
											elif self.config_name in [
											    "wnli",
											    "copa",
											    "sna",
											    "csqa",
											    "wstp",
											    "inltkh",
											    "bbca",
											    "iitp-mr",
											    "iitp-pr",
											    "actsa-sc",
											    "md",
											]:
																		return {"accuracy": simple_accuracy(_lowerCamelCase   ,       _lowerCamelCase    )}
											else:
																		raise KeyError(
																		    """You should supply a configuration name selected in """
																		    """[\"wnli\", \"copa\", \"sna\", \"csqa\", \"wstp\", \"inltkh\", \"bbca\", """
																		    """\"cvit-mkb-clsr\", \"iitp-mr\", \"iitp-pr\", \"actsa-sc\", \"md\", """
																		    """\"wiki-ner\"]"""    )












"""simple docstring"""


import numpy as np
from cva import COLOR_BGR2GRAY, cvtColor, imread
from numpy import array, uinta
from PIL import Image

from digital_image_processing import change_contrast as cc
from digital_image_processing import convert_to_negative as cn
from digital_image_processing import sepia as sp
from digital_image_processing.dithering import burkes as bs
from digital_image_processing.edge_detection import canny
from digital_image_processing.filters import convolve as conv
from digital_image_processing.filters import gaussian_filter as gg
from digital_image_processing.filters import local_binary_pattern as lbp
from digital_image_processing.filters import median_filter as med
from digital_image_processing.filters import sobel_filter as sob
from digital_image_processing.resize import resize as rs

lowercase_				     =     imread(R'digital_image_processing/image_data/lena_small.jpg')
lowercase_				     =     cvtColor(img, COLOR_BGR2GRAY)



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  __A									= cn.convert_to_negative(__UpperCamelCase )
  # assert negative_img array for at least one True
  assert negative_img.any()



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  with Image.open('''digital_image_processing/image_data/lena_small.jpg''' ) as img:
    # Work around assertion for response
    assert str(cc.change_contrast(__UpperCamelCase		,       1_1_0 ) ).startswith(
        '''<PIL.Image.Image image mode=RGB size=100x100 at''' )



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  __A									= canny.gen_gaussian_kernel(9		,       sigma=1.4 )
  # Assert ambiguous array
  assert resp.all()



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  __A									= imread('''digital_image_processing/image_data/lena_small.jpg'''		,       0 )
  # assert ambiguous array for all == True
  assert canny_img.all()
  __A									= canny.canny(__UpperCamelCase )
  # assert canny array for at least one True
  assert canny_array.any()



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  assert gg.gaussian_filter(__UpperCamelCase		,       5		,       sigma=0.9 ).all()



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  __A									= array([[0.25, 0.5, 0.25], [0.5, -3, 0.5], [0.25, 0.5, 0.25]] )
  __A									= conv.img_convolve(__UpperCamelCase		,       __UpperCamelCase ).astype(__UpperCamelCase )
  assert res.any()



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  assert med.median_filter(__UpperCamelCase		,       3 ).any()



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  __A			,    __A									= sob.sobel_filter(__UpperCamelCase )
  assert grad.any() and theta.any()



def 					lowerCAmelCase				(    ):




  """simple docstring"""







  __A									= sp.make_sepia(__UpperCamelCase		,       2_0 )
  assert sepia.all()



def 					lowerCAmelCase				(    __UpperCamelCase = "digital_image_processing/image_data/lena_small.jpg" ):




  """simple docstring"""







  __A									= bs.Burkes(imread(__UpperCamelCase		,       1 )		,       1_2_0 )
  burkes.process()
  assert burkes.output_img.any()



def 					lowerCAmelCase				(    __UpperCamelCase = "digital_image_processing/image_data/lena_small.jpg"		,       ):




  """simple docstring"""







  __A									= rs.NearestNeighbour(imread(__UpperCamelCase		,       1 )		,       4_0_0		,       2_0_0 )
  nn.process()
  assert nn.output.any()





def 					lowerCAmelCase				(    ):




  """simple docstring"""







  __A									= '''digital_image_processing/image_data/lena.jpg'''

  # Reading the image and converting it to grayscale.
  __A									= imread(__UpperCamelCase		,       0 )

  # Test for get_neighbors_pixel function() return not None
  __A									= 0
  __A									= 0
  __A									= image[x_coordinate][y_coordinate]

  __A									= lbp.get_neighbors_pixel(
      __UpperCamelCase		,       __UpperCamelCase		,       __UpperCamelCase		,       __UpperCamelCase )

  assert neighbors_pixels is not None

  # Test for local_binary_pattern function()
  # Create a numpy array as the same height and width of read image
  __A									= np.zeros((image.shape[0], image.shape[1]) )

  # Iterating through the image and calculating the local binary pattern value
  # for each pixel.
  for i in range(0		,       image.shape[0] ):
    for j in range(0		,       image.shape[1] ):
      __A									= lbp.local_binary_value(__UpperCamelCase		,       __UpperCamelCase		,       __UpperCamelCase )

  assert lbp_image.any()




