code: def _test_masks(
      self,
      input_dim,
      observed_dim,
      hidden_dims,
      permutation,
      output_dim_multiplier,
  ):
      masks, mask_skip = create_mask(
          input_dim,
          observed_dim,
          hidden_dims,
          permutation,
          output_dim_multiplier,
      )
  
      # First test that hidden layer masks are adequately connected
      # Tracing backwards, works out what inputs each output is connected to
      # It's a dictionary of sets indexed by a tuple (input_dim, param_dim)
      permutation = list(permutation.numpy())
  
      # Loop over variables
      for idx in range(input_dim):
          # Calculate correct answer
          correct = torch.cat(
              (
                  torch.arange(observed_dim, dtype=torch.long),
                  torch.tensor(
                      sorted(permutation[0 : permutation.index(idx)]),
                      dtype=torch.long,
                  )
                  + observed_dim,
              )
          )
  
          # Loop over parameters for each variable
          for jdx in range(output_dim_multiplier):
              prev_connections = set()
              # Do output-to-penultimate hidden layer mask
              for kdx in range(masks[-1].size(1)):
                  if masks[-1][idx + jdx * input_dim, kdx]:
                      prev_connections.add(kdx)
  
              # Do hidden-to-hidden, and hidden-to-input layer masks
              for m in reversed(masks[:-1]):
                  this_connections = set()
                  for kdx in prev_connections:
                      for ldx in range(m.size(1)):
                          if m[kdx, ldx]:
                              this_connections.add(ldx)
                  prev_connections = this_connections
  
              assert (
                  torch.tensor(
                      list(sorted(prev_connections)), dtype=torch.long
                  )
                  == correct
              ).all()
  
              # Test the skip-connections mask
              skip_connections = set()
              for kdx in range(mask_skip.size(1)):
                  if mask_skip[idx + jdx * input_dim, kdx]:
                      skip_connections.add(kdx)
              assert (
                  torch.tensor(
                      list(sorted(skip_connections)), dtype=torch.long
                  )
                  == correct
              ).all()
  
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 3 for calling the AutoRegressiveNNTests obj's underlying member method code with example usage: obj._test_masks(input_dim, observed_dim, hidden_dims, permutation, output_dim_multiplier) without return types