Skip to content
Snippets Groups Projects
Commit ed6acb52 authored by auphelia's avatar auphelia
Browse files

[Test] Extended rtlsim2npy test to test int2, int4 and int32 arrays

parent dea8695a
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ from finn.util.data_packing import unpack_innermost_dim_from_hex_string
def test_unpack_innermost_dim_from_hex_string():
# BINARY
A = np.asarray(["0x0e", "0x06"])
dtype = DataType.BINARY
shape = (1, 2, 4)
......@@ -19,6 +20,7 @@ def test_unpack_innermost_dim_from_hex_string():
)
assert (A_unpacked_flipped == eA_flipped).all()
# UINT2
B = np.asarray([["0x0f", "0x0f"], ["0x07", "0x0d"]])
dtype = DataType.UINT2
shape = (1, 2, 2, 2)
......@@ -32,3 +34,44 @@ def test_unpack_innermost_dim_from_hex_string():
B, dtype, shape, reverse_inner=True
)
assert (B_unpacked_flipped == eB_flipped).all()
# INT2
C = np.asarray([["0x0f", "0x0f"], ["0x07", "0x0d"]])
dtype = DataType.INT2
shape = (1, 2, 2, 2)
eC = [[[-1, -1], [-1, -1]], [[1, -1], [-1, 1]]]
C_unpacked = unpack_innermost_dim_from_hex_string(C, dtype, shape)
assert (C_unpacked == eC).all()
C = np.asarray([["0x0f", "0x0f"], ["0x07", "0x0d"]])
dtype = DataType.INT2
shape = (1, 2, 2, 2)
eC = [[[-1, -1], [-1, -1]], [[-1, 1], [1, -1]]]
C_unpacked = unpack_innermost_dim_from_hex_string(C, dtype, shape, reverse_inner=True)
assert (C_unpacked == eC).all()
# INT4
D = np.asarray(["0x0e", "0x06"])
dtype = DataType.INT4
shape = (2, 1)
eD = [[-2], [6]]
D_unpacked = unpack_innermost_dim_from_hex_string(D, dtype, shape)
assert (D_unpacked == eD).all()
D_unpacked = unpack_innermost_dim_from_hex_string(D, dtype, shape, reverse_inner=True)
assert (D_unpacked == eD).all()
# INT32
E = np.asarray(["0xffffffff", "0xfffffffe", "0x02", "0xffffffef"])
dtype = DataType.INT32
shape = (1, 4, 1)
eE = [[[-1],[-2],[2],[-17]]]
E_unpacked = unpack_innermost_dim_from_hex_string(E, dtype, shape)
assert (E_unpacked == eE).all()
E_unpacked = unpack_innermost_dim_from_hex_string(E, dtype, shape, reverse_inner=True)
assert (E_unpacked == eE).all()
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