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

Function copy_from_numpy

python/singa/tensor.py:1777–1797  ·  view source on GitHub ↗

Copy the data from the numpy array. used as static method Args: data: singa ctensor np_array: source numpy array

(data, np_array)

Source from the content-addressed store, hash-verified

1775
1776
1777def 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
1800def concatenate(tensors, axis):

Callers 1

__init__Method · 0.70

Calls 1

SizeMethod · 0.45

Tested by

no test coverage detected