Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added condassign function + tests

  • Loading branch information...
commit ad3cb7b8242175582d6a766f1166c015d841e144 1 parent 3f088e0
Sebastian F. Walter authored
21 adolc/src/py_adolc.cpp
View
@@ -45,12 +45,31 @@ bp::dict wrapped_tapestats(short tape_tag){
return retval;
}
+
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);
+ // 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;
}
+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 */
/* easy to use drivers */
4 adolc/src/py_adolc.hpp
View
@@ -268,7 +268,9 @@ BOOST_PYTHON_MODULE(_adolc)
def("log10", adub_log10_badouble, return_value_policy<manage_new_object>() );
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 &>())
.def(boost::python::self_ns::str(self))
50 adolc/tests/test_wrapped_functions.py
View
@@ -171,7 +171,7 @@ def test_numpyabs(self):
#test_expression('fabs (a) : ', lambda x: numpy.fabs (x), a, a.val)
- def test_condassign(self):
+ def test_double_condassign_if(self):
x = 3.
y = 4.
cond = 1.
@@ -186,7 +186,55 @@ def test_condassign(self):
print x
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 ):
Please sign in to comment.
Something went wrong with that request. Please try again.