code: def _test_jacobian(
      self, input_dim, observed_dim, hidden_dim, param_dim
  ):
      jacobian = torch.zeros(input_dim, input_dim)
      if observed_dim > 0:
          arn = ConditionalAutoRegressiveNN(
              input_dim,
              observed_dim,
              [hidden_dim],
              param_dims=[param_dim],
          )
      else:
          arn = AutoRegressiveNN(
              input_dim, [hidden_dim], param_dims=[param_dim]
          )
  
      def nonzero(x):
          return torch.sign(torch.abs(x))
  
      x = torch.randn(1, input_dim)
      y = torch.randn(1, observed_dim)
  
      for output_index in range(param_dim):
          for j in range(input_dim):
              for k in range(input_dim):
                  epsilon_vector = torch.zeros(1, input_dim)
                  epsilon_vector[0, j] = self.epsilon
                  if observed_dim > 0:
                      delta = (
                          arn(x + 0.5 * epsilon_vector, y)
                          - arn(x - 0.5 * epsilon_vector, y)
                      ) / self.epsilon
                  else:
                      delta = (
                          arn(x + 0.5 * epsilon_vector)
                          - arn(x - 0.5 * epsilon_vector)
                      ) / self.epsilon
                  jacobian[j, k] = float(delta[0, output_index, k])
  
          permutation = arn.get_permutation()
          permuted_jacobian = jacobian.clone()
          for j in range(input_dim):
              for k in range(input_dim):
                  permuted_jacobian[j, k] = jacobian[
                      permutation[j], permutation[k]
                  ]
  
          lower_sum = torch.sum(
              torch.tril(nonzero(permuted_jacobian), diagonal=0)
          )
  
          assert lower_sum == float(0.0)
  
file_path: pyro/tests/nn/test_autoregressive.py
imports: from unittest import TestCase
  import pytest
  import torch
  from pyro.nn import AutoRegressiveNN, ConditionalAutoRegressiveNN
  from pyro.nn.auto_reg_nn import create_mask
label_desc: Use image node_id 2 for calling the AutoRegressiveNNTests obj's underlying member method code with example usage: obj._test_jacobian(input_dim, observed_dim, hidden_dim, param_dim) and returns: torch