| 101 | |
| 102 | |
| 103 | class Subtraction(Function): |
| 104 | @staticmethod |
| 105 | def forward(ctx, input1, input2, idx): |
| 106 | """ |
| 107 | input: input1: (n, c), input2: (n, c), idx: (n, nsample) |
| 108 | output: (n, nsample, c) |
| 109 | """ |
| 110 | assert input1.is_contiguous() and input2.is_contiguous() |
| 111 | n, c = input1.shape; nsample = idx.shape[-1] |
| 112 | output = torch.cuda.FloatTensor(n, nsample, c).zero_() |
| 113 | pointops_cuda.subtraction_forward_cuda(n, nsample, c, input1, input2, idx, output) |
| 114 | ctx.save_for_backward(idx) |
| 115 | return output |
| 116 | |
| 117 | @staticmethod |
| 118 | def backward(ctx, grad_output): |
| 119 | """ |
| 120 | input: grad_out: (n, nsample, c) |
| 121 | output: grad_input1: (n, c), grad_input2: (n, c) |
| 122 | """ |
| 123 | idx, = ctx.saved_tensors |
| 124 | n, nsample, c = grad_output.shape |
| 125 | grad_input1 = torch.cuda.FloatTensor(n, c).zero_() |
| 126 | grad_input2 = torch.cuda.FloatTensor(n, c).zero_() |
| 127 | pointops_cuda.subtraction_backward_cuda(n, nsample, c, idx, grad_output, grad_input1, grad_input2) |
| 128 | return grad_input1, grad_input2, None |
| 129 | |
| 130 | subtraction = Subtraction.apply |
| 131 |
nothing calls this directly
no outgoing calls
no test coverage detected