Copy the tensor into a numpy array. Args: t (Tensor): a Tensor Returns: a numpy array
(t)
| 922 | |
| 923 | |
| 924 | def 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 | |
| 945 | def abs(t): |