Change the data type. Args: dtype: accepts 'int', 'float', 'singa.kFloat32', 'singa.kInt' Returns: new tensor with new type
(self, dtype)
| 259 | self.dtype = t.dtype |
| 260 | |
| 261 | def as_type(self, dtype): |
| 262 | '''Change the data type. |
| 263 | |
| 264 | Args: |
| 265 | dtype: accepts 'int', 'float', 'singa.kFloat32', 'singa.kInt' |
| 266 | |
| 267 | Returns: |
| 268 | new tensor with new type |
| 269 | ''' |
| 270 | if dtype == singa.kInt: |
| 271 | pass |
| 272 | elif dtype == singa.kFloat16: |
| 273 | pass |
| 274 | elif dtype == singa.kFloat32: |
| 275 | pass |
| 276 | elif dtype == 'int': |
| 277 | dtype = singa.kInt |
| 278 | elif dtype == 'float': |
| 279 | dtype = singa.kFloat32 |
| 280 | else: |
| 281 | raise TypeError("invalid data type %s" % dtype) |
| 282 | t = Tensor(self.shape, self.device, dtype) |
| 283 | t.data = self.data.AsType(dtype) |
| 284 | return t |
| 285 | |
| 286 | def to_type(self, dtype): |
| 287 | '''Change the data type inplace. |