def recursive_sum(self, arg): """ Generate code that repeatedly sums arg until all that is left is a scalar :param arg: Argument to sum """ return self._add_statement(statement_types.FunctionCall("stan::test::recursive_sum", "summed_result" + self._get_next_name_suffix(), arg))
def to_var_value(self, arg): """ Generate code to convert arg to a varmat :param arg: Argument to convert to varmat """ return self._add_statement(statement_types.FunctionCall("stan::math::to_var_value", arg.name + "_varmat" + self._get_next_name_suffix(), arg))
def grad(self, arg): """ Generate code to call stan::test::grad(arg) (equivalent of arg.grad()) :param arg: Argument to call grad on """ return self._add_statement(statement_types.FunctionCall("stan::test::grad", None, arg))
def function_call_assign(self, cpp_function_name, *args): """ Generate code to call the c++ function given by cpp_function_name with given args and assign the result to another variable :param cpp_function_name: c++ function name to call :param args: list of arguments to pass to function """ return self._add_statement(statement_types.FunctionCall(cpp_function_name, "result" + self._get_next_name_suffix(), *args))
def expect_leq_one(self, arg): """ Generate code to check that arg is less than or equal to one :param arg: Argument to check """ one = self._add_statement(statement_types.IntVariable("int" + self._get_next_name_suffix(), 1)) return self._add_statement(statement_types.FunctionCall("EXPECT_LE", None, arg, one))
def expect_eq(self, arg1, arg2): """ Generate code that checks that values of arg1 and arg2 are equal :param arg1: First argument :param arg2: Second argument """ return self._add_statement(statement_types.FunctionCall("EXPECT_STAN_EQ", None, arg1, arg2))
def expect_adj_eq(self, arg1, arg2): """ Generate code that checks that the adjoints of arg1 and arg2 are equal :param arg1: First argument :param arg2: Second argument """ return self._add_statement(statement_types.FunctionCall("stan::test::expect_adj_eq", None, arg1, arg2))
def add(self, arg1, arg2): """ Generate code for arg1 + arg2 :param arg1: First argument :param arg1: Second argument """ return self._add_statement(statement_types.FunctionCall("stan::math::add", "sum_of_sums" + self._get_next_name_suffix(), arg1, arg2))
def recover_memory(self): """Generate code to call stan::math::recover_memory()""" return self._add_statement(statement_types.FunctionCall("stan::math::recover_memory", None))