From 147984e6aff853458811cd9745b5c6bfc311b0c7 Mon Sep 17 00:00:00 2001
From: Yaman Umuroglu <maltanar@gmail.com>
Date: Fri, 8 May 2020 15:50:27 +0100
Subject: [PATCH] [rtlsim] don't produce leftover out.npy file during rtlsim

use None in util fxn to indicate no file output
---
 src/finn/core/rtlsim_exec.py  | 2 +-
 src/finn/util/data_packing.py | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/finn/core/rtlsim_exec.py b/src/finn/core/rtlsim_exec.py
index af84a75e2..e5e6d29bd 100644
--- a/src/finn/core/rtlsim_exec.py
+++ b/src/finn/core/rtlsim_exec.py
@@ -94,7 +94,7 @@ def rtlsim_exec(model, execution_context):
     model.set_metadata_prop("sim_cycles", str(ret[1]))
     # unpack output and put into context
     o_folded_tensor = rtlsim_output_to_npy(
-        packed_output, "out.npy", o_dt, o_folded_shape, packedBits, targetBits
+        packed_output, None, o_dt, o_folded_shape, packedBits, targetBits
     )
     execution_context[o_name] = o_folded_tensor.reshape(o_shape)
 
diff --git a/src/finn/util/data_packing.py b/src/finn/util/data_packing.py
index e67638bd1..a087fd2ff 100644
--- a/src/finn/util/data_packing.py
+++ b/src/finn/util/data_packing.py
@@ -296,7 +296,8 @@ def rtlsim_output_to_npy(
     """Convert a flattened sequence of Python arbitrary-precision integers
     output into a NumPy array, saved as npy file at path. 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."""
+    will be unpacked as the innermost dimension of the NumPy array. If path is
+    not None it will also be saved as a npy file."""
 
     # TODO should have its own testbench?
     output = np.asarray([hex(int(x)) for x in output])
@@ -305,7 +306,8 @@ def rtlsim_output_to_npy(
     )
     # make copy before saving the array
     out_array = out_array.copy()
-    np.save(path, out_array)
+    if path is not None:
+        np.save(path, out_array)
     return out_array
 
 
-- 
GitLab