diff --git a/src/finn/util/basic.py b/src/finn/util/basic.py index ebe4f4fa62810ec5425db17496e64d93bbd2d879..3803e66872cdbe7383c5c55c3338463681c8b62e 100644 --- a/src/finn/util/basic.py +++ b/src/finn/util/basic.py @@ -53,7 +53,7 @@ def get_by_name(container, name, name_field="name"): def remove_by_name(container, name, name_field="name"): - """Remove item from container by .name field if it exists""" + """Remove item from container by .name field if it exists.""" item = get_by_name(container, name, name_field) if item is not None: container.remove(item) @@ -135,7 +135,7 @@ def pad_tensor_to_multiple_of(ndarray, pad_to_dims, val=0, distr_pad=False): def gen_finn_dt_tensor(finn_dt, tensor_shape): - """Generates random tensor in given shape and with given FINN DataType""" + """Generates random tensor in given shape and with given FINN DataType.""" if type(tensor_shape) == list: tensor_shape = tuple(tensor_shape) if finn_dt == DataType.BIPOLAR: @@ -196,7 +196,8 @@ class CppBuilder: def build(self, code_gen_dir): """Builds the g++ compiler command according to entries in include_paths - and cpp_files lists. Saves it in bash script and executes it.""" + and cpp_files lists. Saves it in bash script in given folder and + executes it.""" # raise error if includes are empty self.code_gen_dir = code_gen_dir self.compile_components.append("g++ -o " + str(self.executable_path)) diff --git a/src/finn/util/data_packing.py b/src/finn/util/data_packing.py index 639fa6d3fb44694c347d984524c175aee8575713..bc0d528aed4a3ce5d663e6117850ec3e832e960f 100644 --- a/src/finn/util/data_packing.py +++ b/src/finn/util/data_packing.py @@ -21,9 +21,13 @@ def array2hexstring(array, dtype, pad_to_nbits, prefix="0x", reverse=False): packing. Examples: + array2hexstring([1, 1, 1, 0], DataType.BINARY, 4) = "0xe" + array2hexstring([1, 1, 1, 0], DataType.BINARY, 8) = "0x0e" + array2hexstring([1, 1, 0, 1], DataType.BINARY, 4, reverse=True) = "0xb" + array2hexstring([1, 1, 1, 0], DataType.BINARY, 8, reverse=True) = "0x07" """ if pad_to_nbits < 4: @@ -63,7 +67,9 @@ def array2hexstring(array, dtype, pad_to_nbits, prefix="0x", reverse=False): def hexstring2npbytearray(hexstring, remove_prefix="0x"): - """Convert a hex string into a NumPy array of dtype uint8. Examples: + """Convert a hex string into a NumPy array of dtype uint8. + + Example: hexstring2npbytearray("0f01") = array([15, 1], dtype=uint8) """ @@ -76,7 +82,9 @@ def hexstring2npbytearray(hexstring, remove_prefix="0x"): def npbytearray2hexstring(npbytearray, prefix="0x"): - """Convert a NumPy array of uint8 dtype into a hex string. Examples: + """Convert a NumPy array of uint8 dtype into a hex string. + + Example: npbytearray2hexstring(array([15, 1], dtype=uint8)) = "0x0f01" """ @@ -85,13 +93,20 @@ def npbytearray2hexstring(npbytearray, prefix="0x"): def pack_innermost_dim_as_hex_string(ndarray, dtype, pad_to_nbits, reverse_inner=False): """Pack the innermost dimension of the given numpy ndarray into hex - strings using array2hexstring. Examples: + strings using array2hexstring. + + Examples: A = [[1, 1, 1, 0], [0, 1, 1, 0]] + eA = ["0e", "06"] + pack_innermost_dim_as_hex_string(A, DataType.BINARY, 8) == eA + B = [[[3, 3], [3, 3]], [[1, 3], [3, 1]]] + eB = [[ "0f", "0f"], ["07", "0d"]] + pack_innermost_dim_as_hex_string(B, DataType.UINT2, 8) == eB """ @@ -295,7 +310,9 @@ def packed_bytearray_to_finnpy( reverse_endian=False, ): """Given a packed numpy uint8 ndarray, unpack it into a FINN array of - given DataType. output_shape can be specified to remove padding from the + given DataType. + + output_shape can be specified to remove padding from the packed dimension, or set to None to be inferred from the input.""" if ( diff --git a/src/finn/util/fpgadataflow.py b/src/finn/util/fpgadataflow.py index 4a87522ea82cbc3a9a89bc4e1427e9fb117df53d..d02ef4549fde0cae1b9d6b039d4dbd2bb3a1f1dc 100644 --- a/src/finn/util/fpgadataflow.py +++ b/src/finn/util/fpgadataflow.py @@ -21,8 +21,9 @@ class IPGenBuilder: self.ipgen_path = path def build(self, code_gen_dir): - """Builds the bash script with given parameters. To guarantee the - generation in the correct folder the bash script contains a cd command.""" + """Builds the bash script with given parameters and saves it in given folder. + To guarantee the generation in the correct folder the bash script contains a + cd command.""" self.code_gen_dir = code_gen_dir self.ipgen_script = str(self.code_gen_dir) + "/ipgen.sh" working_dir = os.environ["PWD"]