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

Function copy_from_numpy

examples/model_selection/Trails/singa_pkg_code/tensor.py:1742–1760  ·  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

1740
1741
1742def 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
1763def concatenate(tensors, axis):

Callers 1

__init__Method · 0.70

Calls 1

SizeMethod · 0.45

Tested by

no test coverage detected