To transpose the tensor Args: axes: axes to transpose Returns: new transposed tensor
(self, axes=None)
| 189 | return self.data.transpose() |
| 190 | |
| 191 | def transpose(self, axes=None): |
| 192 | ''' To transpose the tensor |
| 193 | |
| 194 | Args: |
| 195 | axes: axes to transpose |
| 196 | |
| 197 | Returns: |
| 198 | new transposed tensor |
| 199 | ''' |
| 200 | t = Tensor(self.shape, self.device, self.dtype) |
| 201 | if axes is None: |
| 202 | tshape = [self.shape[x] for x in range(len(t.shape))] |
| 203 | t.shape = tuple(tshape) |
| 204 | t.data = singa.DefaultTranspose(self.data) |
| 205 | else: |
| 206 | if (len(axes) != len(self.shape)): |
| 207 | raise ValueError('dimensions do not match') |
| 208 | tshape = [self.shape[x] for x in axes] |
| 209 | t.shape = tuple(tshape) |
| 210 | t.data = singa.Transpose(self.data, list(axes)) |
| 211 | return t |
| 212 | |
| 213 | def size(self): # TODO(wangwei) compute size |
| 214 | ''' |