Copy the data from the numpy array. used as static method Args: data: singa ctensor np_array: source numpy array
(data, np_array)
| 1775 | |
| 1776 | |
| 1777 | def copy_from_numpy(data, np_array): |
| 1778 | ''' Copy the data from the numpy array. |
| 1779 | used as static method |
| 1780 | |
| 1781 | Args: |
| 1782 | data: singa ctensor |
| 1783 | np_array: source numpy array |
| 1784 | ''' |
| 1785 | assert np_array.size == data.Size(), \ |
| 1786 | 'tensor shape should be the same' |
| 1787 | if not np_array.ndim == 1: |
| 1788 | np_array = np_array.flatten() |
| 1789 | dt = np_array.dtype |
| 1790 | if dt == np.float32: |
| 1791 | data.CopyFloatDataFromHostPtr(np_array) |
| 1792 | elif dt == np.float16: |
| 1793 | data.CopyHalfFloatDataFromHostPtr(np_array) |
| 1794 | elif dt == np.int or dt == np.int32: |
| 1795 | data.CopyIntDataFromHostPtr(np_array) |
| 1796 | else: |
| 1797 | raise NotImplementedError('Not implemented yet for ', dt) |
| 1798 | |
| 1799 | |
| 1800 | def concatenate(tensors, axis): |