heterocl.nparray¶
Helper functions for NumPy arrays.
-
asarray
(arr, dtype=None, ctx=cpu(0))[source]¶ Convert a NumPy array to a HeteroCL array.
The converted array will be inputs to the executable.
- Parameters
arr (ndarray) – The array to be converted
dtype (Type, optional) – The target data type
ctx (TVMContext) – The target context
- Returns
- Return type
Examples
np_A = numpy.zeros(10) hcl_A = np_A.asarray()
-
cast_np
(np_in, dtype)[source]¶ Cast a NumPy array to a specified data type.
- Parameters
np_in (ndarray) – The array to be cast
dtype (Type) – The target data type
- Returns
- Return type
ndarray
Examples
A_float = numpy.random.rand(10) A_fixed = hcl.cast_np(A_float, hcl.Fixed(10, 8))
-
pack_np
(np_in, dtype_in, dtype_out)[source]¶ Pack a NumPy array according to the specified data types.
Now we only support packing and unpacking for a 1-dimensional array.
- Parameters
- Returns
- Return type
ndarray
Examples
a = numpy.random.randint(16, size=(10,)) packed_a = hcl.pack_np(np_in, hcl.UInt(8), hcl.UInt(32))
-
unpack_np
(np_in, dtype_in, dtype_out)[source]¶ Unpack a NumPy array according to the specified data types.
Now we only support packing and unpacking for a 1-dimensional array.
- Parameters
- Returns
- Return type
ndarray
Examples
a = numpy.random.randint(4, size=(10,)) unpacked_a = hcl.pack_np(np_in, hcl.UInt(32), hcl.UInt(8))