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

Method as_type

python/singa/tensor.py:261–284  ·  view source on GitHub ↗

Change the data type. 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

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.

Callers 3

_astype_helperMethod · 0.95
__init__Method · 0.45
stepMethod · 0.45

Calls 2

TensorClass · 0.70
AsTypeMethod · 0.45

Tested by 1

_astype_helperMethod · 0.76