






'''simple docstring'''

from sklearn.metrics import recall_score

import datasets


SCREAMING_SNAKE_CASE__											=     '\nRecall is the fraction of the positive examples that were correctly labeled by the model as positive. It can be computed with the equation:\nRecall = TP / (TP + FN)\nWhere TP is the true positives and FN is the false negatives.\n'


SCREAMING_SNAKE_CASE__											=     '\nArgs:\n- **predictions** (`list` of `int`): The predicted labels.\n- **references** (`list` of `int`): The ground truth labels.\n- **labels** (`list` of `int`): The set of labels to include when `average` is not set to `binary`, and their order when average is `None`. Labels present in the data can be excluded in this input, for example to calculate a multiclass average ignoring a majority negative class, while labels not present in the data will result in 0 components in a macro average. For multilabel targets, labels are column indices. By default, all labels in y_true and y_pred are used in sorted order. Defaults to None.\n- **pos_label** (`int`): The class label to use as the \'positive class\' when calculating the recall. Defaults to `1`.\n- **average** (`string`): This parameter is required for multiclass/multilabel targets. If None, the scores for each class are returned. Otherwise, this determines the type of averaging performed on the data. Defaults to `\'binary\'`.\n    - `\'binary\'`: Only report results for the class specified by `pos_label`. This is applicable only if the target labels and predictions are binary.\n    - `\'micro\'`: Calculate metrics globally by counting the total true positives, false negatives, and false positives.\n    - `\'macro\'`: Calculate metrics for each label, and find their unweighted mean. This does not take label imbalance into account.\n    - `\'weighted\'`: Calculate metrics for each label, and find their average weighted by support (the number of true instances for each label). This alters `\'macro\'` to account for label imbalance. Note that it can result in an F-score that is not between precision and recall.\n    - `\'samples\'`: Calculate metrics for each instance, and find their average (only meaningful for multilabel classification).\n- **sample_weight** (`list` of `float`): Sample weights Defaults to `None`.\n- **zero_division** (): Sets the value to return when there is a zero division. Defaults to .\n    - `\'warn\'`: If there is a zero division, the return value is `0`, but warnings are also raised.\n    - `0`: If there is a zero division, the return value is `0`.\n    - `1`: If there is a zero division, the return value is `1`.\n\nReturns:\n- **recall** (`float`, or `array` of `float`): Either the general recall score, or the recall scores for individual classes, depending on the values input to `labels` and `average`. Minimum possible value is 0. Maximum possible value is 1. A higher recall means that more of the positive examples have been labeled correctly. Therefore, a higher recall is generally considered better.\n\nExamples:\n\n    Example 1-A simple example with some errors\n        >>> recall_metric = datasets.load_metric(\'recall\')\n        >>> results = recall_metric.compute(references=[0, 0, 1, 1, 1], predictions=[0, 1, 0, 1, 1])\n        >>> print(results)\n        {\'recall\': 0.6666666666666666}\n\n    Example 2-The same example as Example 1, but with `pos_label=0` instead of the default `pos_label=1`.\n        >>> recall_metric = datasets.load_metric(\'recall\')\n        >>> results = recall_metric.compute(references=[0, 0, 1, 1, 1], predictions=[0, 1, 0, 1, 1], pos_label=0)\n        >>> print(results)\n        {\'recall\': 0.5}\n\n    Example 3-The same example as Example 1, but with `sample_weight` included.\n        >>> recall_metric = datasets.load_metric(\'recall\')\n        >>> sample_weight = [0.9, 0.2, 0.9, 0.3, 0.8]\n        >>> results = recall_metric.compute(references=[0, 0, 1, 1, 1], predictions=[0, 1, 0, 1, 1], sample_weight=sample_weight)\n        >>> print(results)\n        {\'recall\': 0.55}\n\n    Example 4-A multiclass example, using different averages.\n        >>> recall_metric = datasets.load_metric(\'recall\')\n        >>> predictions = [0, 2, 1, 0, 0, 1]\n        >>> references = [0, 1, 2, 0, 1, 2]\n        >>> results = recall_metric.compute(predictions=predictions, references=references, average=\'macro\')\n        >>> print(results)\n        {\'recall\': 0.3333333333333333}\n        >>> results = recall_metric.compute(predictions=predictions, references=references, average=\'micro\')\n        >>> print(results)\n        {\'recall\': 0.3333333333333333}\n        >>> results = recall_metric.compute(predictions=predictions, references=references, average=\'weighted\')\n        >>> print(results)\n        {\'recall\': 0.3333333333333333}\n        >>> results = recall_metric.compute(predictions=predictions, references=references, average=None)\n        >>> print(results)\n        {\'recall\': array([1., 0., 0.])}\n'


SCREAMING_SNAKE_CASE__											=     '\n@article{scikit-learn, title={Scikit-learn: Machine Learning in {P}ython}, author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V. and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P. and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.}, journal={Journal of Machine Learning Research}, volume={12}, pages={2825--2830}, year={2011}\n'






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

  def 						A__		(   self   )						->   str:



        """simple docstring"""






        return datasets.MetricInfo(
            description=_DESCRIPTION    ,	citation=_CITATION    ,	inputs_description=_KWARGS_DESCRIPTION    ,	features=datasets.Features(
                {
                    """predictions""": datasets.Sequence(datasets.Value("""int32"""   )   ),
                    """references""": datasets.Sequence(datasets.Value("""int32"""   )   ),
                }
                if self.config_name == """multilabel"""
                else {
                    """predictions""": datasets.Value("""int32"""   ),
                    """references""": datasets.Value("""int32"""   ),
                }   )    ,	reference_urls=["""https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html"""]    ,	)


  def 						A__		(   self    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE=None    ,	_SCREAMING_SNAKE_CASE=1    ,	_SCREAMING_SNAKE_CASE="binary"    ,	_SCREAMING_SNAKE_CASE=None    ,	_SCREAMING_SNAKE_CASE="warn"    ,	)						->   int:



        """simple docstring"""






        UpperCamelCase       						=      recall_score(
            _SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	labels=_SCREAMING_SNAKE_CASE    ,	pos_label=_SCREAMING_SNAKE_CASE    ,	average=_SCREAMING_SNAKE_CASE    ,	sample_weight=_SCREAMING_SNAKE_CASE    ,	zero_division=_SCREAMING_SNAKE_CASE    ,	)
        return {"recall": float(_SCREAMING_SNAKE_CASE   ) if score.size == 1 else score}








'''simple docstring'''

# Copyright 2022 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os
import platform

import numpy as np
import psutil
import torch

from accelerate import __version__ as version
from accelerate.commands.config import default_config_file, load_config_from_file

from ..utils import is_npu_available, is_xpu_available







def 					lowercase__				(   __UpperCamelCase=None					)->				Union[str, Any]:
      if subparsers is not None:
            UpperCamelCase       						=      subparsers.add_parser("""env"""					)
      else:
            UpperCamelCase       						=      argparse.ArgumentParser("""Accelerate env command"""					)

      parser.add_argument(
          """--config_file"""	,		default=__UpperCamelCase	,		help="""The config file to use for the default values in the launching script."""					)

      if subparsers is not None:
            parser.set_defaults(func=__UpperCamelCase					)
      return parser







def 					lowercase__				(   __UpperCamelCase					)->				List[str]:
      UpperCamelCase       						=      torch.__version__
      UpperCamelCase       						=      torch.cuda.is_available()
      UpperCamelCase       						=      is_xpu_available()
      UpperCamelCase       						=      is_npu_available()

      UpperCamelCase       						=      """Not found"""
      # Get the default from the config file.
      if args.config_file is not None or os.path.isfile(__UpperCamelCase					):
            UpperCamelCase       						=      load_config_from_file(args.config_file					).to_dict()

      UpperCamelCase       						=      {
          """`Accelerate` version""": version,
          """Platform""": platform.platform(),
          """Python version""": platform.python_version(),
          """Numpy version""": np.__version__,
          """PyTorch version (GPU?)""": F"{pt_version} ({pt_cuda_available})",
          """PyTorch XPU available""": str(__UpperCamelCase					),
          """PyTorch NPU available""": str(__UpperCamelCase					),
          """System RAM""": F"{psutil.virtual_memory().total / 1024 ** 3:.2f} GB",
      }
      if pt_cuda_available:
            UpperCamelCase       						=      torch.cuda.get_device_name()

      print("""\nCopy-and-paste the text below in your GitHub issue\n"""					)
      print("""\n""".join([F"- {prop}: {val}" for prop, val in info.items()]					)					)

      print("""- `Accelerate` default config:""" if args.config_file is None else """- `Accelerate` config passed:"""					)
      UpperCamelCase       						=      (
          """\n""".join([F"\t- {prop}: {val}" for prop, val in accelerate_config.items()]					)
          if isinstance(__UpperCamelCase	,		__UpperCamelCase					)
          else F"\t{accelerate_config}"
      )
      print(__UpperCamelCase					)

      UpperCamelCase       						=      accelerate_config

      return info







def 					lowercase__				(   )->				int:
      UpperCamelCase       						=      env_command_parser()
      UpperCamelCase       						=      parser.parse_args()
      env_command(__UpperCamelCase					)
      return 0


if __name__ == "__main__":
     raise SystemExit(main())
