code: def test_pcc():
      labels, preds = cm_batch(
          [
              [7, 3],
              [2, 5],
          ]
      )
      met_pcc = mx.gluon.metric.create("pcc")
      met_pcc.update(labels, preds)
      _, pcc = met_pcc.get()
  
      # pcc should agree with mcc for binary classification
      met_mcc = mx.gluon.metric.create("mcc")
      met_mcc.update(labels, preds)
      _, mcc = met_mcc.get()
      np.testing.assert_almost_equal(pcc, mcc)
  
      # pcc should agree with Pearson for binary classification
      met_pear = mx.gluon.metric.create("pearsonr")
      met_pear.update(labels, [p.argmax(axis=1) for p in preds])
      _, pear = met_pear.get()
      np.testing.assert_almost_equal(pcc, pear)
  
      # pcc should also accept pred as scalar rather than softmax vector
      # like acc does
      met_pcc.reset()
      met_pcc.update(labels, [p.argmax(axis=1) for p in preds])
      _, chk = met_pcc.get()
      np.testing.assert_almost_equal(pcc, chk)
  
      # check multiclass case against reference implementation
      CM = [
          [23, 13, 3],
          [7, 19, 11],
          [2, 5, 17],
      ]
      K = 3
      ref = (
          sum(
              CM[k][k] * CM[l][m] - CM[k][l] * CM[m][k]
              for k in range(K)
              for l in range(K)
              for m in range(K)
          )
          / (
              sum(
                  sum(CM[k][l] for l in range(K))
                  * sum(
                      sum(CM[f][g] for g in range(K))
                      for f in range(K)
                      if f != k
                  )
                  for k in range(K)
              )
              * sum(
                  sum(CM[l][k] for l in range(K))
                  * sum(
                      sum(CM[f][g] for f in range(K))
                      for g in range(K)
                      if g != k
                  )
                  for k in range(K)
              )
          )
          ** 0.5
      )
      labels, preds = cm_batch(CM)
      met_pcc.reset()
      met_pcc.update(labels, preds)
      _, pcc = met_pcc.get()
      np.testing.assert_almost_equal(pcc, ref)
  
      # things that should not change metric score:
      # * order
      # * batch size
      # * update frequency
      labels = [[i.reshape(-1)] for i in labels[0]]
      labels.reverse()
      preds = [[i.reshape((1, -1))] for i in preds[0]]
      preds.reverse()
  
      met_pcc.reset()
      for l, p in zip(labels, preds):
          met_pcc.update(l, p)
      assert pcc == met_pcc.get()[1]
  
imports: import mxnet
  from mxnet.test_utils import use_np
  import numpy
  import scipy
  from scipy.stats import pearsonr
  import json
  import math
  from common import xfail_when_nonstandard_decimal_separator
  from copy import deepcopy
label_desc: Use image node_id 14 for calling a global function with example usage: test_pcc() without return types