prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Fix discrepencies introduced by sciki-learn 0.23
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `skl2onnx/operator_converters/gaussian_process.py`
  Content:
  ```
  1 # -------------------------------------------------------------------------
  2 # Copyright (c) Microsoft Corporation. All rights reserved.
  3 # Licensed under the MIT License. See License.txt in the project root for
  4 # license information.
  5 # --------------------------------------------------------------------------
  6 import numpy as np
  7 from sklearn.gaussian_process.kernels import ConstantKernel as C, RBF
  8 from ..common._registration import register_converter
  9 from ..algebra.onnx_ops import (
  10     OnnxAdd, OnnxSqrt, OnnxMatMul, OnnxSub, OnnxReduceSum,
  11     OnnxMul, OnnxMax
  12 )
  13 try:
  14     from ..algebra.onnx_ops import OnnxConstantOfShape
  15 except ImportError:
  16     OnnxConstantOfShape = None
  17 
  18 from ._gp_kernels import (
  19     convert_kernel_diag,
  20     convert_kernel,
  21     _zero_vector_of_size
  22 )
  23 
  24 
  25 def convert_gaussian_process_regressor(scope, operator, container):
  26     """
  27     The method *predict* from class *GaussianProcessRegressor*
  28     may cache some results if it is called with parameter
  29     ``return_std=True`` or ``return_cov=True``. This converter
  30     needs to be called with theses options to enable
  31     the second results.
  32     See example :ref:`l-gpr-example` to see how to
  33     use this converter which does not behave exactly
  34     as the others.
  35     """
  36     dtype = container.dtype
  37     if dtype is None:
  38         raise RuntimeError("dtype cannot be None")
  39     X = operator.inputs[0]
  40     out = operator.outputs
  41     op = operator.raw_operator
  42     opv = container.target_opset
  43     if opv is None:
  44         raise RuntimeError("container.target_opset must not be None")
  45 
  46     options = container.get_options(op, dict(return_cov=False,
  47                                              return_std=False,
  48                                              optim=None))
  49     if hasattr(op, 'kernel_') and op.kernel_ is not None:
  50         kernel = op.kernel_
  51     elif op.kernel is None:
  52         kernel = (C(1.0, constant_value_bounds="fixed") *
  53                   RBF(1.0, length_scale_bounds="fixed"))
  54     else:
  55         kernel = op.kernel
  56 
  57     if not hasattr(op, "X_train_") or op.X_train_ is None:
  58         out0 = _zero_vector_of_size(X, keepdims=1, output_names=out[:1],
  59                                     dtype=dtype)
  60 
  61         outputs = [out0]
  62         if options['return_cov']:
  63             outputs.append(convert_kernel(kernel, X,
  64                                           output_names=out[1:],
  65                                           dtype=dtype,
  66                                           op_version=opv))
  67         if options['return_std']:
  68             outputs.append(
  69                 OnnxSqrt(
  70                     convert_kernel_diag(
  71                         kernel, X, dtype=dtype, op_version=opv),
  72                     output_names=out[1:], op_version=opv))
  73     else:
  74         out0 = _zero_vector_of_size(
  75             X, keepdims=1, dtype=dtype, op_version=opv)
  76 
  77         # Code scikit-learn
  78         # K_trans = self.kernel_(X, self.X_train_)
  79         # y_mean = K_trans.dot(self.alpha_)  # Line 4 (y_mean = f_star)
  80         # y_mean = self._y_train_mean + y_mean  # undo normal.
  81 
  82         k_trans = convert_kernel(kernel, X,
  83                                  x_train=op.X_train_.astype(dtype),
  84                                  dtype=dtype,
  85                                  optim=options.get('optim', None),
  86                                  op_version=opv)
  87         k_trans.set_onnx_name_prefix('kgpd')
  88         y_mean_b = OnnxMatMul(k_trans, op.alpha_.astype(dtype), op_version=opv)
  89 
  90         mean_y = op._y_train_mean.astype(dtype)
  91         if len(mean_y.shape) == 1:
  92             mean_y = mean_y.reshape(mean_y.shape + (1,))
  93         y_mean = OnnxAdd(y_mean_b, mean_y,
  94                          output_names=out[:1],
  95                          op_version=opv)
  96         y_mean.set_onnx_name_prefix('gpr')
  97         outputs = [y_mean]
  98 
  99         if options['return_cov']:
  100             raise NotImplementedError()
  101         if options['return_std']:
  102             if op._K_inv is None:
  103                 raise RuntimeError(
  104                     "The method *predict* must be called once with parameter "
  105                     "return_std=True to compute internal variables. "
  106                     "They cannot be computed here as the same operation "
  107                     "(matrix inversion) produces too many discrepencies "
  108                     "if done with single floats than double floats.")
  109             _K_inv = op._K_inv
  110 
  111             # y_var = self.kernel_.diag(X)
  112             y_var = convert_kernel_diag(kernel, X, dtype=dtype,
  113                                         optim=options.get('optim', None),
  114                                         op_version=opv)
  115 
  116             # y_var -= np.einsum("ij,ij->i",
  117             #       np.dot(K_trans, self._K_inv), K_trans)
  118             k_dot = OnnxMatMul(k_trans, _K_inv.astype(dtype), op_version=opv)
  119             ys_var = OnnxSub(
  120                 y_var, OnnxReduceSum(
  121                     OnnxMul(k_dot, k_trans, op_version=opv),
  122                     axes=[1], keepdims=0, op_version=opv),
  123                 op_version=opv)
  124 
  125             # y_var_negative = y_var < 0
  126             # if np.any(y_var_negative):
  127             #     y_var[y_var_negative] = 0.0
  128             ys0_var = OnnxMax(ys_var, np.array([0], dtype=dtype),
  129                               op_version=opv)
  130 
  131             # var = np.sqrt(ys0_var)
  132             var = OnnxSqrt(ys0_var, output_names=out[1:], op_version=opv)
  133             var.set_onnx_name_prefix('gprv')
  134             outputs.append(var)
  135 
  136     for o in outputs:
  137         o.add_to(scope, container)
  138 
  139 
  140 if OnnxConstantOfShape is not None:
  141     register_converter('SklearnGaussianProcessRegressor',
  142                        convert_gaussian_process_regressor,
  143                        options={'return_cov': [False, True],
  144                                 'return_std': [False, True],
  145                                 'optim': [None, 'cdist']})
  146
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/skl2onnx/operator_converters/gaussian_process.py b/skl2onnx/operator_converters/gaussian_process.py
  --- a/skl2onnx/operator_converters/gaussian_process.py
  +++ b/skl2onnx/operator_converters/gaussian_process.py
  @@ -90,9 +90,22 @@
           mean_y = op._y_train_mean.astype(dtype)
           if len(mean_y.shape) == 1:
               mean_y = mean_y.reshape(mean_y.shape + (1,))
  -        y_mean = OnnxAdd(y_mean_b, mean_y,
  -                         output_names=out[:1],
  -                         op_version=opv)
  +
  +        if not hasattr(op, '_y_train_std') or op._y_train_std == 1:
  +            y_mean = OnnxAdd(y_mean_b, mean_y, output_names=out[:1],
  +                             op_version=opv)
  +        else:
  +            # A bug was fixed in 0.23 and it changed
  +            # the predictions when return_std is True.
  +            # See https://github.com/scikit-learn/scikit-learn/pull/15782.
  +            # y_mean = self._y_train_std * y_mean + self._y_train_mean
  +            var_y = op._y_train_std.astype(dtype)
  +            if len(var_y.shape) == 1:
  +                var_y = var_y.reshape(var_y.shape + (1,))
  +            y_mean = OnnxAdd(
  +                OnnxMul(y_mean_b, var_y, op_version=opv),
  +                mean_y, output_names=out[:1], op_version=opv)
  +
           y_mean.set_onnx_name_prefix('gpr')
           outputs = [y_mean]
   
  @@ -128,6 +141,10 @@
               ys0_var = OnnxMax(ys_var, np.array([0], dtype=dtype),
                                 op_version=opv)
   
  +            if hasattr(op, '_y_train_std') and op._y_train_std != 1:
  +                # y_var = y_var * self._y_train_std**2
  +                ys0_var = OnnxMul(ys0_var, var_y ** 2, op_version=opv)
  +
               # var = np.sqrt(ys0_var)
               var = OnnxSqrt(ys0_var, output_names=out[1:], op_version=opv)
               var.set_onnx_name_prefix('gprv')
  
verification_info: {"golden_diff": "diff --git a/skl2onnx/operator_converters/gaussian_process.py b/skl2onnx/operator_converters/gaussian_process.py\n--- a/skl2onnx/operator_converters/gaussian_process.py\n+++ b/skl2onnx/operator_converters/gaussian_process.py\n@@ -90,9 +90,22 @@\n         mean_y = op._y_train_mean.astype(dtype)\n         if len(mean_y.shape) == 1:\n             mean_y = mean_y.reshape(mean_y.shape + (1,))\n-        y_mean = OnnxAdd(y_mean_b, mean_y,\n-                         output_names=out[:1],\n-                         op_version=opv)\n+\n+        if not hasattr(op, '_y_train_std') or op._y_train_std == 1:\n+            y_mean = OnnxAdd(y_mean_b, mean_y, output_names=out[:1],\n+                             op_version=opv)\n+        else:\n+            # A bug was fixed in 0.23 and it changed\n+            # the predictions when return_std is True.\n+            # See https://github.com/scikit-learn/scikit-learn/pull/15782.\n+            # y_mean = self._y_train_std * y_mean + self._y_train_mean\n+            var_y = op._y_train_std.astype(dtype)\n+            if len(var_y.shape) == 1:\n+                var_y = var_y.reshape(var_y.shape + (1,))\n+            y_mean = OnnxAdd(\n+                OnnxMul(y_mean_b, var_y, op_version=opv),\n+                mean_y, output_names=out[:1], op_version=opv)\n+\n         y_mean.set_onnx_name_prefix('gpr')\n         outputs = [y_mean]\n \n@@ -128,6 +141,10 @@\n             ys0_var = OnnxMax(ys_var, np.array([0], dtype=dtype),\n                               op_version=opv)\n \n+            if hasattr(op, '_y_train_std') and op._y_train_std != 1:\n+                # y_var = y_var * self._y_train_std**2\n+                ys0_var = OnnxMul(ys0_var, var_y ** 2, op_version=opv)\n+\n             # var = np.sqrt(ys0_var)\n             var = OnnxSqrt(ys0_var, output_names=out[1:], op_version=opv)\n             var.set_onnx_name_prefix('gprv')\n", "issue": "Fix discrepencies introduced by sciki-learn 0.23\n\n", "before_files": [{"content": "# -------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for\n# license information.\n# --------------------------------------------------------------------------\nimport numpy as np\nfrom sklearn.gaussian_process.kernels import ConstantKernel as C, RBF\nfrom ..common._registration import register_converter\nfrom ..algebra.onnx_ops import (\n    OnnxAdd, OnnxSqrt, OnnxMatMul, OnnxSub, OnnxReduceSum,\n    OnnxMul, OnnxMax\n)\ntry:\n    from ..algebra.onnx_ops import OnnxConstantOfShape\nexcept ImportError:\n    OnnxConstantOfShape = None\n\nfrom ._gp_kernels import (\n    convert_kernel_diag,\n    convert_kernel,\n    _zero_vector_of_size\n)\n\n\ndef convert_gaussian_process_regressor(scope, operator, container):\n    \"\"\"\n    The method *predict* from class *GaussianProcessRegressor*\n    may cache some results if it is called with parameter\n    ``return_std=True`` or ``return_cov=True``. This converter\n    needs to be called with theses options to enable\n    the second results.\n    See example :ref:`l-gpr-example` to see how to\n    use this converter which does not behave exactly\n    as the others.\n    \"\"\"\n    dtype = container.dtype\n    if dtype is None:\n        raise RuntimeError(\"dtype cannot be None\")\n    X = operator.inputs[0]\n    out = operator.outputs\n    op = operator.raw_operator\n    opv = container.target_opset\n    if opv is None:\n        raise RuntimeError(\"container.target_opset must not be None\")\n\n    options = container.get_options(op, dict(return_cov=False,\n                                             return_std=False,\n                                             optim=None))\n    if hasattr(op, 'kernel_') and op.kernel_ is not None:\n        kernel = op.kernel_\n    elif op.kernel is None:\n        kernel = (C(1.0, constant_value_bounds=\"fixed\") *\n                  RBF(1.0, length_scale_bounds=\"fixed\"))\n    else:\n        kernel = op.kernel\n\n    if not hasattr(op, \"X_train_\") or op.X_train_ is None:\n        out0 = _zero_vector_of_size(X, keepdims=1, output_names=out[:1],\n                                    dtype=dtype)\n\n        outputs = [out0]\n        if options['return_cov']:\n            outputs.append(convert_kernel(kernel, X,\n                                          output_names=out[1:],\n                                          dtype=dtype,\n                                          op_version=opv))\n        if options['return_std']:\n            outputs.append(\n                OnnxSqrt(\n                    convert_kernel_diag(\n                        kernel, X, dtype=dtype, op_version=opv),\n                    output_names=out[1:], op_version=opv))\n    else:\n        out0 = _zero_vector_of_size(\n            X, keepdims=1, dtype=dtype, op_version=opv)\n\n        # Code scikit-learn\n        # K_trans = self.kernel_(X, self.X_train_)\n        # y_mean = K_trans.dot(self.alpha_)  # Line 4 (y_mean = f_star)\n        # y_mean = self._y_train_mean + y_mean  # undo normal.\n\n        k_trans = convert_kernel(kernel, X,\n                                 x_train=op.X_train_.astype(dtype),\n                                 dtype=dtype,\n                                 optim=options.get('optim', None),\n                                 op_version=opv)\n        k_trans.set_onnx_name_prefix('kgpd')\n        y_mean_b = OnnxMatMul(k_trans, op.alpha_.astype(dtype), op_version=opv)\n\n        mean_y = op._y_train_mean.astype(dtype)\n        if len(mean_y.shape) == 1:\n            mean_y = mean_y.reshape(mean_y.shape + (1,))\n        y_mean = OnnxAdd(y_mean_b, mean_y,\n                         output_names=out[:1],\n                         op_version=opv)\n        y_mean.set_onnx_name_prefix('gpr')\n        outputs = [y_mean]\n\n        if options['return_cov']:\n            raise NotImplementedError()\n        if options['return_std']:\n            if op._K_inv is None:\n                raise RuntimeError(\n                    \"The method *predict* must be called once with parameter \"\n                    \"return_std=True to compute internal variables. \"\n                    \"They cannot be computed here as the same operation \"\n                    \"(matrix inversion) produces too many discrepencies \"\n                    \"if done with single floats than double floats.\")\n            _K_inv = op._K_inv\n\n            # y_var = self.kernel_.diag(X)\n            y_var = convert_kernel_diag(kernel, X, dtype=dtype,\n                                        optim=options.get('optim', None),\n                                        op_version=opv)\n\n            # y_var -= np.einsum(\"ij,ij->i\",\n            #       np.dot(K_trans, self._K_inv), K_trans)\n            k_dot = OnnxMatMul(k_trans, _K_inv.astype(dtype), op_version=opv)\n            ys_var = OnnxSub(\n                y_var, OnnxReduceSum(\n                    OnnxMul(k_dot, k_trans, op_version=opv),\n                    axes=[1], keepdims=0, op_version=opv),\n                op_version=opv)\n\n            # y_var_negative = y_var < 0\n            # if np.any(y_var_negative):\n            #     y_var[y_var_negative] = 0.0\n            ys0_var = OnnxMax(ys_var, np.array([0], dtype=dtype),\n                              op_version=opv)\n\n            # var = np.sqrt(ys0_var)\n            var = OnnxSqrt(ys0_var, output_names=out[1:], op_version=opv)\n            var.set_onnx_name_prefix('gprv')\n            outputs.append(var)\n\n    for o in outputs:\n        o.add_to(scope, container)\n\n\nif OnnxConstantOfShape is not None:\n    register_converter('SklearnGaussianProcessRegressor',\n                       convert_gaussian_process_regressor,\n                       options={'return_cov': [False, True],\n                                'return_std': [False, True],\n                                'optim': [None, 'cdist']})\n", "path": "skl2onnx/operator_converters/gaussian_process.py"}], "after_files": [{"content": "# -------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for\n# license information.\n# --------------------------------------------------------------------------\nimport numpy as np\nfrom sklearn.gaussian_process.kernels import ConstantKernel as C, RBF\nfrom ..common._registration import register_converter\nfrom ..algebra.onnx_ops import (\n    OnnxAdd, OnnxSqrt, OnnxMatMul, OnnxSub, OnnxReduceSum,\n    OnnxMul, OnnxMax\n)\ntry:\n    from ..algebra.onnx_ops import OnnxConstantOfShape\nexcept ImportError:\n    OnnxConstantOfShape = None\n\nfrom ._gp_kernels import (\n    convert_kernel_diag,\n    convert_kernel,\n    _zero_vector_of_size\n)\n\n\ndef convert_gaussian_process_regressor(scope, operator, container):\n    \"\"\"\n    The method *predict* from class *GaussianProcessRegressor*\n    may cache some results if it is called with parameter\n    ``return_std=True`` or ``return_cov=True``. This converter\n    needs to be called with theses options to enable\n    the second results.\n    See example :ref:`l-gpr-example` to see how to\n    use this converter which does not behave exactly\n    as the others.\n    \"\"\"\n    dtype = container.dtype\n    if dtype is None:\n        raise RuntimeError(\"dtype cannot be None\")\n    X = operator.inputs[0]\n    out = operator.outputs\n    op = operator.raw_operator\n    opv = container.target_opset\n    if opv is None:\n        raise RuntimeError(\"container.target_opset must not be None\")\n\n    options = container.get_options(op, dict(return_cov=False,\n                                             return_std=False,\n                                             optim=None))\n    if hasattr(op, 'kernel_') and op.kernel_ is not None:\n        kernel = op.kernel_\n    elif op.kernel is None:\n        kernel = (C(1.0, constant_value_bounds=\"fixed\") *\n                  RBF(1.0, length_scale_bounds=\"fixed\"))\n    else:\n        kernel = op.kernel\n\n    if not hasattr(op, \"X_train_\") or op.X_train_ is None:\n        out0 = _zero_vector_of_size(X, keepdims=1, output_names=out[:1],\n                                    dtype=dtype)\n\n        outputs = [out0]\n        if options['return_cov']:\n            outputs.append(convert_kernel(kernel, X,\n                                          output_names=out[1:],\n                                          dtype=dtype,\n                                          op_version=opv))\n        if options['return_std']:\n            outputs.append(\n                OnnxSqrt(\n                    convert_kernel_diag(\n                        kernel, X, dtype=dtype, op_version=opv),\n                    output_names=out[1:], op_version=opv))\n    else:\n        out0 = _zero_vector_of_size(\n            X, keepdims=1, dtype=dtype, op_version=opv)\n\n        # Code scikit-learn\n        # K_trans = self.kernel_(X, self.X_train_)\n        # y_mean = K_trans.dot(self.alpha_)  # Line 4 (y_mean = f_star)\n        # y_mean = self._y_train_mean + y_mean  # undo normal.\n\n        k_trans = convert_kernel(kernel, X,\n                                 x_train=op.X_train_.astype(dtype),\n                                 dtype=dtype,\n                                 optim=options.get('optim', None),\n                                 op_version=opv)\n        k_trans.set_onnx_name_prefix('kgpd')\n        y_mean_b = OnnxMatMul(k_trans, op.alpha_.astype(dtype), op_version=opv)\n\n        mean_y = op._y_train_mean.astype(dtype)\n        if len(mean_y.shape) == 1:\n            mean_y = mean_y.reshape(mean_y.shape + (1,))\n\n        if not hasattr(op, '_y_train_std') or op._y_train_std == 1:\n            y_mean = OnnxAdd(y_mean_b, mean_y, output_names=out[:1],\n                             op_version=opv)\n        else:\n            # A bug was fixed in 0.23 and it changed\n            # the predictions when return_std is True.\n            # See https://github.com/scikit-learn/scikit-learn/pull/15782.\n            # y_mean = self._y_train_std * y_mean + self._y_train_mean\n            var_y = op._y_train_std.astype(dtype)\n            if len(var_y.shape) == 1:\n                var_y = var_y.reshape(var_y.shape + (1,))\n            y_mean = OnnxAdd(\n                OnnxMul(y_mean_b, var_y, op_version=opv),\n                mean_y, output_names=out[:1], op_version=opv)\n\n        y_mean.set_onnx_name_prefix('gpr')\n        outputs = [y_mean]\n\n        if options['return_cov']:\n            raise NotImplementedError()\n        if options['return_std']:\n            if op._K_inv is None:\n                raise RuntimeError(\n                    \"The method *predict* must be called once with parameter \"\n                    \"return_std=True to compute internal variables. \"\n                    \"They cannot be computed here as the same operation \"\n                    \"(matrix inversion) produces too many discrepencies \"\n                    \"if done with single floats than double floats.\")\n            _K_inv = op._K_inv\n\n            # y_var = self.kernel_.diag(X)\n            y_var = convert_kernel_diag(kernel, X, dtype=dtype,\n                                        optim=options.get('optim', None),\n                                        op_version=opv)\n\n            # y_var -= np.einsum(\"ij,ij->i\",\n            #       np.dot(K_trans, self._K_inv), K_trans)\n            k_dot = OnnxMatMul(k_trans, _K_inv.astype(dtype), op_version=opv)\n            ys_var = OnnxSub(\n                y_var, OnnxReduceSum(\n                    OnnxMul(k_dot, k_trans, op_version=opv),\n                    axes=[1], keepdims=0, op_version=opv),\n                op_version=opv)\n\n            # y_var_negative = y_var < 0\n            # if np.any(y_var_negative):\n            #     y_var[y_var_negative] = 0.0\n            ys0_var = OnnxMax(ys_var, np.array([0], dtype=dtype),\n                              op_version=opv)\n\n            if hasattr(op, '_y_train_std') and op._y_train_std != 1:\n                # y_var = y_var * self._y_train_std**2\n                ys0_var = OnnxMul(ys0_var, var_y ** 2, op_version=opv)\n\n            # var = np.sqrt(ys0_var)\n            var = OnnxSqrt(ys0_var, output_names=out[1:], op_version=opv)\n            var.set_onnx_name_prefix('gprv')\n            outputs.append(var)\n\n    for o in outputs:\n        o.add_to(scope, container)\n\n\nif OnnxConstantOfShape is not None:\n    register_converter('SklearnGaussianProcessRegressor',\n                       convert_gaussian_process_regressor,\n                       options={'return_cov': [False, True],\n                                'return_std': [False, True],\n                                'optim': [None, 'cdist']})\n", "path": "skl2onnx/operator_converters/gaussian_process.py"}]}