SCM

SCM Repository

[matrix] View of /www/doxygen/Csparse_8c-source.html
ViewVC logotype

View of /www/doxygen/Csparse_8c-source.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (download) (as text) (annotate)
Wed Jan 2 17:03:19 2008 UTC (11 years, 8 months ago) by dmbates
File size: 51879 byte(s)
Added doxygen documentation
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Matrix: Csparse.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.3 -->
<div class="tabs">
  <ul>
    <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
    <li class="current"><a href="files.html"><span>Files</span></a></li>
  </ul>
</div>
<h1>Csparse.c</h1><a href="Csparse_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001                         <span class="comment">/* Sparse matrices in compressed column-oriented form */</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include "<a class="code" href="Csparse_8h.html">Csparse.h</a>"</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include "<a class="code" href="chm__common_8h.html">chm_common.h</a>"</span>
<a name="l00004"></a>00004 
<a name="l00005"></a><a class="code" href="Csparse_8h.html#77f654c86c318184ef29b46dc4929e12">00005</a> SEXP <a class="code" href="Csparse_8c.html#77f654c86c318184ef29b46dc4929e12">Csparse_validate</a>(SEXP x)
<a name="l00006"></a>00006 {
<a name="l00007"></a>00007     <span class="comment">/* NB: we do *NOT* check a potential 'x' slot here, at all */</span>
<a name="l00008"></a>00008     SEXP pslot = GET_SLOT(x, <a class="code" href="Syms_8h.html#f08cd6c75b2da4b71c2eb605e00e94ab">Matrix_pSym</a>),
<a name="l00009"></a>00009         islot = GET_SLOT(x, <a class="code" href="Syms_8h.html#900b6b19a8e80b529c1a26eb9fb6156d">Matrix_iSym</a>);
<a name="l00010"></a>00010     Rboolean sorted, strictly;
<a name="l00011"></a>00011     <span class="keywordtype">int</span> j, k,
<a name="l00012"></a>00012         *dims = INTEGER(GET_SLOT(x, <a class="code" href="Syms_8h.html#2b91d011a529c5665e032a6565275374">Matrix_DimSym</a>)),
<a name="l00013"></a>00013         nrow = dims[0],
<a name="l00014"></a>00014         ncol = dims[1],
<a name="l00015"></a>00015         *xp = INTEGER(pslot),
<a name="l00016"></a>00016         *xi = INTEGER(islot);
<a name="l00017"></a>00017 
<a name="l00018"></a>00018     <span class="keywordflow">if</span> (length(pslot) != dims[1] + 1)
<a name="l00019"></a>00019         <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"slot p must have length = ncol(.) + 1"</span>));
<a name="l00020"></a>00020     <span class="keywordflow">if</span> (xp[0] != 0)
<a name="l00021"></a>00021         <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"first element of slot p must be zero"</span>));
<a name="l00022"></a>00022     <span class="keywordflow">if</span> (length(islot) &lt; xp[ncol]) <span class="comment">/* allow larger slots from over-allocation!*/</span>
<a name="l00023"></a>00023         <span class="keywordflow">return</span>
<a name="l00024"></a>00024             mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"last element of slot p must match length of slots i and x"</span>));
<a name="l00025"></a>00025     <span class="keywordflow">for</span> (j = 0; j &lt; length(islot); j++) {
<a name="l00026"></a>00026         <span class="keywordflow">if</span> (xi[j] &lt; 0 || xi[j] &gt;= nrow)
<a name="l00027"></a>00027             <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"all row indices must be between 0 and nrow-1"</span>));
<a name="l00028"></a>00028     }
<a name="l00029"></a>00029     sorted = TRUE; strictly = TRUE;
<a name="l00030"></a>00030     <span class="keywordflow">for</span> (j = 0; j &lt; ncol; j++) {
<a name="l00031"></a>00031         <span class="keywordflow">if</span> (xp[j] &gt; xp[j+1])
<a name="l00032"></a>00032             <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"slot p must be non-decreasing"</span>));
<a name="l00033"></a>00033         <span class="keywordflow">if</span>(sorted)
<a name="l00034"></a>00034             <span class="keywordflow">for</span> (k = xp[j] + 1; k &lt; xp[j + 1]; k++) {
<a name="l00035"></a>00035                 <span class="keywordflow">if</span> (xi[k] &lt; xi[k - 1])
<a name="l00036"></a>00036                     sorted = FALSE;
<a name="l00037"></a>00037                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (xi[k] == xi[k - 1])
<a name="l00038"></a>00038                     strictly = FALSE;
<a name="l00039"></a>00039             }
<a name="l00040"></a>00040     }
<a name="l00041"></a>00041     <span class="keywordflow">if</span> (!sorted) {
<a name="l00042"></a>00042         <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chx = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x);
<a name="l00043"></a>00043         R_CheckStack();
<a name="l00044"></a>00044 
<a name="l00045"></a>00045         cholmod_sort(chx, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00046"></a>00046         <span class="comment">/* Now re-check that row indices are *strictly* increasing</span>
<a name="l00047"></a>00047 <span class="comment">         * (and not just increasing) within each column : */</span>
<a name="l00048"></a>00048         <span class="keywordflow">for</span> (j = 0; j &lt; ncol; j++) {
<a name="l00049"></a>00049             <span class="keywordflow">for</span> (k = xp[j] + 1; k &lt; xp[j + 1]; k++)
<a name="l00050"></a>00050                 <span class="keywordflow">if</span> (xi[k] == xi[k - 1])
<a name="l00051"></a>00051                     <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"slot i is not *strictly* increasing inside a column (even after cholmod_sort)"</span>));
<a name="l00052"></a>00052         }
<a name="l00053"></a>00053 
<a name="l00054"></a>00054     } <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!strictly) {  <span class="comment">/* sorted, but not strictly */</span>
<a name="l00055"></a>00055         <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"slot i is not *strictly* increasing inside a column"</span>));
<a name="l00056"></a>00056     }
<a name="l00057"></a>00057     <span class="keywordflow">return</span> ScalarLogical(1);
<a name="l00058"></a>00058 }
<a name="l00059"></a>00059 
<a name="l00060"></a><a class="code" href="Csparse_8h.html#c732feb976a4c849b0542e99f22d92de">00060</a> SEXP <a class="code" href="Csparse_8c.html#c732feb976a4c849b0542e99f22d92de">Rsparse_validate</a>(SEXP x)
<a name="l00061"></a>00061 {
<a name="l00062"></a>00062     <span class="comment">/* NB: we do *NOT* check a potential 'x' slot here, at all */</span>
<a name="l00063"></a>00063     SEXP pslot = GET_SLOT(x, <a class="code" href="Syms_8h.html#f08cd6c75b2da4b71c2eb605e00e94ab">Matrix_pSym</a>),
<a name="l00064"></a>00064         jslot = GET_SLOT(x, <a class="code" href="Syms_8h.html#92da52e94414e4e2c04f11a6dce844d7">Matrix_jSym</a>);
<a name="l00065"></a>00065     Rboolean sorted, strictly;
<a name="l00066"></a>00066     <span class="keywordtype">int</span> i, k,
<a name="l00067"></a>00067         *dims = INTEGER(GET_SLOT(x, <a class="code" href="Syms_8h.html#2b91d011a529c5665e032a6565275374">Matrix_DimSym</a>)),
<a name="l00068"></a>00068         nrow = dims[0],
<a name="l00069"></a>00069         ncol = dims[1],
<a name="l00070"></a>00070         *xp = INTEGER(pslot),
<a name="l00071"></a>00071         *xj = INTEGER(jslot);
<a name="l00072"></a>00072 
<a name="l00073"></a>00073     <span class="keywordflow">if</span> (length(pslot) != dims[0] + 1)
<a name="l00074"></a>00074         <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"slot p must have length = nrow(.) + 1"</span>));
<a name="l00075"></a>00075     <span class="keywordflow">if</span> (xp[0] != 0)
<a name="l00076"></a>00076         <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"first element of slot p must be zero"</span>));
<a name="l00077"></a>00077     <span class="keywordflow">if</span> (length(jslot) &lt; xp[nrow]) <span class="comment">/* allow larger slots from over-allocation!*/</span>
<a name="l00078"></a>00078         <span class="keywordflow">return</span>
<a name="l00079"></a>00079             mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"last element of slot p must match length of slots j and x"</span>));
<a name="l00080"></a>00080     <span class="keywordflow">for</span> (i = 0; i &lt; length(jslot); i++) {
<a name="l00081"></a>00081         <span class="keywordflow">if</span> (xj[i] &lt; 0 || xj[i] &gt;= ncol)
<a name="l00082"></a>00082             <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"all column indices must be between 0 and ncol-1"</span>));
<a name="l00083"></a>00083     }
<a name="l00084"></a>00084     sorted = TRUE; strictly = TRUE;
<a name="l00085"></a>00085     <span class="keywordflow">for</span> (i = 0; i &lt; nrow; i++) {
<a name="l00086"></a>00086         <span class="keywordflow">if</span> (xp[i] &gt; xp[i+1])
<a name="l00087"></a>00087             <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"slot p must be non-decreasing"</span>));
<a name="l00088"></a>00088         <span class="keywordflow">if</span>(sorted)
<a name="l00089"></a>00089             <span class="keywordflow">for</span> (k = xp[i] + 1; k &lt; xp[i + 1]; k++) {
<a name="l00090"></a>00090                 <span class="keywordflow">if</span> (xj[k] &lt; xj[k - 1])
<a name="l00091"></a>00091                     sorted = FALSE;
<a name="l00092"></a>00092                 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (xj[k] == xj[k - 1])
<a name="l00093"></a>00093                     strictly = FALSE;
<a name="l00094"></a>00094             }
<a name="l00095"></a>00095     }
<a name="l00096"></a>00096     <span class="keywordflow">if</span> (!sorted)
<a name="l00097"></a>00097         <span class="comment">/* cannot easily use cholmod_sort(.) ... -&gt; "error out" :*/</span>
<a name="l00098"></a>00098         <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"slot j is not increasing inside a column"</span>));
<a name="l00099"></a>00099     <span class="keywordflow">else</span> <span class="keywordflow">if</span>(!strictly) <span class="comment">/* sorted, but not strictly */</span>
<a name="l00100"></a>00100         <span class="keywordflow">return</span> mkString(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"slot j is not *strictly* increasing inside a column"</span>));
<a name="l00101"></a>00101 
<a name="l00102"></a>00102     <span class="keywordflow">return</span> ScalarLogical(1);
<a name="l00103"></a>00103 }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105 
<a name="l00106"></a>00106 <span class="comment">/* Called from ../R/Csparse.R : */</span>
<a name="l00107"></a>00107 <span class="comment">/* Can only return [dln]geMatrix (no symm/triang);</span>
<a name="l00108"></a>00108 <span class="comment"> * FIXME: replace by non-CHOLMOD code ! */</span>
<a name="l00109"></a><a class="code" href="Csparse_8h.html#b78e05571230070d4afb830b2e82134c">00109</a> SEXP <a class="code" href="Csparse_8c.html#b78e05571230070d4afb830b2e82134c">Csparse_to_dense</a>(SEXP x)
<a name="l00110"></a>00110 {
<a name="l00111"></a>00111     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chxs = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x);
<a name="l00112"></a>00112     <span class="comment">/* This loses the symmetry property, since cholmod_dense has none,</span>
<a name="l00113"></a>00113 <span class="comment">     * BUT, much worse (FIXME!), it also transforms CHOLMOD_PATTERN ("n") matrices</span>
<a name="l00114"></a>00114 <span class="comment">     * to numeric (CHOLMOD_REAL) ones : */</span>
<a name="l00115"></a>00115     <a class="code" href="chm__common_8h.html#a416c4fbd43f275b63b81b32cff10811">CHM_DN</a> chxd = cholmod_sparse_to_dense(chxs, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00116"></a>00116     <span class="keywordtype">int</span> Rkind = (chxs-&gt;xtype == CHOLMOD_PATTERN)? -1 : <a class="code" href="Mutils_8h.html#d0ec8e93e7bf996d7d4f241f4820c15b">Real_kind</a>(x);
<a name="l00117"></a>00117     R_CheckStack();
<a name="l00118"></a>00118 
<a name="l00119"></a>00119     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#c0552f8d5248824ec90a314b69bd1408" title="Copy the contents of a to an appropriate denseMatrix object and, optionally, free...">chm_dense_to_SEXP</a>(chxd, 1, Rkind, GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>));
<a name="l00120"></a>00120 }
<a name="l00121"></a>00121 
<a name="l00122"></a><a class="code" href="Csparse_8h.html#9e26da2b0832ca4dc2f4cb894705bcdd">00122</a> SEXP <a class="code" href="Csparse_8c.html#9e26da2b0832ca4dc2f4cb894705bcdd">Csparse_to_nz_pattern</a>(SEXP x, SEXP tri)
<a name="l00123"></a>00123 {
<a name="l00124"></a>00124     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chxs = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x);
<a name="l00125"></a>00125     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chxcp = cholmod_copy(chxs, chxs-&gt;stype, CHOLMOD_PATTERN, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00126"></a>00126     <span class="keywordtype">int</span> tr = asLogical(tri);
<a name="l00127"></a>00127     R_CheckStack();
<a name="l00128"></a>00128 
<a name="l00129"></a>00129     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(chxcp, 1<span class="comment">/*do_free*/</span>,
<a name="l00130"></a>00130                               tr ? ((*<a class="code" href="Mutils_8h.html#3a43f83d21f80a9d484da9f2731f76d2">uplo_P</a>(x) == <span class="charliteral">'U'</span>) ? 1 : -1) : 0,
<a name="l00131"></a>00131                               0, tr ? <a class="code" href="Mutils_8h.html#1e1f224c5e72ee3eb2583024db2c59e6">diag_P</a>(x) : <span class="stringliteral">""</span>,
<a name="l00132"></a>00132                               GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>));
<a name="l00133"></a>00133 }
<a name="l00134"></a>00134 
<a name="l00135"></a><a class="code" href="Csparse_8h.html#445c08f7c12195da18d858465511b516">00135</a> SEXP <a class="code" href="Csparse_8c.html#445c08f7c12195da18d858465511b516">Csparse_to_matrix</a>(SEXP x)
<a name="l00136"></a>00136 {
<a name="l00137"></a>00137     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#a63a154e775eded261bf72b8a219de11" title="Copy the contents of a to a matrix object and, optionally, free a or free both a...">chm_dense_to_matrix</a>(cholmod_sparse_to_dense(<a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x), &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>),
<a name="l00138"></a>00138                                1 <span class="comment">/*do_free*/</span>, GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>));
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 
<a name="l00141"></a><a class="code" href="Csparse_8h.html#12b0c242957f1fad9137e767f882e6b8">00141</a> SEXP <a class="code" href="Csparse_8c.html#12b0c242957f1fad9137e767f882e6b8">Csparse_to_Tsparse</a>(SEXP x, SEXP tri)
<a name="l00142"></a>00142 {
<a name="l00143"></a>00143     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chxs = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x);
<a name="l00144"></a>00144     <a class="code" href="chm__common_8h.html#154f615211df9183342deb9c178cedea">CHM_TR</a> chxt = cholmod_sparse_to_triplet(chxs, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00145"></a>00145     <span class="keywordtype">int</span> tr = asLogical(tri);
<a name="l00146"></a>00146     <span class="keywordtype">int</span> Rkind = (chxs-&gt;xtype != CHOLMOD_PATTERN) ? <a class="code" href="Mutils_8h.html#d0ec8e93e7bf996d7d4f241f4820c15b">Real_kind</a>(x) : 0;
<a name="l00147"></a>00147     R_CheckStack();
<a name="l00148"></a>00148 
<a name="l00149"></a>00149     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#b5d31c23691cc4a3c96a7f526dc84006" title="Copy the contents of a to an appropriate TsparseMatrix object and, optionally, free...">chm_triplet_to_SEXP</a>(chxt, 1,
<a name="l00150"></a>00150                                tr ? ((*<a class="code" href="Mutils_8h.html#3a43f83d21f80a9d484da9f2731f76d2">uplo_P</a>(x) == <span class="charliteral">'U'</span>) ? 1 : -1) : 0,
<a name="l00151"></a>00151                                Rkind, tr ? <a class="code" href="Mutils_8h.html#1e1f224c5e72ee3eb2583024db2c59e6">diag_P</a>(x) : <span class="stringliteral">""</span>,
<a name="l00152"></a>00152                                GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>));
<a name="l00153"></a>00153 }
<a name="l00154"></a>00154 
<a name="l00155"></a>00155 <span class="comment">/* this used to be called  sCMatrix_to_gCMatrix(..)   [in ./dsCMatrix.c ]: */</span>
<a name="l00156"></a><a class="code" href="Csparse_8h.html#1fe70f89e424351c54c9bf4ba618ae65">00156</a> SEXP <a class="code" href="Csparse_8c.html#1fe70f89e424351c54c9bf4ba618ae65">Csparse_symmetric_to_general</a>(SEXP x)
<a name="l00157"></a>00157 {
<a name="l00158"></a>00158     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chx = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x), chgx;
<a name="l00159"></a>00159     <span class="keywordtype">int</span> Rkind = (chx-&gt;xtype != CHOLMOD_PATTERN) ? <a class="code" href="Mutils_8h.html#d0ec8e93e7bf996d7d4f241f4820c15b">Real_kind</a>(x) : 0;
<a name="l00160"></a>00160     R_CheckStack();
<a name="l00161"></a>00161 
<a name="l00162"></a>00162     <span class="keywordflow">if</span> (!(chx-&gt;stype))
<a name="l00163"></a>00163         error(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"Nonsymmetric matrix in Csparse_symmetric_to_general"</span>));
<a name="l00164"></a>00164     chgx = cholmod_copy(chx, <span class="comment">/* stype: */</span> 0, chx-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00165"></a>00165     <span class="comment">/* xtype: pattern, "real", complex or .. */</span>
<a name="l00166"></a>00166     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(chgx, 1, 0, Rkind, <span class="stringliteral">""</span>,
<a name="l00167"></a>00167                               GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>));
<a name="l00168"></a>00168 }
<a name="l00169"></a>00169 
<a name="l00170"></a><a class="code" href="Csparse_8h.html#24241833bc1fbb9c17404ee109ef50fd">00170</a> SEXP <a class="code" href="Csparse_8c.html#24241833bc1fbb9c17404ee109ef50fd">Csparse_general_to_symmetric</a>(SEXP x, SEXP uplo)
<a name="l00171"></a>00171 {
<a name="l00172"></a>00172     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chx = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x), chgx;
<a name="l00173"></a>00173     <span class="keywordtype">int</span> uploT = (*CHAR(asChar(uplo)) == <span class="charliteral">'U'</span>) ? 1 : -1;
<a name="l00174"></a>00174     <span class="keywordtype">int</span> Rkind = (chx-&gt;xtype != CHOLMOD_PATTERN) ? <a class="code" href="Mutils_8h.html#d0ec8e93e7bf996d7d4f241f4820c15b">Real_kind</a>(x) : 0;
<a name="l00175"></a>00175     R_CheckStack();
<a name="l00176"></a>00176 
<a name="l00177"></a>00177     chgx = cholmod_copy(chx, <span class="comment">/* stype: */</span> uploT, chx-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00178"></a>00178     <span class="comment">/* xtype: pattern, "real", complex or .. */</span>
<a name="l00179"></a>00179     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(chgx, 1, 0, Rkind, <span class="stringliteral">""</span>,
<a name="l00180"></a>00180                               GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>));
<a name="l00181"></a>00181 }
<a name="l00182"></a>00182 
<a name="l00183"></a><a class="code" href="Csparse_8h.html#ab695b6af65c32eac1776cf04c661518">00183</a> SEXP <a class="code" href="Csparse_8c.html#ab695b6af65c32eac1776cf04c661518">Csparse_transpose</a>(SEXP x, SEXP tri)
<a name="l00184"></a>00184 {
<a name="l00185"></a>00185     <span class="comment">/* TODO: lgCMatrix &amp; igC* currently go via double prec. cholmod -</span>
<a name="l00186"></a>00186 <span class="comment">     *       since cholmod (&amp; cs) lacks sparse 'int' matrices */</span>
<a name="l00187"></a>00187     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chx = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x);
<a name="l00188"></a>00188     <span class="keywordtype">int</span> Rkind = (chx-&gt;xtype != CHOLMOD_PATTERN) ? <a class="code" href="Mutils_8h.html#d0ec8e93e7bf996d7d4f241f4820c15b">Real_kind</a>(x) : 0;
<a name="l00189"></a>00189     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chxt = cholmod_transpose(chx, chx-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00190"></a>00190     SEXP dn = PROTECT(duplicate(GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>))), tmp;
<a name="l00191"></a>00191     <span class="keywordtype">int</span> tr = asLogical(tri);
<a name="l00192"></a>00192     R_CheckStack();
<a name="l00193"></a>00193 
<a name="l00194"></a>00194     tmp = VECTOR_ELT(dn, 0);    <span class="comment">/* swap the dimnames */</span>
<a name="l00195"></a>00195     SET_VECTOR_ELT(dn, 0, VECTOR_ELT(dn, 1));
<a name="l00196"></a>00196     SET_VECTOR_ELT(dn, 1, tmp);
<a name="l00197"></a>00197     UNPROTECT(1);
<a name="l00198"></a>00198     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(chxt, 1, <span class="comment">/* SWAP 'uplo' for triangular */</span>
<a name="l00199"></a>00199                               tr ? ((*<a class="code" href="Mutils_8h.html#3a43f83d21f80a9d484da9f2731f76d2">uplo_P</a>(x) == <span class="charliteral">'U'</span>) ? -1 : 1) : 0,
<a name="l00200"></a>00200                               Rkind, tr ? <a class="code" href="Mutils_8h.html#1e1f224c5e72ee3eb2583024db2c59e6">diag_P</a>(x) : <span class="stringliteral">""</span>, dn);
<a name="l00201"></a>00201 }
<a name="l00202"></a>00202 
<a name="l00203"></a><a class="code" href="Csparse_8h.html#8414bce86d0916499c2d63f70728176b">00203</a> SEXP <a class="code" href="Csparse_8c.html#8414bce86d0916499c2d63f70728176b">Csparse_Csparse_prod</a>(SEXP a, SEXP b)
<a name="l00204"></a>00204 {
<a name="l00205"></a>00205     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> cha = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(a), chb = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(b);
<a name="l00206"></a>00206     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chc = cholmod_ssmult(cha, chb, 0, cha-&gt;xtype, 1, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00207"></a>00207     SEXP dn = allocVector(VECSXP, 2);
<a name="l00208"></a>00208     R_CheckStack();
<a name="l00209"></a>00209 
<a name="l00210"></a>00210     SET_VECTOR_ELT(dn, 0,       <span class="comment">/* establish dimnames */</span>
<a name="l00211"></a>00211                    duplicate(VECTOR_ELT(GET_SLOT(a, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>), 0)));
<a name="l00212"></a>00212     SET_VECTOR_ELT(dn, 1,
<a name="l00213"></a>00213                    duplicate(VECTOR_ELT(GET_SLOT(b, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>), 1)));
<a name="l00214"></a>00214     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(chc, 1, 0, 0, <span class="stringliteral">""</span>, dn);
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216 
<a name="l00217"></a><a class="code" href="Csparse_8h.html#6c4e110d10721580b2b43969800dfdb2">00217</a> SEXP <a class="code" href="Csparse_8c.html#6c4e110d10721580b2b43969800dfdb2">Csparse_Csparse_crossprod</a>(SEXP a, SEXP b, SEXP trans)
<a name="l00218"></a>00218 {
<a name="l00219"></a>00219     <span class="keywordtype">int</span> tr = asLogical(trans);
<a name="l00220"></a>00220     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> cha = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(a), chb = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(b), chTr, chc;
<a name="l00221"></a>00221     SEXP dn = allocVector(VECSXP, 2);
<a name="l00222"></a>00222     R_CheckStack();
<a name="l00223"></a>00223 
<a name="l00224"></a>00224     chTr = cholmod_transpose((tr) ? chb : cha, chb-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00225"></a>00225     chc = cholmod_ssmult((tr) ? cha : chTr, (tr) ? chTr : chb,
<a name="l00226"></a>00226                          0, cha-&gt;xtype, 1, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00227"></a>00227     cholmod_free_sparse(&amp;chTr, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00228"></a>00228 
<a name="l00229"></a>00229     SET_VECTOR_ELT(dn, 0,       <span class="comment">/* establish dimnames */</span>
<a name="l00230"></a>00230                    duplicate(VECTOR_ELT(GET_SLOT(a, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>), (tr) ? 0 : 1)));
<a name="l00231"></a>00231     SET_VECTOR_ELT(dn, 1,
<a name="l00232"></a>00232                    duplicate(VECTOR_ELT(GET_SLOT(b, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>), (tr) ? 0 : 1)));
<a name="l00233"></a>00233     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(chc, 1, 0, 0, <span class="stringliteral">""</span>, dn);
<a name="l00234"></a>00234 }
<a name="l00235"></a>00235 
<a name="l00236"></a><a class="code" href="Csparse_8h.html#fec5dcac16fd72028456b98704632f1e">00236</a> SEXP <a class="code" href="Csparse_8c.html#fec5dcac16fd72028456b98704632f1e">Csparse_dense_prod</a>(SEXP a, SEXP b)
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> cha = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(a);
<a name="l00239"></a>00239     SEXP b_M = PROTECT(<a class="code" href="Mutils_8h.html#460951a1f5dadb579d977ba114eec12e">mMatrix_as_dgeMatrix</a>(b));
<a name="l00240"></a>00240     <a class="code" href="chm__common_8h.html#a416c4fbd43f275b63b81b32cff10811">CHM_DN</a> chb = <a class="code" href="chm__common_8h.html#aa0424486b25ff64e947e1946f1c1b2c">AS_CHM_DN</a>(b_M);
<a name="l00241"></a>00241     <a class="code" href="chm__common_8h.html#a416c4fbd43f275b63b81b32cff10811">CHM_DN</a> chc = cholmod_allocate_dense(cha-&gt;nrow, chb-&gt;ncol, cha-&gt;nrow,
<a name="l00242"></a>00242                                         chb-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00243"></a>00243     SEXP dn = PROTECT(allocVector(VECSXP, 2));
<a name="l00244"></a>00244     <span class="keywordtype">double</span> one[] = {1,0}, zero[] = {0,0};
<a name="l00245"></a>00245     R_CheckStack();
<a name="l00246"></a>00246 
<a name="l00247"></a>00247     cholmod_sdmult(cha, 0, one, zero, chb, chc, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00248"></a>00248     SET_VECTOR_ELT(dn, 0,       <span class="comment">/* establish dimnames */</span>
<a name="l00249"></a>00249                    duplicate(VECTOR_ELT(GET_SLOT(a, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>), 0)));
<a name="l00250"></a>00250     SET_VECTOR_ELT(dn, 1,
<a name="l00251"></a>00251                    duplicate(VECTOR_ELT(GET_SLOT(b_M, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>), 1)));
<a name="l00252"></a>00252     UNPROTECT(2);
<a name="l00253"></a>00253     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#c0552f8d5248824ec90a314b69bd1408" title="Copy the contents of a to an appropriate denseMatrix object and, optionally, free...">chm_dense_to_SEXP</a>(chc, 1, 0, dn);
<a name="l00254"></a>00254 }
<a name="l00255"></a>00255 
<a name="l00256"></a><a class="code" href="Csparse_8h.html#ef1a61ab6f25436301b8ee835106c23b">00256</a> SEXP <a class="code" href="Csparse_8c.html#ef1a61ab6f25436301b8ee835106c23b">Csparse_dense_crossprod</a>(SEXP a, SEXP b)
<a name="l00257"></a>00257 {
<a name="l00258"></a>00258     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> cha = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(a);
<a name="l00259"></a>00259     SEXP b_M = PROTECT(<a class="code" href="Mutils_8h.html#460951a1f5dadb579d977ba114eec12e">mMatrix_as_dgeMatrix</a>(b));
<a name="l00260"></a>00260     <a class="code" href="chm__common_8h.html#a416c4fbd43f275b63b81b32cff10811">CHM_DN</a> chb = <a class="code" href="chm__common_8h.html#aa0424486b25ff64e947e1946f1c1b2c">AS_CHM_DN</a>(b_M);
<a name="l00261"></a>00261     <a class="code" href="chm__common_8h.html#a416c4fbd43f275b63b81b32cff10811">CHM_DN</a> chc = cholmod_allocate_dense(cha-&gt;ncol, chb-&gt;ncol, cha-&gt;ncol,
<a name="l00262"></a>00262                                         chb-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00263"></a>00263     SEXP dn = PROTECT(allocVector(VECSXP, 2));
<a name="l00264"></a>00264     <span class="keywordtype">double</span> one[] = {1,0}, zero[] = {0,0};
<a name="l00265"></a>00265     R_CheckStack();
<a name="l00266"></a>00266 
<a name="l00267"></a>00267     cholmod_sdmult(cha, 1, one, zero, chb, chc, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00268"></a>00268     SET_VECTOR_ELT(dn, 0,       <span class="comment">/* establish dimnames */</span>
<a name="l00269"></a>00269                    duplicate(VECTOR_ELT(GET_SLOT(a, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>), 1)));
<a name="l00270"></a>00270     SET_VECTOR_ELT(dn, 1,
<a name="l00271"></a>00271                    duplicate(VECTOR_ELT(GET_SLOT(b_M, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>), 1)));
<a name="l00272"></a>00272     UNPROTECT(2);
<a name="l00273"></a>00273     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#c0552f8d5248824ec90a314b69bd1408" title="Copy the contents of a to an appropriate denseMatrix object and, optionally, free...">chm_dense_to_SEXP</a>(chc, 1, 0, dn);
<a name="l00274"></a>00274 }
<a name="l00275"></a>00275 
<a name="l00276"></a>00276 <span class="comment">/* Computes   x'x  or  x x'  -- see Csparse_Csparse_crossprod above for  x'y and x y' */</span>
<a name="l00277"></a><a class="code" href="Csparse_8h.html#407589b56b662830f7a14b251a8c4da3">00277</a> SEXP <a class="code" href="Csparse_8c.html#407589b56b662830f7a14b251a8c4da3">Csparse_crossprod</a>(SEXP x, SEXP trans, SEXP triplet)
<a name="l00278"></a>00278 {
<a name="l00279"></a>00279     <span class="keywordtype">int</span> trip = asLogical(triplet),
<a name="l00280"></a>00280         tr   = asLogical(trans); <span class="comment">/* gets reversed because _aat is tcrossprod */</span>
<a name="l00281"></a>00281     <a class="code" href="chm__common_8h.html#154f615211df9183342deb9c178cedea">CHM_TR</a> cht = trip ? <a class="code" href="chm__common_8h.html#0de4ac732ba359948e3b377352f99b97">AS_CHM_TR</a>(x) : (<a class="code" href="chm__common_8h.html#154f615211df9183342deb9c178cedea">CHM_TR</a>) NULL;
<a name="l00282"></a>00282     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chcp, chxt,
<a name="l00283"></a>00283         chx = trip ? cholmod_triplet_to_sparse(cht, cht-&gt;nnz, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>) : <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x);
<a name="l00284"></a>00284     SEXP dn = PROTECT(allocVector(VECSXP, 2));
<a name="l00285"></a>00285     R_CheckStack();
<a name="l00286"></a>00286 
<a name="l00287"></a>00287     <span class="keywordflow">if</span> (!tr) chxt = cholmod_transpose(chx, chx-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00288"></a>00288     chcp = cholmod_aat((!tr) ? chxt : chx, (<span class="keywordtype">int</span> *) NULL, 0, chx-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00289"></a>00289     <span class="keywordflow">if</span>(!chcp) error(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"Csparse_crossprod(): error return from cholmod_aat()"</span>));
<a name="l00290"></a>00290     cholmod_band_inplace(0, chcp-&gt;ncol, chcp-&gt;xtype, chcp, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00291"></a>00291     chcp-&gt;stype = 1;
<a name="l00292"></a>00292     <span class="keywordflow">if</span> (trip) cholmod_free_sparse(&amp;chx, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00293"></a>00293     <span class="keywordflow">if</span> (!tr) cholmod_free_sparse(&amp;chxt, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00294"></a>00294     SET_VECTOR_ELT(dn, 0,       <span class="comment">/* establish dimnames */</span>
<a name="l00295"></a>00295                    duplicate(VECTOR_ELT(GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>),
<a name="l00296"></a>00296                                         (tr) ? 0 : 1)));
<a name="l00297"></a>00297     SET_VECTOR_ELT(dn, 1, duplicate(VECTOR_ELT(dn, 0)));
<a name="l00298"></a>00298     UNPROTECT(1);
<a name="l00299"></a>00299     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(chcp, 1, 0, 0, <span class="stringliteral">""</span>, dn);
<a name="l00300"></a>00300 }
<a name="l00301"></a>00301 
<a name="l00302"></a><a class="code" href="Csparse_8h.html#1d165b31075f32ee0ca273f51c13f9df">00302</a> SEXP <a class="code" href="Csparse_8c.html#1d165b31075f32ee0ca273f51c13f9df">Csparse_drop</a>(SEXP x, SEXP tol)
<a name="l00303"></a>00303 {
<a name="l00304"></a>00304     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chx = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x);
<a name="l00305"></a>00305     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> ans = cholmod_copy(chx, chx-&gt;stype, chx-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00306"></a>00306     <span class="keywordtype">double</span> dtol = asReal(tol);
<a name="l00307"></a>00307     <span class="keywordtype">int</span> Rkind = (chx-&gt;xtype != CHOLMOD_PATTERN) ? <a class="code" href="Mutils_8h.html#d0ec8e93e7bf996d7d4f241f4820c15b">Real_kind</a>(x) : 0;
<a name="l00308"></a>00308     R_CheckStack();
<a name="l00309"></a>00309 
<a name="l00310"></a>00310     <span class="keywordflow">if</span>(!cholmod_drop(dtol, ans, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>))
<a name="l00311"></a>00311         error(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"cholmod_drop() failed"</span>));
<a name="l00312"></a>00312     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(ans, 1, 0, Rkind, <span class="stringliteral">""</span>,
<a name="l00313"></a>00313                               GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>));
<a name="l00314"></a>00314 }
<a name="l00315"></a>00315 
<a name="l00316"></a><a class="code" href="Csparse_8h.html#8973a306b51dbd6b2b66b21185bf048a">00316</a> SEXP <a class="code" href="Csparse_8c.html#8973a306b51dbd6b2b66b21185bf048a">Csparse_horzcat</a>(SEXP x, SEXP y)
<a name="l00317"></a>00317 {
<a name="l00318"></a>00318     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chx = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x), chy = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(y);
<a name="l00319"></a>00319     <span class="keywordtype">int</span> Rkind = 0; <span class="comment">/* only for "d" - FIXME */</span>
<a name="l00320"></a>00320     R_CheckStack();
<a name="l00321"></a>00321 
<a name="l00322"></a>00322     <span class="comment">/* FIXME: currently drops dimnames */</span>
<a name="l00323"></a>00323     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(cholmod_horzcat(chx, chy, 1, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>),
<a name="l00324"></a>00324                               1, 0, Rkind, <span class="stringliteral">""</span>, R_NilValue);
<a name="l00325"></a>00325 }
<a name="l00326"></a>00326 
<a name="l00327"></a><a class="code" href="Csparse_8h.html#913d061ccf8536244aae6b7157c105f1">00327</a> SEXP <a class="code" href="Csparse_8c.html#913d061ccf8536244aae6b7157c105f1">Csparse_vertcat</a>(SEXP x, SEXP y)
<a name="l00328"></a>00328 {
<a name="l00329"></a>00329     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chx = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x), chy = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(y);
<a name="l00330"></a>00330     <span class="keywordtype">int</span> Rkind = 0; <span class="comment">/* only for "d" - FIXME */</span>
<a name="l00331"></a>00331     R_CheckStack();
<a name="l00332"></a>00332 
<a name="l00333"></a>00333     <span class="comment">/* FIXME: currently drops dimnames */</span>
<a name="l00334"></a>00334     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(cholmod_vertcat(chx, chy, 1, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>),
<a name="l00335"></a>00335                               1, 0, Rkind, <span class="stringliteral">""</span>, R_NilValue);
<a name="l00336"></a>00336 }
<a name="l00337"></a>00337 
<a name="l00338"></a><a class="code" href="Csparse_8h.html#546eddc63011f2f2af462894dbec7dc9">00338</a> SEXP <a class="code" href="Csparse_8c.html#546eddc63011f2f2af462894dbec7dc9">Csparse_band</a>(SEXP x, SEXP k1, SEXP k2)
<a name="l00339"></a>00339 {
<a name="l00340"></a>00340     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chx = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x);
<a name="l00341"></a>00341     <span class="keywordtype">int</span> Rkind = (chx-&gt;xtype != CHOLMOD_PATTERN) ? <a class="code" href="Mutils_8h.html#d0ec8e93e7bf996d7d4f241f4820c15b">Real_kind</a>(x) : 0;
<a name="l00342"></a>00342     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> ans = cholmod_band(chx, asInteger(k1), asInteger(k2), chx-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00343"></a>00343     R_CheckStack();
<a name="l00344"></a>00344 
<a name="l00345"></a>00345     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(ans, 1, 0, Rkind, <span class="stringliteral">""</span>,
<a name="l00346"></a>00346                               GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>));
<a name="l00347"></a>00347 }
<a name="l00348"></a>00348 
<a name="l00349"></a><a class="code" href="Csparse_8h.html#0cc8d2f7047736ee111b11cb2faeaf11">00349</a> SEXP <a class="code" href="Csparse_8c.html#0cc8d2f7047736ee111b11cb2faeaf11">Csparse_diagU2N</a>(SEXP x)
<a name="l00350"></a>00350 {
<a name="l00351"></a>00351     <span class="keywordflow">if</span> (*<a class="code" href="Mutils_8h.html#1e1f224c5e72ee3eb2583024db2c59e6">diag_P</a>(x) != <span class="charliteral">'U'</span>) {<span class="comment">/* "trivially fast" when there's no 'diag' slot at all */</span>
<a name="l00352"></a>00352         <span class="keywordflow">return</span> (x);
<a name="l00353"></a>00353     }
<a name="l00354"></a>00354     <span class="keywordflow">else</span> {
<a name="l00355"></a>00355         <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chx = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x);
<a name="l00356"></a>00356         <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> eye = cholmod_speye(chx-&gt;nrow, chx-&gt;ncol, chx-&gt;xtype, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00357"></a>00357         <span class="keywordtype">double</span> one[] = {1, 0};
<a name="l00358"></a>00358         <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> ans = cholmod_add(chx, eye, one, one, TRUE, TRUE, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00359"></a>00359         <span class="keywordtype">int</span> uploT = (*<a class="code" href="Mutils_8h.html#3a43f83d21f80a9d484da9f2731f76d2">uplo_P</a>(x) == <span class="charliteral">'U'</span>) ? 1 : -1;
<a name="l00360"></a>00360         <span class="keywordtype">int</span> Rkind = (chx-&gt;xtype != CHOLMOD_PATTERN) ? <a class="code" href="Mutils_8h.html#d0ec8e93e7bf996d7d4f241f4820c15b">Real_kind</a>(x) : 0;
<a name="l00361"></a>00361 
<a name="l00362"></a>00362         R_CheckStack();
<a name="l00363"></a>00363         cholmod_free_sparse(&amp;eye, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>);
<a name="l00364"></a>00364         <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(ans, 1, uploT, Rkind, <span class="stringliteral">"N"</span>,
<a name="l00365"></a>00365                                   GET_SLOT(x, <a class="code" href="Syms_8h.html#93d8b8a3cd9c897599b3e2d996821a0b">Matrix_DimNamesSym</a>));
<a name="l00366"></a>00366     }
<a name="l00367"></a>00367 }
<a name="l00368"></a>00368 
<a name="l00369"></a><a class="code" href="Csparse_8h.html#bfee8cfe834c57a1bb2144ee157b83dc">00369</a> SEXP <a class="code" href="Csparse_8c.html#bfee8cfe834c57a1bb2144ee157b83dc">Csparse_submatrix</a>(SEXP x, SEXP i, SEXP j)
<a name="l00370"></a>00370 {
<a name="l00371"></a>00371     <a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a> chx = <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x);
<a name="l00372"></a>00372     <span class="keywordtype">int</span> rsize = (isNull(i)) ? -1 : LENGTH(i),
<a name="l00373"></a>00373         csize = (isNull(j)) ? -1 : LENGTH(j);
<a name="l00374"></a>00374     <span class="keywordtype">int</span> Rkind = (chx-&gt;xtype != CHOLMOD_PATTERN) ? <a class="code" href="Mutils_8h.html#d0ec8e93e7bf996d7d4f241f4820c15b">Real_kind</a>(x) : 0;
<a name="l00375"></a>00375     R_CheckStack();
<a name="l00376"></a>00376 
<a name="l00377"></a>00377     <span class="keywordflow">if</span> (rsize &gt;= 0 &amp;&amp; !isInteger(i))
<a name="l00378"></a>00378         error(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"Index i must be NULL or integer"</span>));
<a name="l00379"></a>00379     <span class="keywordflow">if</span> (csize &gt;= 0 &amp;&amp; !isInteger(j))
<a name="l00380"></a>00380         error(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"Index j must be NULL or integer"</span>));
<a name="l00381"></a>00381 
<a name="l00382"></a>00382     <span class="keywordflow">return</span> <a class="code" href="chm__common_8c.html#7aa1a6e564c24a55b031b5c03b3313f4" title="Copy the contents of a to an appropriate CsparseMatrix object and, optionally, free...">chm_sparse_to_SEXP</a>(cholmod_submatrix(chx, INTEGER(i), rsize,
<a name="l00383"></a>00383                                                 INTEGER(j), csize,
<a name="l00384"></a>00384                                                 TRUE, TRUE, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>),
<a name="l00385"></a>00385                               1, 0, Rkind, <span class="stringliteral">""</span>,
<a name="l00386"></a>00386                               <span class="comment">/* FIXME: drops dimnames */</span> R_NilValue);
<a name="l00387"></a>00387 }
<a name="l00388"></a>00388 
<a name="l00389"></a><a class="code" href="Csparse_8h.html#0ff90b74963cd2db63b8cc7542d5aa96">00389</a> SEXP <a class="code" href="Csparse_8c.html#0ff90b74963cd2db63b8cc7542d5aa96">Csparse_MatrixMarket</a>(SEXP x, SEXP fname)
<a name="l00390"></a>00390 {
<a name="l00391"></a>00391     FILE *f = fopen(CHAR(asChar(fname)), <span class="stringliteral">"w"</span>);
<a name="l00392"></a>00392 
<a name="l00393"></a>00393     <span class="keywordflow">if</span> (!f)
<a name="l00394"></a>00394         error(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"failure to open file \"%s\" for writing"</span>),
<a name="l00395"></a>00395               CHAR(asChar(fname)));
<a name="l00396"></a>00396     <span class="keywordflow">if</span> (!cholmod_write_sparse(f, <a class="code" href="chm__common_8h.html#181c1e5f964ecab945a22c5309500afd">AS_CHM_SP</a>(x), (<a class="code" href="chm__common_8h.html#1a47b00141f8a86eb3d071242cdec825">CHM_SP</a>)NULL,
<a name="l00397"></a>00397                               (<span class="keywordtype">char</span>*) NULL, &amp;<a class="code" href="chm__common_8c.html#c2b5dcf1f18e620b15b2e284dd9f6bd4">c</a>))
<a name="l00398"></a>00398         error(<a class="code" href="Mutils_8h.html#32a3cf3d9dd914f5aeeca5423c157934">_</a>(<span class="stringliteral">"cholmod_write_sparse returned error code"</span>));
<a name="l00399"></a>00399     fclose(f);
<a name="l00400"></a>00400     <span class="keywordflow">return</span> R_NilValue;
<a name="l00401"></a>00401 }
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Wed Jan 2 09:19:08 2008 for Matrix by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>

root@r-forge.r-project.org
ViewVC Help
Powered by ViewVC 1.0.0  
Thanks to:
Vienna University of Economics and Business Powered By FusionForge