Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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)
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)
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)
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)
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)))
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))
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)