class_docstr: This class tests all functions of CUDALongTensor as well as its integration with MPCTensor.
class_docstr_tok: ["This","class","tests","all","functions","of","CUDALongTensor","as","well","as","its","integration","with","MPCTensor","."]
docstr: Test convolution of torch.cuda.LongTensor with cuda_patches technique.
code: def _patched_conv2d(self, image_size, in_channels):
      """Test convolution of torch.cuda.LongTensor with cuda_patches technique."""
      kwargs = collections.OrderedDict()
      kwargs["nbatches"] = [1, 3]
      kwargs["kernel_sizes"] = [(1, 1), (2, 2), (2, 3)]
      kwargs["ochannels"] = [1, 3, 6]
      kwargs["paddings"] = [0, 1, (0, 1)]
      kwargs["strides"] = [1, 2, (1, 2)]
  
      for attribute in [
          "nbatches",
          "ochannels",
          "paddings",
          "strides",
          "kernel_sizes",
      ]:
          if hasattr(self, attribute):
              kwargs[attribute] = getattr(self, attribute)
  
      for func_name in ["conv2d", "conv_transpose2d"]:
          for (
              batches,
              kernel_size,
              out_channels,
              padding,
              stride,
          ) in itertools.product(*[v for _, v in kwargs.items()]):
              # sample input:
              input_size = (batches, in_channels, *image_size)
              input = get_random_test_tensor(
                  size=input_size, is_float=False
              )
  
              # sample filtering kernel:
              if func_name == "conv2d":
                  k_size = (out_channels, in_channels, *kernel_size)
              else:
                  k_size = (in_channels, out_channels, *kernel_size)
              kernel = get_random_test_tensor(
                  size=k_size, is_float=False
              )
  
              input_cuda = CUDALongTensor(input)
              kernel_cuda = CUDALongTensor(kernel)
  
              result = getattr(F, func_name)(
                  input_cuda,
                  kernel_cuda,
                  padding=padding,
                  stride=stride,
              )
              self.assertTrue(
                  type(result) == CUDALongTensor,
                  "result should be a CUDALongTensor",
              )
              result = result.data.cpu()
  
              # check that result is correct:
              reference = getattr(F, func_name)(
                  input, kernel, padding=padding, stride=stride
              )
              self._check_int(
                  result, reference, "%s failed" % func_name
              )
  
imports: import collections
  import itertools
  import logging
  import unittest
  import crypten
  import torch
  import torch.nn
  import torch.nn.functional
  from crypten.config import cfg
  from crypten.cuda import CUDALongTensor
  from test.multiprocess_test_case import get_random_test_tensor, MultiProcessTestCase
  from test.test_mpc import TestMPC
label_desc: Use image node_id 15 for calling the TestCUDA obj's underlying member method code with example usage: obj._patched_conv2d(image_size, in_channels) without return types