Skip to content

Commit

Permalink
Add optional argument output to `Athos/CompilerScripts/convert_np_t…
Browse files Browse the repository at this point in the history
…o_fixedpt.py`. (#137)
  • Loading branch information
Divyanshu Agrawal authored Jun 21, 2022
1 parent 3392737 commit e2957fc
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Athos/CompilerScripts/convert_np_to_fixedpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import argparse
from argparse import RawTextHelpFormatter
import sys

import parse_config
import os
Expand All @@ -42,6 +43,12 @@ def parse_args():
parser.add_argument(
"--config", required=True, type=str, help="Path to the config json file"
)
parser.add_argument(
"--output",
required=False,
type=str,
help="Path where the output fixedpoint numbers will be stored.",
)
args = parser.parse_args()
return args

Expand All @@ -50,19 +57,21 @@ def convert_np_to_fixedpt(path_to_numpy_arr, scaling_factor):
if not os.path.exists(path_to_numpy_arr):
sys.exit("Numpy arr {} specified does not exist".format(path_to_numpy_arr))
input_name = os.path.splitext(path_to_numpy_arr)[0]
output_path = input_name + "_fixedpt_scale_" + str(scaling_factor) + ".inp"

output_path = (
(input_name + "_fixedpt_scale_" + str(scaling_factor) + ".inp")
if args.output is None
else args.output
)
np_inp = np.load(path_to_numpy_arr, allow_pickle=True)
with open(output_path, "w") as ff:
for xx in np.nditer(np_inp, order="C"):
ff.write(str(int(xx * (1 << scaling_factor))) + " ")
ff.write("\n")
return output_path
return args.output


if __name__ == "__main__":
args = parse_args()

if not os.path.isfile(args.config):
sys.exit("Config file (" + args.config + ") specified does not exist")

Expand Down

0 comments on commit e2957fc

Please sign in to comment.