How to use the m2cgen.ast.PowExpr function in m2cgen

To help you get started, we’ve selected a few m2cgen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BayesWitnesses / m2cgen / tests / interpreters / test_python.py View on Github external
def test_pow_expr():
    expr = ast.PowExpr(ast.NumVal(2.0), ast.NumVal(3.0))

    interpreter = interpreters.PythonInterpreter()

    expected_code = """
import math
def score(input):
    return math.pow(2.0, 3.0)
    """

    utils.assert_code_equal(interpreter.interpret(expr), expected_code)
github BayesWitnesses / m2cgen / tests / assemblers / test_svm.py View on Github external
def _rbf_kernel_ast(estimator, sup_vec_value, to_reuse=False):
    negative_gamma_ast = ast.BinNumExpr(
        ast.NumVal(0),
        ast.NumVal(estimator.gamma),
        ast.BinNumOpType.SUB,
        to_reuse=True)

    return ast.SubroutineExpr(
        ast.ExpExpr(
            ast.BinNumExpr(
                negative_gamma_ast,
                ast.PowExpr(
                    ast.BinNumExpr(
                        ast.NumVal(sup_vec_value),
                        ast.FeatureRef(0),
                        ast.BinNumOpType.SUB),
                    ast.NumVal(2)),
                ast.BinNumOpType.MUL)),
        to_reuse=to_reuse)
github BayesWitnesses / m2cgen / tests / interpreters / test_visual_basic.py View on Github external
def test_pow_expr():
    expr = ast.PowExpr(ast.NumVal(2.0), ast.NumVal(3.0))

    expected_code = """
Module Model
Function score(ByRef input_vector() As Double) As Double
    score = (2.0) ^ (3.0)
End Function
End Module
"""

    interpreter = VisualBasicInterpreter()
    utils.assert_code_equal(interpreter.interpret(expr), expected_code)
github BayesWitnesses / m2cgen / tests / interpreters / test_java.py View on Github external
def test_pow_expr():
    expr = ast.PowExpr(ast.NumVal(2.0), ast.NumVal(3.0))

    interpreter = interpreters.JavaInterpreter()

    expected_code = """
public class Model {

    public static double score(double[] input) {
        return Math.pow(2.0, 3.0);
    }
}"""

    utils.assert_code_equal(interpreter.interpret(expr), expected_code)
github BayesWitnesses / m2cgen / tests / interpreters / test_go.py View on Github external
def test_pow_expr():
    expr = ast.PowExpr(ast.NumVal(2.0), ast.NumVal(3.0))

    interpreter = interpreters.GoInterpreter()

    expected_code = """
import "math"
func score(input []float64) float64 {
    return math.Pow(2.0, 3.0)
}"""

    utils.assert_code_equal(interpreter.interpret(expr), expected_code)
github BayesWitnesses / m2cgen / tests / assemblers / test_svm.py View on Github external
def kernel_ast(sup_vec_value):
        return ast.SubroutineExpr(
            ast.PowExpr(
                ast.BinNumExpr(
                    ast.BinNumExpr(
                        ast.NumVal(estimator.gamma),
                        ast.BinNumExpr(
                            ast.NumVal(sup_vec_value),
                            ast.FeatureRef(0),
                            ast.BinNumOpType.MUL),
                        ast.BinNumOpType.MUL),
                    ast.NumVal(0.0),
                    ast.BinNumOpType.ADD),
                ast.NumVal(estimator.degree)))
github BayesWitnesses / m2cgen / m2cgen / assemblers / svm.py View on Github external
def _poly_kernel(self, support_vector):
        kernel = self._linear_kernel_with_gama_and_coef(support_vector)
        return ast.PowExpr(kernel, ast.NumVal(self.model.degree))
github BayesWitnesses / m2cgen / m2cgen / assemblers / svm.py View on Github external
def _rbf_kernel(self, support_vector):
        elem_wise = [
            ast.PowExpr(
                utils.sub(ast.NumVal(support_element), ast.FeatureRef(i)),
                ast.NumVal(2)
            )
            for i, support_element in enumerate(support_vector)
        ]
        kernel = utils.apply_op_to_expressions(ast.BinNumOpType.ADD,
                                               *elem_wise)
        kernel = utils.mul(self._neg_gamma_expr, kernel)
        return ast.ExpExpr(kernel)