From 8b3f65764070378de39d9bf87b0e12fcef8346c1 Mon Sep 17 00:00:00 2001 From: Iaroslav Zeigerman Date: Sun, 24 May 2020 21:26:59 -0700 Subject: [PATCH] Use NumVal with specified 'dtype' instead of converting the threshold value in place when assembling a sklearn tree (#190) --- m2cgen/assemblers/tree.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/m2cgen/assemblers/tree.py b/m2cgen/assemblers/tree.py index 26639577..f25afd1e 100644 --- a/m2cgen/assemblers/tree.py +++ b/m2cgen/assemblers/tree.py @@ -54,6 +54,6 @@ def _assemble_cond(self, node_id): # sklearn's trees internally work with float32 numbers, so in order # to have consistent results across all supported languages, we convert # all thresholds into float32. - threshold = threshold.astype(np.float32) + threshold_num_val = ast.NumVal(threshold, dtype=np.float32) - return utils.lte(ast.FeatureRef(feature_idx), ast.NumVal(threshold)) + return utils.lte(ast.FeatureRef(feature_idx), threshold_num_val)