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

Function to_numpy

python/singa/tensor.py:924–942  ·  view source on GitHub ↗

Copy the tensor into a numpy array. Args: t (Tensor): a Tensor Returns: a numpy array

(t)

Source from the content-addressed store, hash-verified

922
923
924def to_numpy(t):
925 '''Copy the tensor into a numpy array.
926
927 Args:
928 t (Tensor): a Tensor
929
930 Returns:
931 a numpy array
932 '''
933 th = to_host(t)
934 if th.dtype == float32:
935 np_array = th.data.GetFloatValue(int(th.size()))
936 elif th.dtype == float16:
937 np_array = th.data.GetHalfFloatValue(int(th.size()))
938 elif th.dtype == int32:
939 np_array = th.data.GetIntValue(int(th.size()))
940 else:
941 print('Not implemented yet for ', th.dtype)
942 return np_array.reshape(th.shape)
943
944
945def abs(t):

Callers 1

__repr__Method · 0.70

Calls 3

to_hostFunction · 0.70
sizeMethod · 0.45
reshapeMethod · 0.45

Tested by

no test coverage detected