@@ -20,7 +20,7 @@ using ADOLC::Sparse::RecoveryMethod;
2020 identifies and recovers only the diagonal nonzero entries.
2121
2222 The function is:
23- f(x) = Σ_ {i=0}^{4} [ sin(x_i) + (x_{i+10})^2 ]
23+ f(x) = sum_ {i=0}^{4} [ sin(x_i) + (x_{i+10})^2 ]
2424
2525 Analytical Hessian (expected):
2626 For i = 0,... , 4:
@@ -106,7 +106,6 @@ static void testSparseHessWithDiagonal(short tapeId) {
106106 // we only have diagonal elements
107107 BOOST_TEST (rowIndices[i] == columnIndices[i]);
108108 }
109-
110109 // test with rowIndices, columnIndices and sparseValues != nullptr
111110 ADOLC::Sparse::sparse_hess<CFM, RCM>(tapeId, dimIn, 0 , in.data (),
112111 &numberOfNonzeros, &rowIndices,
@@ -127,7 +126,6 @@ static void testSparseHessWithDiagonal(short tapeId) {
127126 // we only have diagonal elements
128127 BOOST_TEST (rowIndices[i] == columnIndices[i]);
129128 }
130-
131129 // test with repeat == 1
132130 ADOLC::Sparse::sparse_hess<CFM, RCM>(tapeId, dimIn, 1 , in.data (),
133131 &numberOfNonzeros, &rowIndices,
@@ -148,7 +146,9 @@ static void testSparseHessWithDiagonal(short tapeId) {
148146 // we only have diagonal elements
149147 BOOST_TEST (rowIndices[i] == columnIndices[i]);
150148 }
151- delete sparseValues;
149+ delete[] sparseValues;
150+ delete[] columnIndices;
151+ delete[] rowIndices;
152152 for (auto &h : hess)
153153 delete[] h;
154154}
@@ -164,7 +164,6 @@ BOOST_AUTO_TEST_CASE(SparseHessSafeIndirect) {
164164 testSparseHessWithDiagonal<ControlFlowMode::Safe, RecoveryMethod::Indirect>(
165165 tapeId);
166166}
167-
168167BOOST_AUTO_TEST_CASE (SparseHessTightDirect) {
169168 const short tapeId = 634 ;
170169 testSparseHessWithDiagonal<ControlFlowMode::Tight, RecoveryMethod::Direct>(
@@ -200,7 +199,6 @@ BOOST_AUTO_TEST_CASE(SparseHessOldTightIndirect) {
200199 testSparseHessWithDiagonal<ControlFlowMode::OldTight,
201200 RecoveryMethod::Indirect>(tapeId);
202201}
203-
204202/*
205203 This test constructs a function with mixed-product terms so that the Hessian
206204 contains off-diagonal nonzeros.
@@ -314,15 +312,15 @@ static void testSparseHessWithOffDiagonals(short tapeId) {
314312 delete[] rowIndices;
315313 delete[] columnIndices;
316314 delete[] sparseValues;
317- for (auto &ptr : hess)
318- delete[] ptr ;
315+ for (auto &h : hess)
316+ delete[] h ;
319317}
320-
321318BOOST_AUTO_TEST_CASE (SparseHessNonDiagSafeDirect) {
322319 const short tapeId = 700 ;
323320 testSparseHessWithOffDiagonals<ControlFlowMode::Safe, RecoveryMethod::Direct>(
324321 tapeId);
325322}
323+
326324BOOST_AUTO_TEST_CASE (SparseHessNonDiagSafeIndirect) {
327325 const short tapeId = 701 ;
328326 testSparseHessWithOffDiagonals<ControlFlowMode::Safe,
@@ -435,6 +433,9 @@ static void testSparseHessPatWithDiagonal(short tapeId) {
435433 BOOST_TEST (compressedRowStorage[17 ][0 ] == 0 );
436434 BOOST_TEST (compressedRowStorage[18 ][0 ] == 0 );
437435 BOOST_TEST (compressedRowStorage[19 ][0 ] == 0 );
436+
437+ for (auto & crs: compressedRowStorage)
438+ delete[] crs;
438439}
439440
440441BOOST_AUTO_TEST_CASE (SparseHessPatDiagSafe) {
@@ -519,6 +520,9 @@ static void testSparseHessPatWithOffDiagonal(short tapeId) {
519520 // sixth hessian row has fifth
520521 BOOST_TEST (compressedRowStorage[5 ][0 ] == 1 );
521522 BOOST_TEST (compressedRowStorage[5 ][1 ] == 4 );
523+
524+ for (auto & crs: compressedRowStorage)
525+ delete[] crs;
522526}
523527
524528BOOST_AUTO_TEST_CASE (SparseHessPatOffDiagSafe) {
@@ -540,5 +544,4 @@ BOOST_AUTO_TEST_CASE(SparseHessPatOffDiagOldTight) {
540544 const short tapeId = 715 ;
541545 testSparseHessPatWithOffDiagonal<ControlFlowMode::OldTight>(tapeId);
542546}
543-
544- BOOST_AUTO_TEST_SUITE_END ()
547+ BOOST_AUTO_TEST_SUITE_END ()
0 commit comments