class_docstr: This class tests the crypten.nn package.
class_docstr_tok: ["This","class","tests","the","crypten.nn","package","."]
docstr: Tests the __getattr__ and __setattr__ functions
code: def test_getattr_setattr(self):
      """Tests the __getattr__ and __setattr__ functions"""
  
      tensor1 = get_random_test_tensor(size=(3, 3), is_float=True)
      tensor2 = get_random_test_tensor(size=(3, 3), is_float=True)
  
      class ExampleNet(crypten.nn.Module):
          def __init__(self):
              super(ExampleNet, self).__init__()
              self.fc1 = crypten.nn.Linear(20, 1)
              sample_buffer = tensor1
              self.register_buffer("sample_buffer", sample_buffer)
              sample_param = tensor2
              self.register_parameter("sample_param", sample_param)
  
          def forward(self, x):
              out = self.fc1(x)
              return out
  
      model = ExampleNet()
      model.encrypt()
  
      self.assertTrue(
          "fc1" in model._modules.keys(), "modules __setattr__ failed"
      )
      self._check(
          model.sample_buffer, tensor1, "buffer __getattr__ failed"
      )
      self._check(
          model.sample_param, tensor2, "parameter __getattr__ failed"
      )
      self.assertTrue(
          isinstance(model.fc1, crypten.nn.Linear),
          "modules __getattr__ failed",
      )
  
      """
          assign to model.weight should change model._parameters["weight"]
          """
      model.fc1.weight = torch.nn.Parameter(torch.zeros((2, 3)))
  
      self.assertEqual(
          model.fc1._parameters["weight"].tolist(),
          torch.nn.Parameter(torch.zeros((2, 3))).tolist(),
      )
  
      """
          assign to  model._parameters["weight"] should change model.weight
          """
      model.fc1._parameters["weight"] = torch.nn.Parameter(
          torch.ones((2, 3))
      )
      self.assertEqual(
          model.fc1.weight.tolist(),
          torch.nn.Parameter(torch.ones((2, 3))).tolist(),
      )
  
      """
          assign to  model._buffers["bufferedItem"] should change model.bufferedItem
          """
      model.fc1._buffers["bufferedItem"] = torch.nn.Parameter(
          torch.ones((2, 3))
      )
      self.assertEqual(
          model.fc1.bufferedItem.tolist(),
          torch.nn.Parameter(torch.ones((2, 3))).tolist(),
      )
  
      """
          assign to model.weight should change model._parameters["weight"]
          """
      model.fc1.bufferedItem = torch.nn.Parameter(torch.zeros((2, 3)))
  
      self.assertEqual(
          model.fc1._buffers["bufferedItem"].tolist(),
          torch.nn.Parameter(torch.zeros((2, 3))).tolist(),
      )
  
imports: import copy
  import itertools
  import logging
  import unittest
  import crypten
  import crypten.communicator
  import torch
  import torch.nn.functional
  from crypten.common.rng import generate_random_ring_element
  from crypten.common.tensor_types import is_float_tensor
  from crypten.config import cfg
  from crypten.encoder import FixedPointEncoder
  from test.multiprocess_test_case import get_random_linear, get_random_test_tensor, MultiProcessTestCase, onehot
label_desc: Use image node_id 18 for calling the TestNN obj's underlying member method code with example usage: obj.test_getattr_setattr() and returns: out