code: def test_mahalanobis():
      global a, b, S
      # int test
      a, b, S = 3, 1, 2
      assert (
          abs(mahalanobis(a, b, S) - scipy_mahalanobis(a, b, 1 / S))
          < 1.0e-12
      )
  
      # int list
      assert (
          abs(
              mahalanobis([a], [b], [S])
              - scipy_mahalanobis(a, b, 1 / S)
          )
          < 1.0e-12
      )
      assert (
          abs(mahalanobis([a], b, S) - scipy_mahalanobis(a, b, 1 / S))
          < 1.0e-12
      )
  
      # float
      a, b, S = 3.123, 3.235235, 0.01234
      assert (
          abs(mahalanobis(a, b, S) - scipy_mahalanobis(a, b, 1 / S))
          < 1.0e-12
      )
      assert (
          abs(
              mahalanobis([a], [b], [S])
              - scipy_mahalanobis(a, b, 1 / S)
          )
          < 1.0e-12
      )
      assert (
          abs(mahalanobis([a], b, S) - scipy_mahalanobis(a, b, 1 / S))
          < 1.0e-12
      )
  
      # float array
      assert (
          abs(
              mahalanobis(np.array([a]), b, S)
              - scipy_mahalanobis(a, b, 1 / S)
          )
          < 1.0e-12
      )
  
      # 1d array
      a = np.array([1.0, 2.0])
      b = np.array([1.4, 1.2])
      S = np.array([[1.0, 2.0], [2.0, 4.001]])
  
      assert (
          abs(mahalanobis(a, b, S) - scipy_mahalanobis(a, b, inv(S)))
          < 1.0e-12
      )
  
      # 2d array
      a = np.array([[1.0, 2.0]])
      b = np.array([[1.4, 1.2]])
      S = np.array([[1.0, 2.0], [2.0, 4.001]])
  
      assert (
          abs(mahalanobis(a, b, S) - scipy_mahalanobis(a, b, inv(S)))
          < 1.0e-12
      )
      assert (
          abs(mahalanobis(a.T, b, S) - scipy_mahalanobis(a, b, inv(S)))
          < 1.0e-12
      )
      assert (
          abs(mahalanobis(a, b.T, S) - scipy_mahalanobis(a, b, inv(S)))
          < 1.0e-12
      )
      assert (
          abs(
              mahalanobis(a.T, b.T, S) - scipy_mahalanobis(a, b, inv(S))
          )
          < 1.0e-12
      )
  
      try:
          # mismatched shapes
          mahalanobis([1], b, S)
          assert "didn't catch vectors of different lengths"
      except ValueError:
          pass
      except:
          assert "raised exception other than ValueError"
  
      # okay, now check for numerical accuracy
      for _ in range(ITERS):
          N = np.random.randint(1, 20)
          a = np.random.randn(N)
          b = np.random.randn(N)
          S = np.random.randn(N, N)
          S = np.dot(S, S.T)  # ensure positive semi-definite
          assert (
              abs(
                  mahalanobis(a, b, S) - scipy_mahalanobis(a, b, inv(S))
              )
              < 1.0e-12
          )
  
imports: from __future__ import division
  from math import exp
  import warnings
  import matplotlib.pyplot
  from mpl_toolkits.mplot3d import axes3d
  import numpy
  from numpy.linalg import inv
  import scipy
  from scipy.spatial.distance import mahalanobis
  from filterpy.stats import norm_cdf, multivariate_gaussian, logpdf, mahalanobis
  from scipy import linalg
label_desc: Use image node_id 2 for calling a global function with example usage: test_mahalanobis() without return types