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

Function to_numpy

examples/model_selection/Trails/singa_pkg_code/tensor.py:891–907  ·  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

889
890
891def to_numpy(t):
892 '''Copy the tensor into a numpy array.
893
894 Args:
895 t (Tensor): a Tensor
896
897 Returns:
898 a numpy array
899 '''
900 th = to_host(t)
901 if th.dtype == float32:
902 np_array = th.data.GetFloatValue(int(th.size()))
903 elif th.dtype == int32:
904 np_array = th.data.GetIntValue(int(th.size()))
905 else:
906 print('Not implemented yet for ', th.dtype)
907 return np_array.reshape(th.shape)
908
909
910def 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