Skip to content

Commit 8153522

Browse files
committed
quality-of-life changes
1 parent 9c585aa commit 8153522

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

hls4ml/converters/keras_v3_to_hls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class UniqueName:
100100
'''Helper class to generate unique names for layers, if one being used multiple times.'''
101101

102102
def __init__(self):
103-
self.used_names: set[str] = set()
103+
self.used_names: set[str] = set('input')
104+
# input is reserved in hls4ml, avoid conflict with it
104105

105106
def next_name(self, name: str):
106107
i = 0

hls4ml/model/graph.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,12 @@ def _compute_n_samples(self, x):
867867
return int(n_sample)
868868

869869
def predict(self, x):
870+
if isinstance(x, np.ndarray) and not x.flags['C_CONTIGUOUS']:
871+
x = np.ascontiguousarray(x)
872+
873+
# Compile the model if it wasn't compiled yet
874+
if self._top_function_lib is None:
875+
self.compile()
870876
top_function, ctype = self._get_top_function(x)
871877
n_samples = self._compute_n_samples(x)
872878
n_inputs = len(self.get_input_variables())
@@ -882,10 +888,9 @@ def predict(self, x):
882888
inp = [np.asarray(x[i])]
883889
else:
884890
inp = [np.asarray(xj[i]) for xj in x]
885-
argtuple = inp
886-
argtuple += predictions
887-
argtuple = tuple(argtuple)
888-
top_function(*argtuple)
891+
inp = [_inp if _inp.flags['C_CONTIGUOUS'] else np.ascontiguousarray(_inp) for _inp in inp]
892+
893+
top_function(*inp, *predictions)
889894
output.append(predictions)
890895

891896
# Convert to list of numpy arrays (one for each output)

0 commit comments

Comments
 (0)