code: def test_mnist_autoencoder(latent_dim):
      """Tests whether the latent representation is in [-1, 1] and has the
      expected shape, and the composition of the encoder and decoder modules.
      """
      x = torch.randn(1, 1, 28, 28)
      enc = MNISTEncoder(latent_dim=latent_dim)
      dec = MNISTDecoder(latent_dim=latent_dim)
      ae = AE(encoder=enc, decoder=dec)
  
      z = enc(x)
      assert z.shape[-1] == latent_dim
      assert torch.all((z >= -1) & (z <= 1))
  
      x_hat1 = dec(z)
      assert x.shape == x_hat1.shape
  
      x_hat2 = ae(x)
      assert x.shape == x_hat2.shape
      assert torch.allclose(x_hat1, x_hat2)
  
file_path: alibi/alibi/models/pytorch/tests/test_cfrl_models.py
imports: import pytest
  import torch
  from alibi.models.pytorch import AE, HeAE
  from alibi.models.pytorch.cfrl_models import ADULTDecoder, ADULTEncoder, MNISTClassifier, MNISTDecoder, MNISTEncoder
label_desc: Use image node_id 2 for calling a global function with example usage: test_mnist_autoencoder(latent_dim) without return types