We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
SpatialFullConvolution loaded from Lua doesn't have finput attribute
I am new to python，when i solve the promblem with the help below：
https://github.com/pytorch/pytorch/issues/897

I find some confusion in the code：
https://github.com/pytorch/pytorch/blob/master/torch/legacy/nn/JoinTable.py#L7

I set ‘dimension=1；self.dimension = dimension’，it seem ok for me，but i don’t kown how the value of ’dimension‘ was initialled. 

Thank you !

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `torch/legacy/nn/SpatialFullConvolution.py`
Content:
```
1 import math
2 import torch
3 from .Module import Module
4 from .utils import clear
5 
6 
7 class SpatialFullConvolution(Module):
8 
9     def __init__(self, nInputPlane, nOutputPlane, kW, kH, dW=1, dH=1, padW=0, padH=None, adjW=0, adjH=0):
10         super(SpatialFullConvolution, self).__init__()
11 
12         self.nInputPlane = nInputPlane
13         self.nOutputPlane = nOutputPlane
14         self.kW = kW
15         self.kH = kH
16         self.dW = dW
17         self.dH = dH
18         self.padW = padW
19         self.padH = padH if padH is not None else padW
20         self.adjW = adjW
21         self.adjH = adjH
22 
23         if self.adjW > self.dW - 1 or self.adjH > self.dH - 1:
24             raise ValueError('adjW and adjH must be smaller than self.dW - 1 and self.dH - 1 respectively')
25 
26         self.weight = torch.Tensor(nInputPlane, nOutputPlane, kH, kW)
27         self.gradWeight = torch.Tensor(nInputPlane, nOutputPlane, kH, kW)
28         self.bias = torch.Tensor(self.nOutputPlane)
29         self.gradBias = torch.Tensor(self.nOutputPlane)
30 
31         self.ones = torch.Tensor()
32         self.finput = None
33         self.fgradInput = None
34         self.zeroScalar = None
35         self._gradOutput = None
36 
37         self.reset()
38 
39     def noBias(self):
40         self.bias = None
41         self.gradBias = None
42         return self
43 
44     def reset(self, stdv=None):
45         if stdv is not None:
46             stdv = stdv * math.sqrt(3)
47         else:
48             nInputPlane = self.nInputPlane
49             kH = self.kH
50             kW = self.kW
51             stdv = 1 / math.sqrt(kW * kH * nInputPlane)
52 
53         self.weight.uniform_(-stdv, stdv)
54         if self.bias is not None:
55             self.bias.uniform_(-stdv, stdv)
56 
57     def _makeContiguous(self, input, gradOutput=None):
58         if not input.is_contiguous():
59             if self._input is None:
60                 self._input = input.new()
61             self._input.resize_as_(input).copy_(input)
62             input = self._input
63 
64         if gradOutput is not None:
65             if not gradOutput.is_contiguous():
66                 if self._gradOutput is None:
67                     self._gradOutput = gradOutput.new()
68                 self._gradOutput.resize_as_(gradOutput).copy_(gradOutput)
69                 gradOutput = self._gradOutput
70             return input, gradOutput
71 
72         return input
73 
74     def _calculateAdj(self, targetSize, ker, pad, stride):
75         return (targetSize + 2 * pad - ker) % stride
76 
77     def updateOutput(self, input):
78         inputTensor = input
79         adjW, adjH = self.adjW, self.adjH
80 
81         # The input can be a table where the second element indicates the target
82         # output size, in which case the adj factors are computed automatically
83         if isinstance(input, list):
84             inputTensor = input[0]
85             targetTensor = input[1]
86             tDims = targetTensor.dim()
87             tH = targetTensor.size(tDims - 2)
88             tW = targetTensor.size(tDims - 1)
89             adjW = self._calculateAdj(tW, self.kW, self.padW, self.dW)
90             adjH = self._calculateAdj(tH, self.kH, self.padH, self.dH)
91             if self.finput is None:
92                 self.finput = input[0].new()
93             if self.fgradInput is None:
94                 self.fgradInput = input[0].new()
95         else:
96             if self.finput is None:
97                 self.finput = input.new()
98             if self.fgradInput is None:
99                 self.fgradInput = input.new()
100 
101         inputTensor = self._makeContiguous(inputTensor)
102         self._backend.SpatialFullConvolution_updateOutput(
103             self._backend.library_state,
104             inputTensor,
105             self.output,
106             self.weight,
107             self.bias,
108             self.finput,
109             self.fgradInput,
110             self.kW, self.kH,
111             self.dW, self.dH,
112             self.padW, self.padH,
113             adjW, adjH
114         )
115         return self.output
116 
117     def updateGradInput(self, input, gradOutput):
118         if self.gradInput is None:
119             return
120         inputTensor = input
121         adjW, adjH = self.adjW, self.adjH
122 
123         # The input can be a table where the second element indicates the target
124         # output size, in which case the adj factors are computed automatically
125         if isinstance(input, list):
126             inputTensor = input[0]
127             targetTensor = input[1]
128             tDims = targetTensor.dim()
129             tH = targetTensor.size(tDims - 2)
130             tW = targetTensor.size(tDims - 1)
131             adjW = self._calculateAdj(tW, self.kW, self.padW, self.dW)
132             adjH = self._calculateAdj(tH, self.kH, self.padH, self.dH)
133         # Momentarily extract the gradInput tensor
134         if isinstance(self.gradInput, list):
135             self.gradInput = self.gradInput[0]
136 
137         inputTensor, gradOutput = self._makeContiguous(inputTensor, gradOutput)
138         self._backend.SpatialFullConvolution_updateGradInput(
139             self._backend.library_state,
140             inputTensor,
141             gradOutput,
142             self.gradInput,
143             self.weight,
144             self.finput,
145             self.kW, self.kH,
146             self.dW, self.dH,
147             self.padW, self.padH,
148             adjW, adjH
149         )
150 
151         if isinstance(input, list):
152             # Create a zero tensor to be expanded and used as gradInput[1].
153             if self.zeroScalar is None:
154                 self.zeroScalar = input[1].new(1).zero_()
155             self.ones.resize_(input[1].dim()).fill_(1)
156             zeroTensor = self.zeroScalar.view_as(self.ones).expand_as(input[1])
157             self.gradInput = [self.gradInput, zeroTensor]
158 
159         return self.gradInput
160 
161     def accGradParameters(self, input, gradOutput, scale=1):
162         inputTensor = input
163         adjW, adjH = self.adjW, self.adjH
164 
165         # The input can be a table where the second element indicates the target
166         # output size, in which case the adj factors are computed automatically
167         if isinstance(inputTensor, list):
168             inputTensor = input[0]
169             targetTensor = input[1]
170             tDims = targetTensor.dim()
171             tH = targetTensor.size(tDims - 2)
172             tW = targetTensor.size(tDims - 1)
173             adjW = calculateAdj(tW, self.kW, self.padW, self.dW)
174             adjH = calculateAdj(tH, self.kH, self.padH, self.dH)
175 
176         inputTensor, gradOutput = self._makeContiguous(inputTensor, gradOutput)
177         self._backend.SpatialFullConvolution_accGradParameters(
178             self._backend.library_state,
179             inputTensor,
180             gradOutput,
181             self.gradWeight,
182             self.gradBias,
183             self.finput,
184             self.fgradInput,
185             self.kW, self.kH,
186             self.dW, self.dH,
187             self.padW, self.padH,
188             adjW, adjH,
189             scale
190         )
191 
192     def type(self, type=None, tensorCache=None):
193         if self.finput is not None:
194             self.finput = torch.Tensor()
195         if self.fgradInput is not None:
196             self.fgradInput = torch.Tensor()
197         return super(SpatialFullConvolution, self).type(type, tensorCache)
198 
199     def __repr__(self):
200         s = super(SpatialFullConvolution, self).__repr__()
201         s += '({} -> {}, {}x{}'.format(self.nInputPlane, self.nOutputPlane, self.kW, self.kH)
202         if self.dW != 1 or self.dH != 1 or self.padW != 0 or self.padH != 0:
203             s += ', {}, {}'.format(self.dW, self.dH)
204 
205         if (self.padW or self.padH) and (self.padW != 0 or self.padH != 0):
206             s += ', {}, {}'.format(self.padW, self.padH)
207 
208         if (self.adjW or self.adjH) and (self.adjW != 0 or self.adjH != 0):
209             s += ', {}, {}'.format(self.adjW, self.adjH)
210 
211         s += ')'
212         if self.bias is None:
213             s += ' without bias'
214         return s
215 
216     def clearState(self):
217         clear(self, 'finput', 'fgradInput', '_input', '_gradOutput')
218         return super(SpatialFullConvolution, self).clearState()
219
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/torch/legacy/nn/SpatialFullConvolution.py b/torch/legacy/nn/SpatialFullConvolution.py
--- a/torch/legacy/nn/SpatialFullConvolution.py
+++ b/torch/legacy/nn/SpatialFullConvolution.py
@@ -88,14 +88,14 @@
             tW = targetTensor.size(tDims - 1)
             adjW = self._calculateAdj(tW, self.kW, self.padW, self.dW)
             adjH = self._calculateAdj(tH, self.kH, self.padH, self.dH)
-            if self.finput is None:
+            if not hasattr(self, 'finput') or self.finput is None:
                 self.finput = input[0].new()
-            if self.fgradInput is None:
+            if not hasattr(self, 'fgradInput') or self.fgradInput is None:
                 self.fgradInput = input[0].new()
         else:
-            if self.finput is None:
+            if not hasattr(self, 'finput') or self.finput is None:
                 self.finput = input.new()
-            if self.fgradInput is None:
+            if not hasattr(self, 'fgradInput') or self.fgradInput is None:
                 self.fgradInput = input.new()
 
         inputTensor = self._makeContiguous(inputTensor)

{"golden_diff": "diff --git a/torch/legacy/nn/SpatialFullConvolution.py b/torch/legacy/nn/SpatialFullConvolution.py\n--- a/torch/legacy/nn/SpatialFullConvolution.py\n+++ b/torch/legacy/nn/SpatialFullConvolution.py\n@@ -88,14 +88,14 @@\n             tW = targetTensor.size(tDims - 1)\n             adjW = self._calculateAdj(tW, self.kW, self.padW, self.dW)\n             adjH = self._calculateAdj(tH, self.kH, self.padH, self.dH)\n-            if self.finput is None:\n+            if not hasattr(self, 'finput') or self.finput is None:\n                 self.finput = input[0].new()\n-            if self.fgradInput is None:\n+            if not hasattr(self, 'fgradInput') or self.fgradInput is None:\n                 self.fgradInput = input[0].new()\n         else:\n-            if self.finput is None:\n+            if not hasattr(self, 'finput') or self.finput is None:\n                 self.finput = input.new()\n-            if self.fgradInput is None:\n+            if not hasattr(self, 'fgradInput') or self.fgradInput is None:\n                 self.fgradInput = input.new()\n \n         inputTensor = self._makeContiguous(inputTensor)\n", "issue": "SpatialFullConvolution loaded from Lua doesn't have finput attribute\nI am new to python\uff0cwhen i solve the promblem with the help below\uff1a\r\nhttps://github.com/pytorch/pytorch/issues/897\r\n\r\nI find some confusion in the code\uff1a\r\nhttps://github.com/pytorch/pytorch/blob/master/torch/legacy/nn/JoinTable.py#L7\r\n\r\nI set \u2018dimension=1\uff1bself.dimension = dimension\u2019\uff0cit seem ok for me\uff0cbut i don\u2019t kown how the value of \u2019dimension\u2018 was initialled. \r\n\r\nThank you !\n", "before_files": [{"content": "import math\nimport torch\nfrom .Module import Module\nfrom .utils import clear\n\n\nclass SpatialFullConvolution(Module):\n\n    def __init__(self, nInputPlane, nOutputPlane, kW, kH, dW=1, dH=1, padW=0, padH=None, adjW=0, adjH=0):\n        super(SpatialFullConvolution, self).__init__()\n\n        self.nInputPlane = nInputPlane\n        self.nOutputPlane = nOutputPlane\n        self.kW = kW\n        self.kH = kH\n        self.dW = dW\n        self.dH = dH\n        self.padW = padW\n        self.padH = padH if padH is not None else padW\n        self.adjW = adjW\n        self.adjH = adjH\n\n        if self.adjW > self.dW - 1 or self.adjH > self.dH - 1:\n            raise ValueError('adjW and adjH must be smaller than self.dW - 1 and self.dH - 1 respectively')\n\n        self.weight = torch.Tensor(nInputPlane, nOutputPlane, kH, kW)\n        self.gradWeight = torch.Tensor(nInputPlane, nOutputPlane, kH, kW)\n        self.bias = torch.Tensor(self.nOutputPlane)\n        self.gradBias = torch.Tensor(self.nOutputPlane)\n\n        self.ones = torch.Tensor()\n        self.finput = None\n        self.fgradInput = None\n        self.zeroScalar = None\n        self._gradOutput = None\n\n        self.reset()\n\n    def noBias(self):\n        self.bias = None\n        self.gradBias = None\n        return self\n\n    def reset(self, stdv=None):\n        if stdv is not None:\n            stdv = stdv * math.sqrt(3)\n        else:\n            nInputPlane = self.nInputPlane\n            kH = self.kH\n            kW = self.kW\n            stdv = 1 / math.sqrt(kW * kH * nInputPlane)\n\n        self.weight.uniform_(-stdv, stdv)\n        if self.bias is not None:\n            self.bias.uniform_(-stdv, stdv)\n\n    def _makeContiguous(self, input, gradOutput=None):\n        if not input.is_contiguous():\n            if self._input is None:\n                self._input = input.new()\n            self._input.resize_as_(input).copy_(input)\n            input = self._input\n\n        if gradOutput is not None:\n            if not gradOutput.is_contiguous():\n                if self._gradOutput is None:\n                    self._gradOutput = gradOutput.new()\n                self._gradOutput.resize_as_(gradOutput).copy_(gradOutput)\n                gradOutput = self._gradOutput\n            return input, gradOutput\n\n        return input\n\n    def _calculateAdj(self, targetSize, ker, pad, stride):\n        return (targetSize + 2 * pad - ker) % stride\n\n    def updateOutput(self, input):\n        inputTensor = input\n        adjW, adjH = self.adjW, self.adjH\n\n        # The input can be a table where the second element indicates the target\n        # output size, in which case the adj factors are computed automatically\n        if isinstance(input, list):\n            inputTensor = input[0]\n            targetTensor = input[1]\n            tDims = targetTensor.dim()\n            tH = targetTensor.size(tDims - 2)\n            tW = targetTensor.size(tDims - 1)\n            adjW = self._calculateAdj(tW, self.kW, self.padW, self.dW)\n            adjH = self._calculateAdj(tH, self.kH, self.padH, self.dH)\n            if self.finput is None:\n                self.finput = input[0].new()\n            if self.fgradInput is None:\n                self.fgradInput = input[0].new()\n        else:\n            if self.finput is None:\n                self.finput = input.new()\n            if self.fgradInput is None:\n                self.fgradInput = input.new()\n\n        inputTensor = self._makeContiguous(inputTensor)\n        self._backend.SpatialFullConvolution_updateOutput(\n            self._backend.library_state,\n            inputTensor,\n            self.output,\n            self.weight,\n            self.bias,\n            self.finput,\n            self.fgradInput,\n            self.kW, self.kH,\n            self.dW, self.dH,\n            self.padW, self.padH,\n            adjW, adjH\n        )\n        return self.output\n\n    def updateGradInput(self, input, gradOutput):\n        if self.gradInput is None:\n            return\n        inputTensor = input\n        adjW, adjH = self.adjW, self.adjH\n\n        # The input can be a table where the second element indicates the target\n        # output size, in which case the adj factors are computed automatically\n        if isinstance(input, list):\n            inputTensor = input[0]\n            targetTensor = input[1]\n            tDims = targetTensor.dim()\n            tH = targetTensor.size(tDims - 2)\n            tW = targetTensor.size(tDims - 1)\n            adjW = self._calculateAdj(tW, self.kW, self.padW, self.dW)\n            adjH = self._calculateAdj(tH, self.kH, self.padH, self.dH)\n        # Momentarily extract the gradInput tensor\n        if isinstance(self.gradInput, list):\n            self.gradInput = self.gradInput[0]\n\n        inputTensor, gradOutput = self._makeContiguous(inputTensor, gradOutput)\n        self._backend.SpatialFullConvolution_updateGradInput(\n            self._backend.library_state,\n            inputTensor,\n            gradOutput,\n            self.gradInput,\n            self.weight,\n            self.finput,\n            self.kW, self.kH,\n            self.dW, self.dH,\n            self.padW, self.padH,\n            adjW, adjH\n        )\n\n        if isinstance(input, list):\n            # Create a zero tensor to be expanded and used as gradInput[1].\n            if self.zeroScalar is None:\n                self.zeroScalar = input[1].new(1).zero_()\n            self.ones.resize_(input[1].dim()).fill_(1)\n            zeroTensor = self.zeroScalar.view_as(self.ones).expand_as(input[1])\n            self.gradInput = [self.gradInput, zeroTensor]\n\n        return self.gradInput\n\n    def accGradParameters(self, input, gradOutput, scale=1):\n        inputTensor = input\n        adjW, adjH = self.adjW, self.adjH\n\n        # The input can be a table where the second element indicates the target\n        # output size, in which case the adj factors are computed automatically\n        if isinstance(inputTensor, list):\n            inputTensor = input[0]\n            targetTensor = input[1]\n            tDims = targetTensor.dim()\n            tH = targetTensor.size(tDims - 2)\n            tW = targetTensor.size(tDims - 1)\n            adjW = calculateAdj(tW, self.kW, self.padW, self.dW)\n            adjH = calculateAdj(tH, self.kH, self.padH, self.dH)\n\n        inputTensor, gradOutput = self._makeContiguous(inputTensor, gradOutput)\n        self._backend.SpatialFullConvolution_accGradParameters(\n            self._backend.library_state,\n            inputTensor,\n            gradOutput,\n            self.gradWeight,\n            self.gradBias,\n            self.finput,\n            self.fgradInput,\n            self.kW, self.kH,\n            self.dW, self.dH,\n            self.padW, self.padH,\n            adjW, adjH,\n            scale\n        )\n\n    def type(self, type=None, tensorCache=None):\n        if self.finput is not None:\n            self.finput = torch.Tensor()\n        if self.fgradInput is not None:\n            self.fgradInput = torch.Tensor()\n        return super(SpatialFullConvolution, self).type(type, tensorCache)\n\n    def __repr__(self):\n        s = super(SpatialFullConvolution, self).__repr__()\n        s += '({} -> {}, {}x{}'.format(self.nInputPlane, self.nOutputPlane, self.kW, self.kH)\n        if self.dW != 1 or self.dH != 1 or self.padW != 0 or self.padH != 0:\n            s += ', {}, {}'.format(self.dW, self.dH)\n\n        if (self.padW or self.padH) and (self.padW != 0 or self.padH != 0):\n            s += ', {}, {}'.format(self.padW, self.padH)\n\n        if (self.adjW or self.adjH) and (self.adjW != 0 or self.adjH != 0):\n            s += ', {}, {}'.format(self.adjW, self.adjH)\n\n        s += ')'\n        if self.bias is None:\n            s += ' without bias'\n        return s\n\n    def clearState(self):\n        clear(self, 'finput', 'fgradInput', '_input', '_gradOutput')\n        return super(SpatialFullConvolution, self).clearState()\n", "path": "torch/legacy/nn/SpatialFullConvolution.py"}], "after_files": [{"content": "import math\nimport torch\nfrom .Module import Module\nfrom .utils import clear\n\n\nclass SpatialFullConvolution(Module):\n\n    def __init__(self, nInputPlane, nOutputPlane, kW, kH, dW=1, dH=1, padW=0, padH=None, adjW=0, adjH=0):\n        super(SpatialFullConvolution, self).__init__()\n\n        self.nInputPlane = nInputPlane\n        self.nOutputPlane = nOutputPlane\n        self.kW = kW\n        self.kH = kH\n        self.dW = dW\n        self.dH = dH\n        self.padW = padW\n        self.padH = padH if padH is not None else padW\n        self.adjW = adjW\n        self.adjH = adjH\n\n        if self.adjW > self.dW - 1 or self.adjH > self.dH - 1:\n            raise ValueError('adjW and adjH must be smaller than self.dW - 1 and self.dH - 1 respectively')\n\n        self.weight = torch.Tensor(nInputPlane, nOutputPlane, kH, kW)\n        self.gradWeight = torch.Tensor(nInputPlane, nOutputPlane, kH, kW)\n        self.bias = torch.Tensor(self.nOutputPlane)\n        self.gradBias = torch.Tensor(self.nOutputPlane)\n\n        self.ones = torch.Tensor()\n        self.finput = None\n        self.fgradInput = None\n        self.zeroScalar = None\n        self._gradOutput = None\n\n        self.reset()\n\n    def noBias(self):\n        self.bias = None\n        self.gradBias = None\n        return self\n\n    def reset(self, stdv=None):\n        if stdv is not None:\n            stdv = stdv * math.sqrt(3)\n        else:\n            nInputPlane = self.nInputPlane\n            kH = self.kH\n            kW = self.kW\n            stdv = 1 / math.sqrt(kW * kH * nInputPlane)\n\n        self.weight.uniform_(-stdv, stdv)\n        if self.bias is not None:\n            self.bias.uniform_(-stdv, stdv)\n\n    def _makeContiguous(self, input, gradOutput=None):\n        if not input.is_contiguous():\n            if self._input is None:\n                self._input = input.new()\n            self._input.resize_as_(input).copy_(input)\n            input = self._input\n\n        if gradOutput is not None:\n            if not gradOutput.is_contiguous():\n                if self._gradOutput is None:\n                    self._gradOutput = gradOutput.new()\n                self._gradOutput.resize_as_(gradOutput).copy_(gradOutput)\n                gradOutput = self._gradOutput\n            return input, gradOutput\n\n        return input\n\n    def _calculateAdj(self, targetSize, ker, pad, stride):\n        return (targetSize + 2 * pad - ker) % stride\n\n    def updateOutput(self, input):\n        inputTensor = input\n        adjW, adjH = self.adjW, self.adjH\n\n        # The input can be a table where the second element indicates the target\n        # output size, in which case the adj factors are computed automatically\n        if isinstance(input, list):\n            inputTensor = input[0]\n            targetTensor = input[1]\n            tDims = targetTensor.dim()\n            tH = targetTensor.size(tDims - 2)\n            tW = targetTensor.size(tDims - 1)\n            adjW = self._calculateAdj(tW, self.kW, self.padW, self.dW)\n            adjH = self._calculateAdj(tH, self.kH, self.padH, self.dH)\n            if not hasattr(self, 'finput') or self.finput is None:\n                self.finput = input[0].new()\n            if not hasattr(self, 'fgradInput') or self.fgradInput is None:\n                self.fgradInput = input[0].new()\n        else:\n            if not hasattr(self, 'finput') or self.finput is None:\n                self.finput = input.new()\n            if not hasattr(self, 'fgradInput') or self.fgradInput is None:\n                self.fgradInput = input.new()\n\n        inputTensor = self._makeContiguous(inputTensor)\n        self._backend.SpatialFullConvolution_updateOutput(\n            self._backend.library_state,\n            inputTensor,\n            self.output,\n            self.weight,\n            self.bias,\n            self.finput,\n            self.fgradInput,\n            self.kW, self.kH,\n            self.dW, self.dH,\n            self.padW, self.padH,\n            adjW, adjH\n        )\n        return self.output\n\n    def updateGradInput(self, input, gradOutput):\n        if self.gradInput is None:\n            return\n        inputTensor = input\n        adjW, adjH = self.adjW, self.adjH\n\n        # The input can be a table where the second element indicates the target\n        # output size, in which case the adj factors are computed automatically\n        if isinstance(input, list):\n            inputTensor = input[0]\n            targetTensor = input[1]\n            tDims = targetTensor.dim()\n            tH = targetTensor.size(tDims - 2)\n            tW = targetTensor.size(tDims - 1)\n            adjW = self._calculateAdj(tW, self.kW, self.padW, self.dW)\n            adjH = self._calculateAdj(tH, self.kH, self.padH, self.dH)\n        # Momentarily extract the gradInput tensor\n        if isinstance(self.gradInput, list):\n            self.gradInput = self.gradInput[0]\n\n        inputTensor, gradOutput = self._makeContiguous(inputTensor, gradOutput)\n        self._backend.SpatialFullConvolution_updateGradInput(\n            self._backend.library_state,\n            inputTensor,\n            gradOutput,\n            self.gradInput,\n            self.weight,\n            self.finput,\n            self.kW, self.kH,\n            self.dW, self.dH,\n            self.padW, self.padH,\n            adjW, adjH\n        )\n\n        if isinstance(input, list):\n            # Create a zero tensor to be expanded and used as gradInput[1].\n            if self.zeroScalar is None:\n                self.zeroScalar = input[1].new(1).zero_()\n            self.ones.resize_(input[1].dim()).fill_(1)\n            zeroTensor = self.zeroScalar.view_as(self.ones).expand_as(input[1])\n            self.gradInput = [self.gradInput, zeroTensor]\n\n        return self.gradInput\n\n    def accGradParameters(self, input, gradOutput, scale=1):\n        inputTensor = input\n        adjW, adjH = self.adjW, self.adjH\n\n        # The input can be a table where the second element indicates the target\n        # output size, in which case the adj factors are computed automatically\n        if isinstance(inputTensor, list):\n            inputTensor = input[0]\n            targetTensor = input[1]\n            tDims = targetTensor.dim()\n            tH = targetTensor.size(tDims - 2)\n            tW = targetTensor.size(tDims - 1)\n            adjW = calculateAdj(tW, self.kW, self.padW, self.dW)\n            adjH = calculateAdj(tH, self.kH, self.padH, self.dH)\n\n        inputTensor, gradOutput = self._makeContiguous(inputTensor, gradOutput)\n        self._backend.SpatialFullConvolution_accGradParameters(\n            self._backend.library_state,\n            inputTensor,\n            gradOutput,\n            self.gradWeight,\n            self.gradBias,\n            self.finput,\n            self.fgradInput,\n            self.kW, self.kH,\n            self.dW, self.dH,\n            self.padW, self.padH,\n            adjW, adjH,\n            scale\n        )\n\n    def type(self, type=None, tensorCache=None):\n        if self.finput is not None:\n            self.finput = torch.Tensor()\n        if self.fgradInput is not None:\n            self.fgradInput = torch.Tensor()\n        return super(SpatialFullConvolution, self).type(type, tensorCache)\n\n    def __repr__(self):\n        s = super(SpatialFullConvolution, self).__repr__()\n        s += '({} -> {}, {}x{}'.format(self.nInputPlane, self.nOutputPlane, self.kW, self.kH)\n        if self.dW != 1 or self.dH != 1 or self.padW != 0 or self.padH != 0:\n            s += ', {}, {}'.format(self.dW, self.dH)\n\n        if (self.padW or self.padH) and (self.padW != 0 or self.padH != 0):\n            s += ', {}, {}'.format(self.padW, self.padH)\n\n        if (self.adjW or self.adjH) and (self.adjW != 0 or self.adjH != 0):\n            s += ', {}, {}'.format(self.adjW, self.adjH)\n\n        s += ')'\n        if self.bias is None:\n            s += ' without bias'\n        return s\n\n    def clearState(self):\n        clear(self, 'finput', 'fgradInput', '_input', '_gradOutput')\n        return super(SpatialFullConvolution, self).clearState()\n", "path": "torch/legacy/nn/SpatialFullConvolution.py"}]}