code: def test_serialization(X):
      d = Categorical().fit(X[:4])
      d.summarize(X[4:])
  
      p = [
          [0.0, 0.5, 0.25, 0.25],
          [0.25, 0.25, 0.5, 0.0],
          [0.25, 0.25, 0.5, 0.0],
      ]
  
      assert_array_almost_equal(d.probs, p)
      assert_array_almost_equal(d._log_probs, numpy.log(p))
  
      torch.save(d, ".pytest.torch")
      d2 = torch.load(".pytest.torch")
      os.system("rm .pytest.torch")
  
      assert_array_almost_equal(d2.probs, p)
      assert_array_almost_equal(d2._log_probs, numpy.log(p))
  
      assert_array_almost_equal(d2._w_sum, [3.0, 3.0, 3.0])
      assert_array_almost_equal(
          d2._xw_sum,
          [
              [1.0, 1.0, 1.0, 0.0],
              [0.0, 3.0, 0.0, 0.0],
              [2.0, 0.0, 1.0, 0.0],
          ],
      )
      assert_array_almost_equal(
          d.log_probability(X), d2.log_probability(X)
      )
  
imports: import os
  import numpy
  import torch
  import pytest
  from pomegranate.distributions import Categorical
  from ._utils import _test_initialization_raises_one_parameter
  from ._utils import _test_predictions
  from ._utils import _test_raises
  from nose.tools import assert_raises
  from numpy.testing import assert_array_almost_equal
label_desc: Use image node_id 39 for calling a global function with example usage: test_serialization(X) without return types