code: def test__encode_input_data():
      encoded_msg = ComputationModel._encode_input_data(
          None, is_src=True
      )
      assert encoded_msg == [-1] * 512
  
      encoded_msg = ComputationModel._encode_input_data(
          12.0, is_src=True
      )
      assert encoded_msg == [1] + [-1] * 511
  
      encoded_msg = ComputationModel._encode_input_data(
          "abc", is_src=True
      )
      assert encoded_msg == [2] + [-1] * 511
  
      t = torch.rand(2, 512, 32, 32, 64)
      encoded_msg = ComputationModel._encode_input_data(t, is_src=True)
      dtype_str = str(t.dtype)
      true_msg = [
          0,
          5,
          2,
          512,
          32,
          32,
          64,
          len(dtype_str),
          *list(bytearray(dtype_str, "utf-8")),
      ]
      assert encoded_msg == true_msg + [-1] * (512 - len(true_msg))
  
      t = torch.randint(-1235, 1233, size=(2, 512, 32, 32, 64))
      encoded_msg = ComputationModel._encode_input_data(t, is_src=True)
      dtype_str = str(t.dtype)
      true_msg = [
          0,
          5,
          2,
          512,
          32,
          32,
          64,
          len(dtype_str),
          *list(bytearray(dtype_str, "utf-8")),
      ]
      assert encoded_msg == true_msg + [-1] * (512 - len(true_msg))
  
      t = torch.tensor(12)
      encoded_msg = ComputationModel._encode_input_data(t, is_src=True)
      dtype_str = str(t.dtype)
      true_msg = [
          0,
          0,
          len(dtype_str),
          *list(bytearray(dtype_str, "utf-8")),
      ]
      assert encoded_msg == true_msg + [-1] * (512 - len(true_msg))
  
      for t in [
          None,
          "abc",
          torch.rand(2, 512, 32, 32, 64),
          12.34,
          object(),
      ]:
          encoded_msg = ComputationModel._encode_input_data(
              t, is_src=False
          )
          assert encoded_msg == [-1] * 512
  
file_path: ignite/tests/ignite/distributed/comp_models/test_base.py
imports: import pytest
  import torch
  from ignite.distributed.comp_models.base import _SerialModel, _torch_version_le_112, ComputationModel
label_desc: Use image node_id 3 for calling a global function with example usage: test__encode_input_data() without return types