Permalink
Browse files

added an experimental_tests.py file to run some tests that are likely…

… to be trouble

improved the tape equivalence example: uses the <<= operator to reduce the num_max_lives
adouble( adub(x)) now works
  • Loading branch information...
1 parent de419cb commit ce06df9c0efb8f004f722fdd4174093e1773c234 @b45ch1 committed Jul 14, 2009
View
@@ -45,8 +45,9 @@ def adouble(x):
"""
if numpy.isscalar(x):
return _adolc.adouble(float(x))
- elif isinstance(x,_adolc.adouble):
+ elif isinstance(x,_adolc.adouble) or isinstance(x,_adolc.adub):
return _adolc.adouble(x)
+
else:
x = numpy.asarray(x, dtype=float)
shp = numpy.shape(x)
View
@@ -1,2 +1,5 @@
jac_pat.mtx
-!*.png
+!*.png
+
+*.tap
+tape_0.tex
@@ -0,0 +1,30 @@
+import numpy
+from adolc import *
+def test_big_tape():
+ """
+ Hmm, this should raise an error because num_max_lives is bigger than the value buffer
+ """
+ N = 65534*4
+
+ ay = adouble(0.)
+ ax = adouble(0.)
+ x = 1.
+
+ # usual way: leads to increasing locints
+ trace_on(0)
+ independent(ax)
+ ay = ax
+ for i in range(N):
+ ay = ay * ay
+
+ dependent(ay)
+ trace_off()
+
+ print tapestats(0)
+ print function(0,[1.])
+ #tape_to_latex(0,numpy.array([1.]),numpy.array([0.]))
+
+
+
+if __name__ == "__main__":
+ test_big_tape()
@@ -0,0 +1,25 @@
+adolc_include_path = '/home/basti/workspace/adolc-2.0.0'
+adolc_library_path = '/home/basti/workspace/adolc-2.0.0/adolc/.libs'
+
+LIBS = ['adolc',
+ ]
+LIBPATH = [
+ adolc_library_path,
+ ]
+INCLUDEPATH = [
+ adolc_include_path,
+ '/usr/include/python2.5'
+ ]
+
+
+env = Environment(
+ CPPPATH = INCLUDEPATH,
+ CXXFLAGS= "-ftemplate-depth-100 -Wall -O2",
+ LIBPATH =LIBPATH,
+ LIBS = LIBS,
+ RPATH = LIBPATH, #include information where shared libraries can be found to avoid errors like: "ImportError: libboost_python-gcc42-mt-1_34_1.so.1.34.1: cannot open shared object file: No such file or directory"
+ SHLIBPREFIX="", #gets rid of lib prefix, i.e. get mylib.so instead of libmylib.so
+)
+Default('.')
+my_executable = env.Program(target='benchmark.exe', source=['benchmark.cpp'])
+
@@ -24,6 +24,9 @@ def benchmark(f,N,M,message):
dependent(ay)
trace_off()
#tape_to_latex(1,x,y)
+
+ print 'N=%d,M=%d'%(N,M)
+
runtime_taping = time.time() - start_time
print 'PyADOLC\tfunction taping:\t........\telapsed time: %f'%runtime_taping
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from adolc import *
import numpy as npy
-
N = 20
ay = adouble(0.)
@@ -20,25 +19,19 @@
# if necessary: call the garbage collector and therefore start with smaller locints
-del(ay)
del(ax)
-ay = adouble(0.)
-ax = adouble(0.)
+del(ay)
x = 1.
-tmpay = adouble(0.)
trace_on(10)
-ax.is_independent(x)
+ax = adouble(1.)
+independent(ax)
ay = ax
for i in range(N):
- ay = ay * ay
- if i%1 == 0:
- tmpay <<= ay
- del(ay)
- ay = tmpay
-
-depends_on(ay)
+ ay <<= ay * ay
+
+dependent(ay)
trace_off()
tape_to_latex(9,npy.array([x]),npy.array([0]))
View
@@ -168,7 +168,7 @@ def test_dependent():
bx = dependent(ax)
assert numpy.prod( ax == bx )
-
+
def test_hov_ti_reverse():
"""compute the first columnt of the hessian of f = x_1 x_2 x_3"""
@@ -818,6 +818,11 @@ def eval_h_adolc(x, lagrange, obj_factor, flag, user_data = None):
H_adolc = H_adolc.todense()
assert_array_almost_equal( H, H_adolc.T)
+
+
+
+
+
#def test_gradient_and_jacobian_and_hessian():

0 comments on commit ce06df9

Please sign in to comment.