def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() args = [(True, self._feature_array_name)] func_name = self.function_name with self._cg.function_definition( name=func_name, args=args, is_scalar_output=expr.output_size == 1): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result, func_name) if self.with_linear_algebra: filename = os.path.join( os.path.dirname(__file__), "linear_algebra.bas") self._cg.prepend_code_lines(utils.get_file_content(filename)) # Use own Tanh function in order to be compatible with both VB and VBA if self.with_tanh_expr: filename = os.path.join( os.path.dirname(__file__), "tanh.bas") self._cg.prepend_code_lines(utils.get_file_content(filename)) self._cg.prepend_code_line(self._cg.tpl_module_definition( module_name=self.module_name)) self._cg.add_code_line(self._cg.tpl_block_termination( block_name="Module")) return self._cg.code
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() args = [(True, self._feature_array_name)] with self._cg.function_definition( name=self.function_name, args=args, is_vector_output=expr.output_size > 1): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) if self.with_linear_algebra: filename = os.path.join(os.path.dirname(__file__), "linear_algebra.dart") self._cg.add_code_lines(utils.get_file_content(filename)) # Use own tanh function in order to be compatible with Dart if self.with_tanh_expr: filename = os.path.join(os.path.dirname(__file__), "tanh.dart") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_math_module: self._cg.add_dependency("dart:math") return self._cg.code
def interpret(self, expr): top_cg = self.create_code_generator() method_name = self.function_name with top_cg.namespace_definition(self.namespace): with top_cg.class_definition(self.class_name): self.enqueue_subroutine(self.function_name, expr) self.process_subroutine_queue(top_cg) if self.with_linear_algebra: filename = os.path.join(os.path.dirname(__file__), "linear_algebra.cs") top_cg.add_code_lines(utils.get_file_content(filename)) if self.with_log1p_expr: filename = os.path.join(os.path.dirname(__file__), "log1p.cs") top_cg.add_code_lines(utils.get_file_content(filename)) for _, item_set in self.static_declarations.items(): top_cg.add_code_line(item_set) top_cg.add_dependency("System.Collections.Generic", modifier="") if self.with_math_module: top_cg.add_dependency("System.Math") return top_cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() method_name = self.function_name args = [(True, self._feature_array_name)] with self._cg.namespace_definition(self.namespace): with self._cg.class_definition(self.class_name): with self._cg.method_definition( name=method_name, args=args, is_vector_output=expr.output_size > 1, modifier="public"): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) if self.with_linear_algebra: filename = os.path.join(os.path.dirname(__file__), "linear_algebra.cs") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_log1p_expr: filename = os.path.join(os.path.dirname(__file__), "log1p.cs") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_math_module: self._cg.add_dependency("System.Math") return self._cg.finalize_and_get_generated_code()
def interpret(self, expr): top_cg = self.create_code_generator() if self.package_name: top_cg.add_package_name(self.package_name) with top_cg.class_definition(self.class_name): # Since we use SubroutinesMixin, we already have logic # of adding methods. We create first subroutine for incoming # expression and call `process_subroutine_queue` method. self.enqueue_subroutine(self.function_name, expr) self.process_subroutine_queue(top_cg) current_dir = Path(__file__).absolute().parent if self.with_linear_algebra: filename = current_dir / "linear_algebra.java" top_cg.add_code_lines(get_file_content(filename)) if self.with_softmax_expr: filename = current_dir / "softmax.java" top_cg.add_code_lines(get_file_content(filename)) if self.with_sigmoid_expr: filename = current_dir / "sigmoid.java" top_cg.add_code_lines(get_file_content(filename)) return top_cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() args = [(True, self._feature_array_name)] func_name = self.function_name with self._cg.function_definition( name=func_name, args=args, is_scalar_output=expr.output_size == 1): last_result = self._do_interpret(expr) self._cg.add_code_line(last_result) self._dump_cache() if self.with_linear_algebra: filename = os.path.join( os.path.dirname(__file__), "linear_algebra.hs") self._cg.prepend_code_lines(utils.get_file_content(filename)) if self.with_log1p_expr: filename = os.path.join( os.path.dirname(__file__), "log1p.hs") self._cg.prepend_code_lines(utils.get_file_content(filename)) self._cg.prepend_code_line(self._cg.tpl_module_definition( module_name=self.module_name)) return self._cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() with self._cg.function_definition( name=self.function_name, args=[(True, self._feature_array_name)], is_scalar_output=expr.output_size == 1): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) current_dir = os.path.dirname(__file__) if self.with_linear_algebra: filename = os.path.join(current_dir, "linear_algebra.ps1") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_log1p_expr: filename = os.path.join(current_dir, "log1p.ps1") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_softmax_expr: filename = os.path.join(current_dir, "softmax.ps1") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_sigmoid_expr: filename = os.path.join(current_dir, "sigmoid.ps1") self._cg.add_code_lines(utils.get_file_content(filename)) return self._cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() args = [(True, self._feature_array_name)] func_name = self.function_name with self._cg.function_definition(name=func_name, args=args): last_result = self._do_interpret(expr) self._dump_cache() self._cg.add_code_line(last_result) current_dir = os.path.dirname(__file__) if self.with_linear_algebra: filename = os.path.join(current_dir, "linear_algebra.fs") self._cg.prepend_code_lines(utils.get_file_content(filename)) if self.with_log1p_expr: filename = os.path.join(current_dir, "log1p.fs") self._cg.prepend_code_lines(utils.get_file_content(filename)) if self.with_softmax_expr: filename = os.path.join(current_dir, "softmax.fs") self._cg.prepend_code_lines(utils.get_file_content(filename)) if self.with_sigmoid_expr: filename = os.path.join(current_dir, "sigmoid.fs") self._cg.prepend_code_lines(utils.get_file_content(filename)) return self._cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() with self._cg.function_definition(name=self.function_name, args=[self._feature_array_name]): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) current_dir = Path(__file__).absolute().parent if self.with_linear_algebra: filename = current_dir / "linear_algebra.py" self._cg.prepend_code_lines(get_file_content(filename)) if self.with_softmax_expr: filename = current_dir / "softmax.py" self._cg.prepend_code_lines(get_file_content(filename)) if self.with_sigmoid_expr: filename = current_dir / "sigmoid.py" self._cg.prepend_code_lines(get_file_content(filename)) if self.with_math_module: self._cg.add_dependency("math") return self._cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() with self._cg.function_definition( name=self.function_name, args=[(True, self._feature_array_name)], is_scalar_output=expr.output_size == 1): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) current_dir = Path(__file__).absolute().parent if self.with_linear_algebra: filename = current_dir / "linear_algebra.rs" self._cg.add_code_lines(get_file_content(filename)) if self.with_softmax_expr: filename = current_dir / "softmax.rs" self._cg.add_code_lines(get_file_content(filename)) if self.with_sigmoid_expr: filename = current_dir / "sigmoid.rs" self._cg.add_code_lines(get_file_content(filename)) return self._cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() args = [(True, self._feature_array_name)] # C doesn't allow returning vectors, so if model returns vector we will # have additional vector argument which we will populate at the end. if expr.output_size > 1: args += [(True, "output")] with self._cg.function_definition( name="score", args=args, is_scalar_output=expr.output_size == 1): last_result = self._do_interpret(expr) if expr.output_size > 1: self._cg.add_assign_array_statement(last_result, "output", expr.output_size) else: self._cg.add_return_statement(last_result) if self.with_linear_algebra: filename = os.path.join(os.path.dirname(__file__), "linear_algebra.c") self._cg.prepend_code_lines(utils.get_file_content(filename)) if self.with_vectors: self._cg.add_dependency("<string.h>") if self.with_exponent: self._cg.add_dependency("<math.h>") return self._cg.code
def interpret(self, expr): top_cg = self.create_code_generator() self.enqueue_subroutine(self.function_name, expr) self.process_subroutine_queue(top_cg) current_dir = os.path.dirname(__file__) if self.with_softmax_expr: filename = os.path.join(current_dir, "softmax.r") top_cg.prepend_code_lines(utils.get_file_content(filename)) if self.with_sigmoid_expr: filename = os.path.join(current_dir, "sigmoid.r") top_cg.prepend_code_lines(utils.get_file_content(filename)) return top_cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() args = [(True, self._feature_array_name)] # C doesn't allow returning vectors, so if model returns vector we will # have additional vector argument which we will populate at the end. if expr.output_size > 1: args += [(True, "output")] with self._cg.function_definition( name=self.function_name, args=args, is_scalar_output=expr.output_size == 1): last_result = self._do_interpret(expr) if expr.output_size > 1: self._cg.add_assign_array_statement(last_result, "output", expr.output_size) else: self._cg.add_return_statement(last_result) current_dir = Path(__file__).absolute().parent if self.with_linear_algebra: filename = current_dir / "linear_algebra.c" self._cg.prepend_code_lines(get_file_content(filename)) if self.with_softmax_expr: filename = current_dir / "softmax.c" self._cg.prepend_code_lines(get_file_content(filename)) if self.with_sigmoid_expr: filename = current_dir / "sigmoid.c" self._cg.prepend_code_lines(get_file_content(filename)) if self.with_vectors: self._cg.add_dependency("<string.h>") if self.with_math_module: self._cg.add_dependency("<math.h>") return self._cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() with self._cg.function_definition(name=self.function_name, args=[self._feature_array_name]): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) if self.with_linear_algebra: filename = os.path.join(os.path.dirname(__file__), "linear_algebra.rb") self._cg.prepend_code_lines(utils.get_file_content(filename)) if self.with_log1p_expr: filename = os.path.join(os.path.dirname(__file__), "log1p.rb") self._cg.add_code_lines(utils.get_file_content(filename)) return self._cg.finalize_and_get_generated_code()
def predict(self, X): code = get_file_content(self.script_path) args = ",".join(map(utils.format_arg, X)) caller = f"score([{args}])" ctx = py_mini_racer.MiniRacer() ctx.eval(code) result = ctx.execute(caller) return result
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() args = [(True, self._feature_array_name)] with self._cg.function_definition( name=self.function_name, args=args, is_vector_output=expr.output_size > 1): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) current_dir = os.path.dirname(__file__) if self.with_linear_algebra: filename = os.path.join(current_dir, "linear_algebra.dart") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_log1p_expr: filename = os.path.join(current_dir, "log1p.dart") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_sigmoid_expr: filename = os.path.join(current_dir, "sigmoid.dart") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_softmax_expr: filename = os.path.join(current_dir, "softmax.dart") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_tanh_expr: filename = os.path.join(current_dir, "tanh.dart") self._cg.add_code_lines(utils.get_file_content(filename)) if self.with_math_module: self._cg.add_dependency("dart:math") return self._cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() method_name = self.function_name args = [(True, self._feature_array_name)] with self._cg.namespace_definition(self.namespace): with self._cg.class_definition(self.class_name): with self._cg.method_definition( name=method_name, args=args, is_vector_output=expr.output_size > 1, modifier="public"): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) current_dir = Path(__file__).absolute().parent if self.with_linear_algebra: filename = current_dir / "linear_algebra.cs" self._cg.add_code_lines(get_file_content(filename)) if self.with_log1p_expr: filename = current_dir / "log1p.cs" self._cg.add_code_lines(get_file_content(filename)) if self.with_softmax_expr: filename = current_dir / "softmax.cs" self._cg.add_code_lines(get_file_content(filename)) if self.with_sigmoid_expr: filename = current_dir / "sigmoid.cs" self._cg.add_code_lines(get_file_content(filename)) if self.with_math_module: self._cg.add_dependency("System.Math") return self._cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() args = [(True, self._feature_array_name)] with self._cg.function_definition(name="score", args=args): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) if self.with_linear_algebra: filename = os.path.join(os.path.dirname(__file__), "linear_algebra.js") self._cg.add_code_lines(utils.get_file_content(filename)) return self._cg.code
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() with self._cg.function_definition( name="Score", args=[(True, self._feature_array_name)], is_scalar_output=expr.output_size == 1): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) if self.with_linear_algebra: filename = os.path.join(os.path.dirname(__file__), "linear_algebra.ps1") self._cg.prepend_code_lines(utils.get_file_content(filename)) return self._cg.code
def interpret(self, expr): top_cg = self.create_code_generator() if self.package_name: top_cg.add_package_name(self.package_name) with top_cg.class_definition(self.class_name): # Since we use SubroutinesMixin, we already have logic # of adding methods. We create first subroutine for incoming # expression and call `process_subroutine_queue` method. self.enqueue_subroutine(self.function_name, expr) self.process_subroutine_queue(top_cg) if self.with_linear_algebra: filename = os.path.join(os.path.dirname(__file__), "linear_algebra.java") top_cg.add_code_lines(utils.get_file_content(filename)) return top_cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() args = [(True, self._feature_array_name)] func_name = self.function_name with self._cg.function_definition( name=func_name, args=args, is_scalar_output=expr.output_size == 1): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result, func_name) current_dir = Path(__file__).absolute().parent if self.with_linear_algebra: filename = current_dir / "linear_algebra.bas" self._cg.add_code_lines(get_file_content(filename)) if self.with_atan_expr: filename = current_dir / "atan.bas" self._cg.add_code_lines(get_file_content(filename)) if self.with_log1p_expr: filename = current_dir / "log1p.bas" self._cg.add_code_lines(get_file_content(filename)) if self.with_sigmoid_expr: filename = current_dir / "sigmoid.bas" self._cg.add_code_lines(get_file_content(filename)) if self.with_softmax_expr: filename = current_dir / "softmax.bas" self._cg.add_code_lines(get_file_content(filename)) # Use own Tanh function in order to be compatible with both VB and VBA if self.with_tanh_expr: filename = current_dir / "tanh.bas" self._cg.add_code_lines(get_file_content(filename)) self._cg.prepend_code_line(self._cg.tpl_module_definition( module_name=self.module_name)) self._cg.add_code_line(self._cg.tpl_block_termination( block_name="Module")) return self._cg.finalize_and_get_generated_code()
def interpret(self, expr): self._cg.reset_state() self._reset_reused_expr_cache() args = [(True, self._feature_array_name)] with self._cg.function_definition( name=self.function_name, args=args, is_scalar_output=expr.output_size == 1): last_result = self._do_interpret(expr) self._cg.add_return_statement(last_result) if self.with_linear_algebra: filename = os.path.join(os.path.dirname(__file__), "linear_algebra.go") self._cg.prepend_code_lines(utils.get_file_content(filename)) if self.with_math_module: self._cg.add_dependency("math") return self._cg.finalize_and_get_generated_code()