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

[Test] add test_numpy_to_hls_code

parent 64e0658d
No related branches found
No related tags found
No related merge requests found
import numpy as np
from finn.backend.fpgadataflow.utils import numpy_to_hls_code
from finn.core.datatype import DataType
from finn.core.utils import array2hexstring, pack_innermost_dim_as_hex_string
......@@ -23,3 +24,20 @@ def test_pack_innermost_dim_as_hex_string():
B = [[[3, 3], [3, 3]], [[1, 3], [3, 1]]]
eB = np.asarray([["0f", "0f"], ["07", "0d"]])
assert (pack_innermost_dim_as_hex_string(B, DataType.UINT2, 8) == eB).all()
def test_numpy_to_hls_code():
def remove_all_whitespace(s):
return "".join(s.split())
A = [[1, 1, 1, 0], [0, 1, 1, 0]]
ret = numpy_to_hls_code(A, DataType.BINARY, "test", True)
eA = """ap_uint<4> test[2] =
{ap_uint<4>("e", 16), ap_uint<4>("6", 16)};"""
assert remove_all_whitespace(ret) == remove_all_whitespace(eA)
B = [[[3, 3], [3, 3]], [[1, 3], [3, 1]]]
ret = numpy_to_hls_code(B, DataType.UINT2, "test", True)
eB = """ap_uint<4> test[2][2] =
{{ap_uint<4>("f", 16), ap_uint<4>("f", 16)},
{ap_uint<4>("7", 16), ap_uint<4>("d", 16)}};"""
assert remove_all_whitespace(ret) == remove_all_whitespace(eB)
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