





import math_equivalence  # From: git+https://github.com/hendrycks/math.git

import datasets


snake_case_           =      """\
@article{hendrycksmath2021,
  title={Measuring Mathematical Problem Solving With the MATH Dataset},
  author={Dan Hendrycks
    and Collin Burns
    and Saurav Kadavath
    and Akul Arora
    and Steven Basart
    and Eric Tang
    and Dawn Song
    and Jacob Steinhardt},
  journal={arXiv preprint arXiv:2103.03874},
  year={2021}
}
"""


snake_case_           =      """\
This metric is used to assess performance on the Mathematics Aptitude Test of Heuristics (MATH) dataset.
It first canonicalizes the inputs (e.g., converting \"1/2\" to \"\\frac{1}{2}\") and then computes accuracy.
"""


snake_case_           =      r"""
Calculates accuracy after canonicalizing inputs.

Args:
    predictions: list of predictions to score. Each prediction
        is a string that contains natural language and LaTex.
    references: list of reference for each prediction. Each
        reference is a string that contains natural language
        and LaTex.
Returns:
    accuracy: accuracy after canonicalizing inputs
        (e.g., converting \"1/2\" to \"\\frac{1}{2}\")

Examples:
    >>> metric = datasets.load_metric(\"competition_math\")
    >>> results = metric.compute(references=[\"\\frac{1}{2}\"], predictions=[\"1/2\"])
    >>> print(results)
    {'accuracy': 1.0}
"""


@datasets.utils.file_utils.add_end_docstrings(_DESCRIPTION						,				_KWARGS_DESCRIPTION  )
class 		SCREAMING_SNAKE_CASE__    (	datasets.Metric  ):


      def        a			(self	:				Optional[Any]				):





         """simple docstring"""



         return datasets.MetricInfo(
             description=_DESCRIPTION    ,      citation=_CITATION    ,      inputs_description=_KWARGS_DESCRIPTION    ,      features=datasets.Features(
                 {
                     '''predictions''': datasets.Value('''string'''				),
                     '''references''': datasets.Value('''string'''				),
                 }				)    ,      homepage='''https://github.com/hendrycks/math'''    ,      codebase_urls=['''https://github.com/hendrycks/math''']    ,      )


      def        a			(self	:				Any    ,      a__	:				Union[str, Any]    ,      a__	:				Tuple				):





         """simple docstring"""



         __snake_case								=       0.0
         for i, j in zip(__lowercase    ,      __lowercase				):
            n_correct += 1.0 if math_equivalence.is_equiv(__lowercase    ,      __lowercase				) else 0.0
         __snake_case								=       n_correct / len(__lowercase				)
         return {
             "accuracy": accuracy,
         }








# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter


if TYPE_CHECKING:
    import torch

class 		SCREAMING_SNAKE_CASE__    (	TensorFormatter[Mapping, 'torch.Tensor', Mapping]  ):


      def __init__(self	:				Optional[int]    ,      a__	:				Tuple=None    ,      **a__	:				Optional[int]				):





         """simple docstring"""



         super().__init__(features=a__				)
         __snake_case								=       torch_tensor_kwargs
         import torch  # noqa import torch at initialization


      def        a			(self	:				Union[str, Any]    ,      a__	:				Union[str, Any]				):





         """simple docstring"""



         import torch

         if isinstance(a__    ,      a__				) and column:
            if all(
                isinstance(a__    ,      torch.Tensor				) and x.shape == column[0].shape and x.dtype == column[0].dtype
                for x in column				):
               return torch.stack(a__				)
         return column


      def        a			(self	:				Optional[Any]    ,      a__	:				str				):





         """simple docstring"""



         import torch

         if isinstance(a__    ,      (str, bytes, type(a__				))				):
            return value
         elif isinstance(a__    ,      (np.character, np.ndarray)				) and np.issubdtype(value.dtype    ,      np.character				):
            return value.tolist()

         __snake_case								=       {}

         if isinstance(a__    ,      (np.number, np.ndarray)				) and np.issubdtype(value.dtype    ,      np.integer				):
            __snake_case								=       {'''dtype''': torch.intaa}
         elif isinstance(a__    ,      (np.number, np.ndarray)				) and np.issubdtype(value.dtype    ,      np.floating				):
            __snake_case								=       {'''dtype''': torch.floataa}
         elif config.PIL_AVAILABLE and "PIL" in sys.modules:
            import PIL.Image

            if isinstance(a__    ,      PIL.Image.Image				):
               __snake_case								=       np.asarray(a__				)
         return torch.tensor(a__    ,      **{**default_dtype, **self.torch_tensor_kwargs}				)


      def        a			(self	:				Optional[int]    ,      a__	:				str				):





         """simple docstring"""



         import torch

         # support for torch, tf, jax etc.
         if hasattr(a__    ,      '''__array__'''				) and not isinstance(a__    ,      torch.Tensor				):
            __snake_case								=       data_struct.__array__()
         # support for nested types like struct of list of struct
         if isinstance(a__    ,      np.ndarray				):
            if data_struct.dtype == object:  # torch tensors cannot be instantied from an array of objects
               return self._consolidate([self.recursive_tensorize(a__				) for substruct in data_struct]				)
         elif isinstance(a__    ,      (list, tuple)				):
            return self._consolidate([self.recursive_tensorize(a__				) for substruct in data_struct]				)
         return self._tensorize(a__				)


      def        a			(self	:				Optional[Any]    ,      a__	:				dict				):





         """simple docstring"""



         return map_nested(self._recursive_tensorize    ,      a__    ,      map_list=a__				)


      def        a			(self	:				Optional[int]    ,      a__	:				pa.Table				):





         """simple docstring"""



         __snake_case								=       self.numpy_arrow_extractor().extract_row(a__				)
         __snake_case								=       self.python_features_decoder.decode_row(a__				)
         return self.recursive_tensorize(a__				)


      def        a			(self	:				List[Any]    ,      a__	:				pa.Table				):





         """simple docstring"""



         __snake_case								=       self.numpy_arrow_extractor().extract_column(a__				)
         __snake_case								=       self.python_features_decoder.decode_column(a__    ,      pa_table.column_names[0]				)
         __snake_case								=       self.recursive_tensorize(a__				)
         __snake_case								=       self._consolidate(a__				)
         return column


      def        a			(self	:				Optional[int]    ,      a__	:				pa.Table				):





         """simple docstring"""



         __snake_case								=       self.numpy_arrow_extractor().extract_batch(a__				)
         __snake_case								=       self.python_features_decoder.decode_batch(a__				)
         __snake_case								=       self.recursive_tensorize(a__				)
         for column_name in batch:
            __snake_case								=       self._consolidate(batch[column_name]				)
         return batch

