class_docstr: Check that solve/dot methods in Jacobian approximations are consistent
class_docstr_tok: ["Check","that","solve\/dot","methods","in","Jacobian","approximations","are","consistent"]
code: def _check_dot(self, jac_cls, complex=False, tol=1e-6, **kw):
      np.random.seed(123)
  
      N = 7
  
      def rand(*a):
          q = np.random.rand(*a)
          if complex:
              q = q + 1j * np.random.rand(*a)
          return q
  
      def assert_close(a, b, msg):
          d = abs(a - b).max()
          f = tol + abs(b).max() * tol
          if d > f:
              raise AssertionError("%s: err %g" % (msg, d))
  
      self.A = rand(N, N)
  
      # initialize
      x0 = np.random.rand(N)
      jac = jac_cls(**kw)
      jac.setup(x0, self._func(x0), self._func)
  
      # check consistency
      for k in xrange(2 * N):
          v = rand(N)
  
          if hasattr(jac, "__array__"):
              Jd = np.array(jac)
              if hasattr(jac, "solve"):
                  Gv = jac.solve(v)
                  Gv2 = np.linalg.solve(Jd, v)
                  assert_close(Gv, Gv2, "solve vs array")
              if hasattr(jac, "rsolve"):
                  Gv = jac.rsolve(v)
                  Gv2 = np.linalg.solve(Jd.T.conj(), v)
                  assert_close(Gv, Gv2, "rsolve vs array")
              if hasattr(jac, "matvec"):
                  Jv = jac.matvec(v)
                  Jv2 = np.dot(Jd, v)
                  assert_close(Jv, Jv2, "dot vs array")
              if hasattr(jac, "rmatvec"):
                  Jv = jac.rmatvec(v)
                  Jv2 = np.dot(Jd.T.conj(), v)
                  assert_close(Jv, Jv2, "rmatvec vs array")
  
          if hasattr(jac, "matvec") and hasattr(jac, "solve"):
              Jv = jac.matvec(v)
              Jv2 = jac.solve(jac.matvec(Jv))
              assert_close(Jv, Jv2, "dot vs solve")
  
          if hasattr(jac, "rmatvec") and hasattr(jac, "rsolve"):
              Jv = jac.rmatvec(v)
              Jv2 = jac.rmatvec(jac.rsolve(Jv))
              assert_close(Jv, Jv2, "rmatvec vs rsolve")
  
          x = rand(N)
          jac.update(x, self._func(x))
  
imports: from __future__ import division, print_function, absolute_import
  from numpy.testing import assert_
  import pytest
  from scipy._lib.six import xrange
  from scipy.optimize import nonlin, root
  from numpy import diag, dot
  from numpy.linalg import inv
  import numpy
  from .test_minpack import pressure_network
label_desc: Use image node_id 2 for calling the TestJacobianDotSolve obj's underlying member method code with example usage: obj._check_dot(jac_cls, complex, tol) and returns: q