Permalink
Browse files

refactored sparse_jac_no_repeat and sparse_hess_repeat: the memory of…

… cind, rind and values are now overwritten (no new memory is allocated)
  • Loading branch information...
b45ch1 committed Feb 7, 2012
1 parent f41dc15 commit 4c3f79422e882e7cf85704d2421027bbe91ca1bb
View
@@ -7,7 +7,7 @@ Short Description:
It wraps the functionality of the library ADOL-C (C++).
Author:
- Sebastian F. Walter
+ Sebastian F. Walter
Licence (new BSD):
Copyright (c) 2008, Sebastian F. Walter
@@ -36,7 +36,7 @@ Licence (new BSD):
EXAMPLE USAGE::
-
+
import numpy
from adolc import *
N = M = 10
@@ -68,15 +68,18 @@ REQUIREMENTS:
* Python and Numpy, both with header files
* ADOL-C version 2.1.0 http://www.coin-or.org/projects/ADOL-C.xml
* boost::python from http://www.boost.org/
- * scons build tool
OPTIONAL REQUIREMENTS:
* For sparse Jacobians and Hessians: ColPack 1.0.0 http://www.cscapes.org/coloringpage/software.htm
+ * scons build tool (makes things easier if you need to recompile pyadolc)
INSTALLATION:
* CHECK REQUIREMENTS: Make sure you have ADOL-C (version 2.1 and above), ColPack (version 1.0.0 and above) the boost libraries and numpy installed. All with header files.
- * BUILD ADOL-C:
+ * BUILD COLPACK
+ * run ``make``
+ * this should generate ``~workspace/ColPack/build/lib/libColPack.so``.
+ * BUILD ADOL-C:
* run ``./configure --enable-sparse --with-colpack=/home/b45ch1/workspace/ColPack/build``
* run ``make``
* You don't have to run ``make install``.
@@ -88,8 +91,8 @@ INSTALLATION:
* run ``python setup.py build``. A new folder with a name similar to ``~/pyadolc/build/lib.linux-x86_64-2.6`` should be generated.
* run ``python setup.py install`` to install pyadolc to your system.
* TEST YOUR INSTALLATION:
- * Change directory to ``~/pyadolc/build/lib.linux-x86_64-2.6``
+ * Change directory to ``~/pyadolc/build/lib.linux-x86_64-2.6``
* run ``python -c "import adolc; adolc.test()"``. All tests should pass.
* You can also use scons (if you have it) instead of using setup.py
* If anything goes wrong, please file a bug report.
-
+
@@ -9,7 +9,7 @@ bp::list wrapped_sparse_jac_no_repeat(short tape_tag, bpn::array &bpn_x, bpn::ar
double* x = (double*) nu::data(bpn_x);
int* options = (int*) nu::data(bpn_options);
// int options[4] = {1,1,0,0};
-
+
int nnz=-1;
unsigned int *rind = NULL;
@@ -51,19 +51,11 @@ bp::list wrapped_sparse_jac_repeat(short tape_tag, bpn::array &bpn_x, npy_intp n
sparse_jac(tape_tag, M, N, 1, x, &tmp_nnz, &rind, &cind, &values, options);
- bp::object bp_rind ( bp::handle<>(PyArray_SimpleNewFromData(1, &nnz, PyArray_INT, (char*) rind )));
- bp::object bp_cind ( bp::handle<>(PyArray_SimpleNewFromData(1, &nnz, PyArray_INT, (char*) cind )));
- bp::object bp_values ( bp::handle<>(PyArray_SimpleNewFromData(1, &nnz, PyArray_DOUBLE, (char*) values )));
-
- bpn::array ret_rind = boost::python::extract<boost::python::numeric::array>(bp_rind);
- bpn::array ret_cind = boost::python::extract<boost::python::numeric::array>(bp_cind);
- bpn::array ret_values = boost::python::extract<boost::python::numeric::array>(bp_values);
-
bp::list retvals;
retvals.append(nnz);
- retvals.append(ret_rind);
- retvals.append(ret_cind);
- retvals.append(ret_values);
+ retvals.append(bpn_rind);
+ retvals.append(bpn_cind);
+ retvals.append(bpn_values);
return retvals;
@@ -118,19 +110,11 @@ bp::list wrapped_sparse_hess_repeat(short tape_tag, bpn::array &bpn_x, npy_intp
sparse_hess(tape_tag, N, 1, x, &tmp_nnz, &rind, &cind, &values, options);
- bp::object bp_rind ( bp::handle<>(PyArray_SimpleNewFromData(1, &nnz, PyArray_INT, (char*) rind )));
- bp::object bp_cind ( bp::handle<>(PyArray_SimpleNewFromData(1, &nnz, PyArray_INT, (char*) cind )));
- bp::object bp_values ( bp::handle<>(PyArray_SimpleNewFromData(1, &nnz, PyArray_DOUBLE, (char*) values )));
-
- bpn::array ret_rind = boost::python::extract<boost::python::numeric::array>(bp_rind);
- bpn::array ret_cind = boost::python::extract<boost::python::numeric::array>(bp_cind);
- bpn::array ret_values = boost::python::extract<boost::python::numeric::array>(bp_values);
-
bp::list retvals;
retvals.append(nnz);
- retvals.append(ret_rind);
- retvals.append(ret_cind);
- retvals.append(ret_values);
+ retvals.append(bpn_rind);
+ retvals.append(bpn_cind);
+ retvals.append(bpn_values);
return retvals;
Oops, something went wrong.

0 comments on commit 4c3f794

Please sign in to comment.