File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -100,7 +100,8 @@ class UniqueName:
100
100
'''Helper class to generate unique names for layers, if one being used multiple times.'''
101
101
102
102
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
104
105
105
106
def next_name (self , name : str ):
106
107
i = 0
Original file line number Diff line number Diff line change @@ -867,6 +867,12 @@ def _compute_n_samples(self, x):
867
867
return int (n_sample )
868
868
869
869
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 ()
870
876
top_function , ctype = self ._get_top_function (x )
871
877
n_samples = self ._compute_n_samples (x )
872
878
n_inputs = len (self .get_input_variables ())
@@ -882,10 +888,9 @@ def predict(self, x):
882
888
inp = [np .asarray (x [i ])]
883
889
else :
884
890
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 )
889
894
output .append (predictions )
890
895
891
896
# Convert to list of numpy arrays (one for each output)
You can’t perform that action at this time.
0 commit comments