Entry-point for creating viewless tensors. This method should be used, rather than calling 'MakeViewlessTensor' or '_kernel_make_viewless_tensor' directly. This method acts as a switch for determining if an autograd function or a regular method should be used to create the tens
(inp, requires_grad, keep_graph)
| 109 | return grad_output, None |
| 110 | |
| 111 | def make_viewless_tensor(inp, requires_grad, keep_graph): |
| 112 | ''' |
| 113 | Entry-point for creating viewless tensors. |
| 114 | |
| 115 | This method should be used, rather than calling 'MakeViewlessTensor' |
| 116 | or '_kernel_make_viewless_tensor' directly. This method acts as a |
| 117 | switch for determining if an autograd function or a regular method |
| 118 | should be used to create the tensor. |
| 119 | ''' |
| 120 | |
| 121 | # return tensor as-is, if not a 'view' |
| 122 | if inp._base is None: |
| 123 | return inp |
| 124 | |
| 125 | # create viewless tensor |
| 126 | if keep_graph: |
| 127 | return MakeViewlessTensor.apply(inp, requires_grad) |
| 128 | else: |
| 129 | return _kernel_make_viewless_tensor(inp, requires_grad) |
| 130 | |
| 131 | def assert_viewless_tensor(tensor, extra_msg = None): |
| 132 | '''Assert that a tensor is not a view (i.e., its '._base' field is |
no test coverage detected