Permalink
Browse files

fixed the memory leak problem of _adolc.so.

Memory is now allocated in Python.

removed hov_wk_forward because it is unclear what exactly is going on there
  • Loading branch information...
1 parent e5b07e0 commit de419cbed84bf418287cbb88b828f907dec15eca basti committed Jul 13, 2009
Showing with 360 additions and 142 deletions.
  1. +262 −74 adolc.py
  2. +9 −0 jac_pat.mtx
  3. +39 −0 py_adolc.cpp
  4. +43 −32 py_adolc.hpp
  5. +1 −0 py_colpack.hpp
  6. +3 −0 tests/comparison_pycppad_pyadolc/pure_cpp_cppad_adolc_comparison.cpp
  7. +3 −7 tests/jac_pat.mtx
  8. +0 −29 tests/unit_test.py
View
336 adolc.py

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,9 @@
+2 4 8
+1 1 0
+1 2 1
+1 3 2
+1 4 3
+2 1 4
+2 2 5
+2 3 6
+2 4 7
View
@@ -679,6 +679,45 @@ void c_wrapped_hov_reverse (short tape_tag, int M, int N, int D, int Q, bpn::ar
}
+void c_wrapped_hov_ti_reverse (short tape_tag, int M, int N, int D, int Q, bpn::array &bpn_U, bpn::array &bpn_Z, bpn::array &bpn_nz){
+
+ /* U is (Q, M, D+1) matrix */
+ double* U_data = (double*) nu::data(bpn_U);
+ double** U[Q];
+ double* U1[Q*M];
+
+ for( int qn = 0; qn != Q*M; ++qn){
+ U1[qn] = &U_data[qn * (D+1)];
+ }
+
+ for(int q = 0; q != Q; ++q){
+ U[q] = &U1[ q * M];
+ }
+
+ /* Z is (Q, N, D+1) matrix */
+ double* Z_data = (double*) nu::data(bpn_Z);
+ double** Z[Q];
+ double* Z1[Q*N];
+
+ for( int qn = 0; qn != Q*N; ++qn){
+ Z1[qn] = &Z_data[qn * (D+1)];
+ }
+
+ for(int q = 0; q != Q; ++q){
+ Z[q] = &Z1[ q * N];
+ }
+
+ /* nz is (Q,N) matrix */
+ short* nz_data = (short*) nu::data(bpn_nz);
+ short* nz[Q];
+ for(int q = 0; q != Q; ++q){
+ nz[q] = &nz_data[ q * N];
+ }
+
+ hov_ti_reverse(tape_tag, M, N, D, Q, U, Z, nz);
+
+}
+
View
@@ -11,6 +11,12 @@ namespace bp = boost::python;
namespace bpn = boost::python::numeric;
namespace nu = num_util;
+
+int get_size_of_short(){ return static_cast<int>(sizeof(short)); }
+int get_size_of_int(){ return static_cast<int>(sizeof(int)); }
+int get_size_of_long(){ return static_cast<int>(sizeof(long)); }
+
+
extern adub exp ( const badouble& );
extern adub log ( const badouble& );
extern adub sqrt ( const badouble& );
@@ -199,36 +205,40 @@ BOOST_PYTHON_MODULE(_adolc)
bpn::array::set_module_and_type("numpy", "ndarray"); /* some kind of hack to get numpy working */
scope().attr("__doc__") ="unused: moved docstring to adolc.py";
+
+ def("get_size_of_short", get_size_of_short);
+ def("get_size_of_int", get_size_of_int);
+ def("get_size_of_long", get_size_of_long);
+
def("trace_on",trace_on_default_argument);
def("trace_off",trace_off_default_argument);
- def("function", &wrapped_function);
- def("gradient", &wrapped_gradient);
- def("hessian", &wrapped_hessian);
- def("jacobian", &wrapped_jacobian);
- def("vec_jac", &wrapped_vec_jac);
- def("jac_vec", &wrapped_jac_vec);
- def("hess_vec", &wrapped_hess_vec);
- def("lagra_hess_vec", &wrapped_lagra_hess_vec);
-// def("jac_solv", &wrapped_jac_solv, "(void*)lagra_hess_vec(tape_tag,x,b,sparse=0,mode=2):\nsolve F'(x) b_new - b = 0 , F:R^N -> R^M\n"); /* buggy ! */
-
- def("zos_forward", &wrapped_zos_forward);
- def("fos_forward", &wrapped_fos_forward);
- def("fov_forward", &wrapped_fov_forward);
- def("hos_forward", &wrapped_hos_forward);
- def("hov_forward", &wrapped_hov_forward);
-
- def("hov_wk_forward", &wrapped_hov_wk_forward);
+// def("function", &wrapped_function);
+// def("gradient", &wrapped_gradient);
+// def("hessian", &wrapped_hessian);
+// def("jacobian", &wrapped_jacobian);
+// def("vec_jac", &wrapped_vec_jac);
+// def("jac_vec", &wrapped_jac_vec);
+// def("hess_vec", &wrapped_hess_vec);
+// def("lagra_hess_vec", &wrapped_lagra_hess_vec);
+
+// def("zos_forward", &wrapped_zos_forward);
+// def("fos_forward", &wrapped_fos_forward);
+// def("fov_forward", &wrapped_fov_forward);
+// def("hos_forward", &wrapped_hos_forward);
+// def("hov_forward", &wrapped_hov_forward);
+
+// def("hov_wk_forward", &wrapped_hov_wk_forward);
- def("fos_reverse", &wrapped_fos_reverse);
+// def("fos_reverse", &wrapped_fos_reverse);
- def("fov_reverse", &wrapped_fov_reverse);
+// def("fov_reverse", &wrapped_fov_reverse);
- def("hos_reverse", &wrapped_hos_reverse);
- def("hov_reverse", &wrapped_hov_reverse);
+// def("hos_reverse", &wrapped_hos_reverse);
+// def("hov_reverse", &wrapped_hov_reverse);
- def("hov_ti_reverse", &wrapped_hov_ti_reverse);
+// def("hov_ti_reverse", &wrapped_hov_ti_reverse);
/* c style functions */
@@ -242,19 +252,20 @@ BOOST_PYTHON_MODULE(_adolc)
def("lagra_hess_vec", &c_wrapped_lagra_hess_vec);
// def("jac_solv", &c_wrapped_jac_solv); /* buggy ! */
-// def("zos_forward", &c_wrapped_zos_forward);
-// def("fos_forward", &c_wrapped_fos_forward);
-// def("fov_forward", &c_wrapped_fov_forward);
-// def("hos_forward", &c_wrapped_hos_forward);
-// def("hov_forward", &c_wrapped_hov_forward);
+ def("zos_forward", &c_wrapped_zos_forward);
+ def("fos_forward", &c_wrapped_fos_forward);
+ def("fov_forward", &c_wrapped_fov_forward);
+ def("hos_forward", &c_wrapped_hos_forward);
+ def("hov_forward", &c_wrapped_hov_forward);
// def("hov_wk_forward", &c_wrapped_hov_wk_forward);
-// def("fos_reverse", &c_wrapped_fos_reverse);
-// def("fov_reverse", &c_wrapped_fov_reverse);
-// def("hos_reverse", &c_wrapped_hos_reverse);
-// def("hov_reverse", &c_wrapped_hov_reverse);
-
+ def("fos_reverse", &c_wrapped_fos_reverse);
+ def("fov_reverse", &c_wrapped_fov_reverse);
+ def("hos_reverse", &c_wrapped_hos_reverse);
+ def("hov_reverse", &c_wrapped_hov_reverse);
+ def("hov_ti_reverse", &c_wrapped_hov_ti_reverse);
+
def("depends_on", &depends_on);
def("tape_to_latex", py_tape_doc);
View
@@ -23,6 +23,7 @@ namespace nu = num_util;
+
bp::list wrapped_jac_pat(short tape_tag, bpn::array &bpn_x, bpn::array &bpn_options);
bp::list wrapped_sparse_jac_no_repeat(short tape_tag, bpn::array &bpn_x, bpn::array &bpn_options);
bp::list wrapped_sparse_jac_repeat(short tape_tag, bpn::array &bpn_x, npy_intp nnz, bpn::array &bpn_rind, bpn::array &bpn_cind, bpn::array &bpn_values);
@@ -0,0 +1,3 @@
+# include <cppad/cppad.hpp>
+
+# include <cppad/vector.hpp>
View
@@ -1,9 +1,5 @@
-2 4 8
+2 3 4
1 1 0
1 2 1
-1 3 2
-1 4 3
-2 1 4
-2 2 5
-2 3 6
-2 4 7
+2 2 2
+2 3 3
View
@@ -169,35 +169,6 @@ def test_dependent():
assert numpy.prod( ax == bx )
-def test_hov_wk_forward():
- """ hov_wk_forward is necessary to propagate multiple directions of Taylor coefficients"""
- def f(x):
- return numpy.sum(x)
- N = 10
- P = N
- D = 2
- keep = N+1
-
- x = numpy.ones(N)
- ax = adouble(x)
-
- trace_on(17)
- independent(ax)
- ay = f(ax)
- dependent(ay)
- trace_off()
-
- # directions V
- V = numpy.ones((N,P,D))
- (y,W) = hov_wk_forward(17, x, V, keep)
-
- print y
- print W
-
- # need to improve this test!
- true_W = 10.*numpy.ones((1,P,D))
- assert_almost_equal(10.,y)
- assert_array_almost_equal(true_W, W)
def test_hov_ti_reverse():
"""compute the first columnt of the hessian of f = x_1 x_2 x_3"""

0 comments on commit de419cb

Please sign in to comment.