Copy the data from the numpy array. Args: np_array: source numpy array offset (int): destination offset
(self, np_array, offset=0)
| 358 | return self |
| 359 | |
| 360 | def copy_from_numpy(self, np_array, offset=0): |
| 361 | ''' Copy the data from the numpy array. |
| 362 | |
| 363 | Args: |
| 364 | np_array: source numpy array |
| 365 | offset (int): destination offset |
| 366 | ''' |
| 367 | assert np_array.size == self.size(), 'tensor shape should be the same' |
| 368 | if not np_array.ndim == 1: |
| 369 | np_array = np_array.flatten() |
| 370 | dt = np_array.dtype |
| 371 | if dt == np.float32: |
| 372 | self.data.CopyFloatDataFromHostPtr(np_array) |
| 373 | elif dt == np.float16: |
| 374 | self.data.CopyHalfFloatDataFromHostPtr(np_array) |
| 375 | elif dt == np.int or dt == np.int32: |
| 376 | self.data.CopyIntDataFromHostPtr(np_array) |
| 377 | else: |
| 378 | raise NotImplementedError('Not implemented yet for ', dt) |
| 379 | |
| 380 | def copy_data(self, t): |
| 381 | '''Copy data from other Tensor instance. |