MCPcopy Create free account
hub / github.com/apache/singa / to_type

Method to_type

python/singa/tensor.py:286–310  ·  view source on GitHub ↗

Change the data type inplace. Args: dtype: accepts 'int', 'float', 'singa.kFloat32', 'singa.kInt' Returns: new tensor with new type

(self, dtype)

Source from the content-addressed store, hash-verified

284 return t
285
286 def to_type(self, dtype):
287 '''Change the data type inplace.
288
289 Args:
290 dtype: accepts 'int', 'float', 'singa.kFloat32', 'singa.kInt'
291
292 Returns:
293 new tensor with new type
294 '''
295 assert self.data.initialized()
296 if dtype == singa.kInt:
297 pass
298 elif dtype == singa.kFloat32:
299 pass
300 elif dtype == singa.kFloat16:
301 pass
302 elif dtype == 'int':
303 dtype = singa.kInt
304 elif dtype == 'float':
305 dtype = singa.kFloat32
306 else:
307 raise TypeError("invalid data type %s" % dtype)
308 self.data.ToType(dtype)
309 self.dtype = dtype
310 return self
311
312 def to_device(self, device):
313 '''Move the tensor data onto a given device.

Callers 1

dtype_checkMethod · 0.80

Calls 1

initializedMethod · 0.45

Tested by

no test coverage detected