





import argparse
import json
import os

from tensorflow.core.protobuf.saved_model_pba import SavedModel


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_copies.py
lowercase_					     =	"""."""

# Internal TensorFlow ops that can be safely ignored (mostly specific to a saved model)
lowercase_					     =	[
    """Assert""",
    """AssignVariableOp""",
    """EmptyTensorList""",
    """MergeV2Checkpoints""",
    """ReadVariableOp""",
    """ResourceGather""",
    """RestoreV2""",
    """SaveV2""",
    """ShardedFilename""",
    """StatefulPartitionedCall""",
    """StaticRegexFullMatch""",
    """VarHandleOp""",
]




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	)       ->     int:
  lowercase__			    =						SavedModel()
  lowercase__			    =						[]

  with open(os.path.join(_SCREAMING_SNAKE_CASE	,		'utils'	,		'tf_ops'	,		'onnx.json'	)	) as f:
    lowercase__			    =						json.load(_SCREAMING_SNAKE_CASE	)['opsets']

  for i in range(1	,		opset + 1	):
    onnx_ops.extend(onnx_opsets[str(_SCREAMING_SNAKE_CASE	)]	)

  with open(_SCREAMING_SNAKE_CASE	,		'rb'	) as f:
    saved_model.ParseFromString(f.read()	)

  lowercase__			    =						set()

  # Iterate over every metagraph in case there is more than one (a saved model can contain multiple graphs)
  for meta_graph in saved_model.meta_graphs:
    # Add operations in the graph definition
    model_op_names.update(node.op for node in meta_graph.graph_def.node	)

    # Go through the functions in the graph definition
    for func in meta_graph.graph_def.library.function:
      # Add operations in each function
      model_op_names.update(node.op for node in func.node_def	)

    # Convert to list, sorted if you want
  lowercase__			    =						sorted(_SCREAMING_SNAKE_CASE	)
  lowercase__			    =						[]

  for op in model_op_names:
    if op not in onnx_ops and op not in INTERNAL_OPS:
      incompatible_ops.append(_SCREAMING_SNAKE_CASE	)

  if strict and len(_SCREAMING_SNAKE_CASE	) > 0:
    raise Exception(F"""Found the following incompatible ops for the opset {opset}:\n""" + incompatible_ops	)
  elif len(_SCREAMING_SNAKE_CASE	) > 0:
    print(F"""Found the following incompatible ops for the opset {opset}:"""	)
    print(*_SCREAMING_SNAKE_CASE	,		sep='\n'	)
  else:
    print(F"""The saved model {saved_model_path} can properly be converted with ONNX."""	)


if __name__ == "__main__":
      lowercase_					     =	argparse.ArgumentParser()
      parser.add_argument("""--saved_model_path""", help="""Path of the saved model to check (the .pb file).""")
      parser.add_argument(
          """--opset""", default=12, type=int, help="""The ONNX opset against which the model has to be tested."""
      )
      parser.add_argument(
          """--framework""", choices=["""onnx"""], default="""onnx""", help="""Frameworks against which to test the saved model."""
      )
      parser.add_argument(
          """--strict""", action="""store_true""", help="""Whether make the checking strict (raise errors) or not (raise warnings)"""
      )
      lowercase_					     =	parser.parse_args()

      if args.framework == "onnx":
            onnx_compliancy(args.saved_model_path, args.strict, args.opset)









from scipy.stats import spearmanr

import datasets


lowercase_					     =	"""
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
"""

lowercase_					     =	"""
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {'spearmanr': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric(\"spearmanr\")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results['spearmanr'])
        -0.7
        >>> print(round(results['spearmanr_pvalue'], 2))
        0.19
"""

lowercase_					     =	R"""\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
"""
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION    ,			_KWARGS_DESCRIPTION   )
class        SCREAMING_SNAKE_CASE     (datasets.Metric   ):


   def  SCREAMING_SNAKE_CASE_							(					self    :       Union[str, Any] )->     Tuple:





     """simple docstring"""







     return datasets.MetricInfo(
         description=_DESCRIPTION    ,  citation=_CITATION    ,  inputs_description=_KWARGS_DESCRIPTION    ,  features=datasets.Features(
             {
                 'predictions': datasets.Value('float' ),
                 'references': datasets.Value('float' ),
             } )    ,  reference_urls=['https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html']    ,  )


   def  SCREAMING_SNAKE_CASE_							(					self    :       int    ,  a    :       str    ,  a    :       Any    ,  a    :       str=False )->     Optional[int]:





     """simple docstring"""







     lowercase__			    =						spearmanr(a    ,  a )
     if return_pvalue:
       return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
     else:
       return {"spearmanr": results[0]}


