Copy the data from the numpy array. used as static method Args: data: singa ctensor np_array: source numpy array
(data, np_array)
| 1740 | |
| 1741 | |
| 1742 | def copy_from_numpy(data, np_array): |
| 1743 | ''' Copy the data from the numpy array. |
| 1744 | used as static method |
| 1745 | |
| 1746 | Args: |
| 1747 | data: singa ctensor |
| 1748 | np_array: source numpy array |
| 1749 | ''' |
| 1750 | assert np_array.size == data.Size(), \ |
| 1751 | 'tensor shape should be the same' |
| 1752 | if not np_array.ndim == 1: |
| 1753 | np_array = np_array.flatten() |
| 1754 | dt = np_array.dtype |
| 1755 | if dt == np.float32: |
| 1756 | data.CopyFloatDataFromHostPtr(np_array) |
| 1757 | elif dt == int or dt == np.int32: |
| 1758 | data.CopyIntDataFromHostPtr(np_array) |
| 1759 | else: |
| 1760 | print('Not implemented yet for ', dt) |
| 1761 | |
| 1762 | |
| 1763 | def concatenate(tensors, axis): |