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

[Utils] Wrote function to generate a random tensor with FINN data type BIPOLAR, added test for it

parent 04a40e98
No related branches found
No related tags found
No related merge requests found
......@@ -174,3 +174,13 @@ def pad_tensor_to_multiple_of(ndarray, pad_to_dims, val=0, distr_pad=False):
ret = np.pad(ndarray, pad_amt, mode="constant", constant_values=val)
assert (np.asarray(ret.shape, dtype=np.int32) == desired).all()
return ret
def gen_FINN_dt_tensor(FINN_dt, tensor_shape):
# generates random tensor in given shape and with given FINN data type
if FINN_dt == DataType.BIPOLAR:
tensor_values = np.random.randint(2, size=tensor_shape)
tensor_values = 2 * tensor_values - 1
else:
raise ValueError("Datatype {} is not supported, no tensor could be generated".format(FINN_dt))
return[tensor_values]
import finn.core.utils as util
from finn.core.datatype import DataType
def test_FINN_tensor_generator():
# bipolar
shape_bp = [2,2]
dt_bp = DataType.BIPOLAR
tensor_bp = util.gen_FINN_dt_tensor(dt_bp, shape_bp)
import pdb; pdb.set_trace()
print(tensor_bp)
# test shape
# test if elements are FINN datatype
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