コード例 #1
0
 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))
コード例 #2
0
 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))
コード例 #3
0
 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))
コード例 #4
0
 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))
コード例 #5
0
 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))
コード例 #6
0
 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))
コード例 #7
0
 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))
コード例 #8
0
 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))
コード例 #9
0
 def recover_memory(self):
     """Generate code to call stan::math::recover_memory()"""
     return self._add_statement(statement_types.FunctionCall("stan::math::recover_memory", None))