Skip to content

Commit

Permalink
added condassign function + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
b45ch1 committed Feb 17, 2010
1 parent 3f088e0 commit ad3cb7b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
21 changes: 20 additions & 1 deletion adolc/src/py_adolc.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,12 +45,31 @@ bp::dict wrapped_tapestats(short tape_tag){
return retval; return retval;
} }



double wrapped_condassign_double_if(double res, const double cond, const double arg1){ double wrapped_condassign_double_if(double res, const double cond, const double arg1){
printf("cond = %f\n",cond); // printf("res = %f\ncond = %f\narg1=%f",res,cond,arg1);
condassign(res,cond,arg1); condassign(res,cond,arg1);
// printf("after assign res= %f\n",res);
return res;
}

double wrapped_condassign_double_if_else(double res, const double cond, const double arg1, const double arg2){
// printf("res = %f\ncond = %f\narg1=%f\narg2=%f\n",res,cond,arg1,arg2);
condassign(res,cond,arg1,arg2);
// printf("after assign res= %f\n",res);
return res; return res;
} }


adouble wrapped_condassign_adouble_if(adouble &res, const adouble &cond, const adouble &arg1){
condassign(res,cond,arg1);
return res;
}
adouble wrapped_condassign_adouble_if_else(adouble &res, const adouble &cond, const adouble &arg1, const adouble &arg2){
condassign(res,cond,arg1,arg2);
return res;
}




/* C STYLE CALLS OF FUNCTIONS */ /* C STYLE CALLS OF FUNCTIONS */
/* easy to use drivers */ /* easy to use drivers */
Expand Down
4 changes: 3 additions & 1 deletion adolc/src/py_adolc.hpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ BOOST_PYTHON_MODULE(_adolc)
def("log10", adub_log10_badouble, return_value_policy<manage_new_object>() ); def("log10", adub_log10_badouble, return_value_policy<manage_new_object>() );


def("condassign", &wrapped_condassign_double_if); def("condassign", &wrapped_condassign_double_if);

def("condassign", &wrapped_condassign_double_if_else);
def("condassign", &wrapped_condassign_adouble_if);
def("condassign", &wrapped_condassign_adouble_if_else);


class_<badouble>("badouble", init<const badouble &>()) class_<badouble>("badouble", init<const badouble &>())
.def(boost::python::self_ns::str(self)) .def(boost::python::self_ns::str(self))
Expand Down
50 changes: 49 additions & 1 deletion adolc/tests/test_wrapped_functions.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_numpyabs(self):
#test_expression('fabs (a) : ', lambda x: numpy.fabs (x), a, a.val) #test_expression('fabs (a) : ', lambda x: numpy.fabs (x), a, a.val)




def test_condassign(self): def test_double_condassign_if(self):
x = 3. x = 3.
y = 4. y = 4.
cond = 1. cond = 1.
Expand All @@ -186,7 +186,55 @@ def test_condassign(self):
print x print x
assert x == 3. assert x == 3.


def test_double_condassign_if_else(self):
x = 3.
y = 4.
z = 5.
cond = 1.

x = condassign(x,cond,y,z)
assert x == 4.

x = 3.
y = 4.
z = 5.
cond = 0


x = condassign(x,cond,y,z)
assert x == 5


def test_adouble_condassign_if(self):
x = adouble(3.)
y = adouble(4.)
cond = adouble(1.)

x = condassign(x,cond,y)
assert x.val == 4.

x = adouble(3.)
y = adouble(4.)
cond = adouble(0)
x = condassign(x,cond,y)
assert x.val == 3.


def test_adouble_condassign_if_else(self):
x = adouble(3.)
y = adouble(4.)
z = adouble(5.)
cond = adouble(1.)

x = condassign(x,cond,y,z)
assert x.val == 4.

x = adouble(3.)
y = adouble(4.)
z = adouble(5.)
cond = adouble(0.)

x = condassign(x,cond,y,z)
assert x.val == 5


class LowLevelFunctionsTests ( TestCase ): class LowLevelFunctionsTests ( TestCase ):


Expand Down

0 comments on commit ad3cb7b

Please sign in to comment.