Skip to content
Browse files

added a another sparse_hess_no_repeat_test

  • Loading branch information...
1 parent 4c3f794 commit faeaa38014919b384c8daf57d18d03fe4160e60f @b45ch1 committed
Showing with 43 additions and 0 deletions.
  1. +43 −0 adolc/colpack/tests/test_wrapped_functions.py
View
43 adolc/colpack/tests/test_wrapped_functions.py
@@ -115,6 +115,48 @@ def scalar_f2(x):
for i in range(10):
result = colpack.sparse_hess_no_repeat(2, x2, options)
+
+
+ def test_sparse_hess_2(self):
+ """ This example was reported to raise a seg fault (see https://github.com/b45ch1/pyadolc/issues/10) """
+
+ N = 3
+
+ def F(x):
+ y = numpy.sum(x**2)
+ return y
+
+ x = numpy.random.rand(N)
+
+ # Trace F
+ trace_on(0)
+ x = adouble(x)
+ independent(x)
+ y = F(x)
+ dependent(y)
+ trace_off()
+
+ x = numpy.random.rand(N)
+ options = numpy.array([0,1],dtype=int)
+ result = colpack.sparse_hess_no_repeat(0,x,options)
+
+ nnz = numpy.asarray(result[0],dtype=int)
+ rind = numpy.asarray(result[1],dtype=int)
+ cind = numpy.asarray(result[2],dtype=int)
+ values = numpy.asarray(result[3],dtype=float)
+
+
+ print "Sparse hessian:"
+ print "nnz:", nnz
+ print "rind:", rind
+ print "cind:", cind
+ print "values:", values
+
+ assert_array_almost_equal(nnz, N)
+ assert_array_almost_equal(rind, numpy.arange(N))
+ assert_array_almost_equal(cind, numpy.arange(N))
+ assert_array_almost_equal(values, [2]*N)
+
def test_sparse_hess_repeat(self):
N = 3 # dimension
@@ -327,6 +369,7 @@ def eval_h_adolc(x, lagrange, obj_factor, flag, user_data = None):
assert_array_almost_equal( H, H_adolc.T)
+
if __name__ == '__main__':
try:
import nose

0 comments on commit faeaa38

Please sign in to comment.
Something went wrong with that request. Please try again.