<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>If we only want to support one format, this triplet format can work. &nbsp;It is intuitive, and there are routines available to convert to and from CSC and CSR formats. &nbsp;</div><div><br></div><div>I do have a question about how the Jacobian is returned. &nbsp;If I understand the code correctly, CppAD allocates new memory for a new Jacobian/Hessian every time the function is called. &nbsp;If I am repeatedly computing gradients and Hessians, this is an awful lot of dynamic memory allocation. &nbsp;Wouldn't it be more efficient for the user to allocate memory for the output, and then pass in a pointer or reference for that array?</div><div><br></div><div>In that case, the call would be something like:</div><div><br></div><div>f.SparseJacobian(x, p, r, c, *out)</div><div><br></div><div>Also, will the SparseJacobian / SparseMatrix functions still need to allocate a full m-by-n matrix internally? &nbsp;The value of a sparse matrix algorithm is not just that the matrix is return in a sparse format, but the algorithm itself exploits the sparseness in terms of its memory usage.</div><div><br></div><div><br><blockquote type="cite"><div><br><br> &nbsp;&nbsp;1. Sparse Hessians and Jacobians (Brad Bell)<br><br><br>----------------------------------------------------------------------<br><br>Message: 1<br>Date: Tue, 08 May 2012 07:45:05 -0700<br>From: Brad Bell &lt;<a href="mailto:bradbell@seanet.com">bradbell@seanet.com</a>&gt;<br>To: <a href="mailto:CppAD@list.coin-or.org">CppAD@list.coin-or.org</a><br>Subject: [CppAD] Sparse Hessians and Jacobians<br>Message-ID: &lt;<a href="mailto:4FA93171.5040207@seanet.com">4FA93171.5040207@seanet.com</a>&gt;<br>Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br><br>I am considering adding sparse Jacobian and Hessians returns to CppAD as <br>per the sparsity discussion under<br> &nbsp;&nbsp;&nbsp;&nbsp;<a href="http://list.coin-or.org/pipermail/cppad/2012q1/thread.html">http://list.coin-or.org/pipermail/cppad/2012q1/thread.html</a><br><br>Reading over the discussion, it seems to me that the format used by <br>ADOL-C is reasonable; i.e. three vectors rind[], cind[], and values[] <br>all of the same length could be used to represent Sparse Hessians and <br>Jacobians (where the corresponding element types are size_t, size_t, and <br>Base).<br><br>For example, the sparse Jacobian driver<br> &nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.coin-or.org/CppAD/Doc/sparse_jacobian.xml">http://www.coin-or.org/CppAD/Doc/sparse_jacobian.xml</a><br>could be extended to have the syntax<br> &nbsp;&nbsp;&nbsp;&nbsp;jac = f.SparseJacobian(x, p, r, c)<br>where<br> &nbsp;&nbsp;&nbsp;&nbsp;x is the point where the Jacobian is being evaluated<br> &nbsp;&nbsp;&nbsp;&nbsp;p is the CppAD sparsity pattern (for the entire Jacobian)<br> &nbsp;&nbsp;&nbsp;&nbsp;r is the row indices<br> &nbsp;&nbsp;&nbsp;&nbsp;c is the column indices<br> &nbsp;&nbsp;&nbsp;&nbsp;jac is the Jacobian values at the corresponding row and column indices.<br><br>Note that the sparsity pattern p can be computed by either<br> &nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.coin-or.org/CppAD/Doc/forsparsejac.xml">http://www.coin-or.org/CppAD/Doc/forsparsejac.xml</a><br> &nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.coin-or.org/CppAD/Doc/revsparsejac.xml">http://www.coin-or.org/CppAD/Doc/revsparsejac.xml</a><br>Then the users can decide which non-zero indices they want back and in <br>what order. For example, if the Jacobian is know to be symmetric, one <br>only needs to ask for the upper or lower triangle.<br><br>A similar approach be used for the sparse Hessians.<br> &nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.coin-or.org/CppAD/Doc/sparse_hessian.xml">http://www.coin-or.org/CppAD/Doc/sparse_hessian.xml</a><br><br><br><br>------------------------------<br><br>_______________________________________________<br>CppAD mailing list<br><a href="mailto:CppAD@list.coin-or.org">CppAD@list.coin-or.org</a><br>http://list.coin-or.org/mailman/listinfo/cppad<br><br><br>End of CppAD Digest, Vol 56, Issue 1<br>************************************<br></div></blockquote></div><br><div apple-content-edited="true">
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; ">Michael Braun&nbsp;<br>MIT Sloan School of Management<br><a href="mailto:braunm@mit.edu">braunm@mit.edu</a><br>--------------------------------------------------&nbsp;<br>View my research at<br>http://braunm.scripts.mit.edu/</span>
</div>
<br></body></html>