Skip to content
Snippets Groups Projects
Commit 7c716ada authored by Yaman Umuroglu's avatar Yaman Umuroglu
Browse files

[Util] add comments to npy/rtlsim conv functions

parent 43933f35
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ import numpy as np
from finn.core.datatype import DataType
from finn.core.utils import (
pack_innermost_dim_as_hex_string,
unpack_innermost_dim_from_hex_string
unpack_innermost_dim_from_hex_string,
)
......@@ -63,6 +63,12 @@ def numpy_to_hls_code(
def npy_to_rtlsim_input(input_file, input_dtype, pad_to_nbits):
"""Convert the multidimensional NumPy array of integers (stored as floats)
from input_file into a flattened sequence of Python arbitrary-precision
integers, packing the innermost dimension. See
finn.core.utils.pack_innermost_dim_as_hex_string() for more info on how the
packing works."""
inp = np.load(input_file)
ishape = inp.shape
inp = inp.flatten()
......@@ -79,6 +85,11 @@ def npy_to_rtlsim_input(input_file, input_dtype, pad_to_nbits):
def rtlsim_output_to_npy(output, path, dtype, shape, packedBits, targetBits):
"""Convert a flattened sequence of Python arbitrary-precision integers
output into a NumPy array. Each arbitrary-precision integer is assumed to
be a packed array of targetBits-bit elements, which will be unpacked
as the innermost dimension of the NumPy array."""
output = [hex(int(x)) for x in output]
out_array = unpack_innermost_dim_from_hex_string(
output, dtype, shape, packedBits, targetBits, True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment