code: def test_cuda_precise_backwards(
      self, test_case_description, sigmas, input, guide, expected
  ):
      # Params to determine the implementation to test
      device = torch.device("cuda")
  
      # Prepare input tensor
      input_tensor = torch.from_numpy(np.array(input)).to(
          dtype=torch.double, device=device
      )
      input_tensor.requires_grad = True
      guide_tensor = torch.from_numpy(np.array(guide)).to(
          dtype=torch.double, device=device
      )
  
      # C++ extension so far only supports 5-dim inputs.
      len_input = len(input_tensor.shape)
      if len_input == 3:
          input_tensor = input_tensor.unsqueeze(3).unsqueeze(4)
          guide_tensor = guide_tensor.unsqueeze(3).unsqueeze(4)
      elif len_input == 4:
          input_tensor = input_tensor.unsqueeze(4)
          guide_tensor = guide_tensor.unsqueeze(4)
  
      # Check gradient toward input.
      args = (
          input_tensor,
          guide_tensor,
          torch.tensor(sigmas[0]),
          torch.tensor(sigmas[1]),
          torch.tensor(sigmas[2]),
          torch.tensor(sigmas[3]),
      )
      gradcheck(
          TrainableJointBilateralFilterFunction.apply,
          args,
          eps=1e-6,
          atol=1e-5,
          raise_exception=False,
      )
      input_tensor = input_tensor.detach()
      input_tensor.requires_grad = False
  
      # Check gradient toward guide.
      guide_tensor.requires_grad = True
      args = (
          input_tensor,
          guide_tensor,
          torch.tensor(sigmas[0]),
          torch.tensor(sigmas[1]),
          torch.tensor(sigmas[2]),
          torch.tensor(sigmas[3]),
      )
      gradcheck(
          TrainableJointBilateralFilterFunction.apply,
          args,
          eps=1e-6,
          atol=1e-5,
          raise_exception=False,
      )
      guide_tensor = guide_tensor.detach()
      guide_tensor.guide_tensor = False
  
      # Check gradient toward sigma_x.
      args = (
          input_tensor,
          guide_tensor,
          torch.tensor(
              sigmas[0], dtype=torch.double, requires_grad=True
          ),
          torch.tensor(sigmas[1]),
          torch.tensor(sigmas[2]),
          torch.tensor(sigmas[3]),
      )
      gradcheck(
          TrainableJointBilateralFilterFunction.apply,
          args,
          eps=1e-2,
          atol=1e-3,
          raise_exception=False,
      )
  
      # Check gradient toward sigma_y.
      args = (
          input_tensor,
          guide_tensor,
          torch.tensor(sigmas[0]),
          torch.tensor(
              sigmas[1], dtype=torch.double, requires_grad=True
          ),
          torch.tensor(sigmas[2]),
          torch.tensor(sigmas[3]),
      )
      gradcheck(
          TrainableJointBilateralFilterFunction.apply,
          args,
          eps=1e-2,
          atol=1e-3,
          raise_exception=False,
      )
  
      # Check gradient toward sigma_z.
      args = (
          input_tensor,
          guide_tensor,
          torch.tensor(sigmas[0]),
          torch.tensor(sigmas[1]),
          torch.tensor(
              sigmas[2], dtype=torch.double, requires_grad=True
          ),
          torch.tensor(sigmas[3]),
      )
      gradcheck(
          TrainableJointBilateralFilterFunction.apply,
          args,
          eps=1e-2,
          atol=1e-3,
          raise_exception=False,
      )
  
      # Check gradient toward sigma_color.
      args = (
          input_tensor,
          guide_tensor,
          torch.tensor(sigmas[0]),
          torch.tensor(sigmas[1]),
          torch.tensor(sigmas[2]),
          torch.tensor(
              sigmas[3], dtype=torch.double, requires_grad=True
          ),
      )
      gradcheck(
          TrainableJointBilateralFilterFunction.apply,
          args,
          eps=1e-3,
          atol=1e-3,
          raise_exception=False,
      )
  
file_path: MONAI/tests/test_trainable_joint_bilateral.py
imports: from __future__ import annotations
  import unittest
  import numpy
  import torch
  from parameterized import parameterized
  from torch.autograd import gradcheck
  from monai.networks.layers.filtering import TrainableJointBilateralFilterFunction
  from tests.utils import skip_if_no_cpp_extension, skip_if_no_cuda, skip_if_quick
label_desc: Use image node_id 2 for calling the JointBilateralFilterTestCaseCudaPrecise obj's underlying member method code with example usage: obj.test_cuda_precise_backwards(test_case_description, sigmas, input, guide, expected) without return types