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

Method copy_from_numpy

python/singa/tensor.py:360–378  ·  view source on GitHub ↗

Copy the data from the numpy array. Args: np_array: source numpy array offset (int): destination offset

(self, np_array, offset=0)

Source from the content-addressed store, hash-verified

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.

Callers 3

copy_fromMethod · 0.95
from_numpyFunction · 0.95
_round_evenMethod · 0.95

Calls 1

sizeMethod · 0.95

Tested by 1

_round_evenMethod · 0.76