code: def _compare_jacobians(self, j_fwd, j_rev, j_rule, primitive):
      if primitive == lax.convert_element_type_p:
          # Check that only one of fwd/red Jacobians matches the rule.
          e_fwd, e_rev = None, None
          try:
              self.assertAllClose(j_fwd, j_rule)
          except Exception as e:
              logging.exception(
                  "Forward-mode Jacobian does not match the rule."
              )
              e_fwd = e
  
          try:
              self.assertAllClose(j_rev, j_rule)
          except Exception as e:
              logging.exception(
                  "Reverse-mode Jacobian does not match the rule."
              )
              e_rev = e
  
          if e_fwd is not None and e_rev is not None:
              raise ValueError(e_fwd, e_rev)
  
      else:
          if primitive == lax.reshape_p:
              # Reshape Jacobian is special-case defined as identity.
              j_rule: jnp.ndarray
              j_rule = j_rule.reshape(j_fwd.shape)
  
          self.assertAllClose(j_fwd, j_rev)
          if j_rule is not None:
              self.assertAllClose(j_fwd, j_rule)
              self.assertAllClose(j_rev, j_rule)
  
imports: import itertools
  import logging
  import random
  from typing import Optional, Sequence
  import warnings
  from absl.testing import absltest
  import jax
  from jax import lax
  from jax import config
  from jax.core import Primitive
  from jax.core import ShapedArray
  from jax.interpreters import ad
  import jax.numpy
  import more_itertools
  from neural_tangents._src.utils import rules
  from tests import test_utils
  import numpy
label_desc: Use image node_id 3 for calling the JacobianRulesTest obj's underlying member method code with example usage: obj._compare_jacobians(j_fwd, j_rev, j_rule, primitive) without return types