Sophie

Sophie

distrib > Fedora > 16 > i386 > by-pkgid > 4bc66056a634db26a1f4d0845dc41ca6 > files > 2127

mrpt-doc-0.9.5-0.1.20110925svn2670.fc16.i686.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>CSparseMatrix.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<div align="left"><a href="http://www.mrpt.org/">Main MRPT website</a> &gt; <b>C++ reference</b> </div>
<div align="right">
<a href="index.html"><img border="0" src="mrpt_logo.png" alt="MRPT logo"></a>
</div>
<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
          <div class="left">
            <form id="FSearchBox" action="search.php" method="get">
              <img id="MSearchSelect" src="search/mag.png" alt=""/>
              <input type="text" id="MSearchField" name="query" value="Search" size="20" accesskey="S" 
                     onfocus="searchBox.OnSearchFieldFocus(true)" 
                     onblur="searchBox.OnSearchFieldFocus(false)"/>
            </form>
          </div><div class="right"></div>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">CSparseMatrix.h</div>  </div>
</div>
<div class="contents">
<a href="_c_sparse_matrix_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* +---------------------------------------------------------------------------+</span>
<a name="l00002"></a>00002 <span class="comment">   |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |</span>
<a name="l00003"></a>00003 <span class="comment">   |                                                                           |</span>
<a name="l00004"></a>00004 <span class="comment">   |                       http://www.mrpt.org/                                |</span>
<a name="l00005"></a>00005 <span class="comment">   |                                                                           |</span>
<a name="l00006"></a>00006 <span class="comment">   |   Copyright (C) 2005-2011  University of Malaga                           |</span>
<a name="l00007"></a>00007 <span class="comment">   |                                                                           |</span>
<a name="l00008"></a>00008 <span class="comment">   |    This software was written by the Machine Perception and Intelligent    |</span>
<a name="l00009"></a>00009 <span class="comment">   |      Robotics Lab, University of Malaga (Spain).                          |</span>
<a name="l00010"></a>00010 <span class="comment">   |    Contact: Jose-Luis Blanco  &lt;jlblanco@ctima.uma.es&gt;                     |</span>
<a name="l00011"></a>00011 <span class="comment">   |                                                                           |</span>
<a name="l00012"></a>00012 <span class="comment">   |  This file is part of the MRPT project.                                   |</span>
<a name="l00013"></a>00013 <span class="comment">   |                                                                           |</span>
<a name="l00014"></a>00014 <span class="comment">   |     MRPT is free software: you can redistribute it and/or modify          |</span>
<a name="l00015"></a>00015 <span class="comment">   |     it under the terms of the GNU General Public License as published by  |</span>
<a name="l00016"></a>00016 <span class="comment">   |     the Free Software Foundation, either version 3 of the License, or     |</span>
<a name="l00017"></a>00017 <span class="comment">   |     (at your option) any later version.                                   |</span>
<a name="l00018"></a>00018 <span class="comment">   |                                                                           |</span>
<a name="l00019"></a>00019 <span class="comment">   |   MRPT is distributed in the hope that it will be useful,                 |</span>
<a name="l00020"></a>00020 <span class="comment">   |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |</span>
<a name="l00021"></a>00021 <span class="comment">   |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |</span>
<a name="l00022"></a>00022 <span class="comment">   |     GNU General Public License for more details.                          |</span>
<a name="l00023"></a>00023 <span class="comment">   |                                                                           |</span>
<a name="l00024"></a>00024 <span class="comment">   |     You should have received a copy of the GNU General Public License     |</span>
<a name="l00025"></a>00025 <span class="comment">   |     along with MRPT.  If not, see &lt;http://www.gnu.org/licenses/&gt;.         |</span>
<a name="l00026"></a>00026 <span class="comment">   |                                                                           |</span>
<a name="l00027"></a>00027 <span class="comment">   +---------------------------------------------------------------------------+ */</span>
<a name="l00028"></a>00028 <span class="preprocessor">#ifndef CSparseMatrix_H</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define CSparseMatrix_H</span>
<a name="l00030"></a>00030 <span class="preprocessor"></span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;<a class="code" href="utils__defs_8h.html">mrpt/utils/utils_defs.h</a>&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;<a class="code" href="exceptions_8h.html">mrpt/utils/exceptions.h</a>&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;<a class="code" href="_c_uncopiable_8h.html">mrpt/utils/CUncopiable.h</a>&gt;</span>
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;<a class="code" href="math__frwds_8h.html">mrpt/math/math_frwds.h</a>&gt;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &lt;<a class="code" href="_c_sparse_matrix_template_8h.html">mrpt/math/CSparseMatrixTemplate.h</a>&gt;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &lt;<a class="code" href="_c_matrix_template_numeric_8h.html">mrpt/math/CMatrixTemplateNumeric.h</a>&gt;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &lt;<a class="code" href="_c_matrix_fixed_numeric_8h.html">mrpt/math/CMatrixFixedNumeric.h</a>&gt;</span>
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 <span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span>{
<a name="l00041"></a>00041 <span class="preprocessor">#include &lt;<a class="code" href="cs_8h.html">mrpt/otherlibs/CSparse/cs.h</a>&gt;</span>
<a name="l00042"></a>00042 }
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 <span class="keyword">namespace </span>mrpt
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046         <span class="keyword">namespace </span>math
<a name="l00047"></a>00047         {<span class="comment"></span>
<a name="l00048"></a>00048 <span class="comment">                /** Used in mrpt::math::CSparseMatrix */</span>
<a name="l00049"></a>00049                 <span class="keyword">class </span>CExceptionNotDefPos : <span class="keyword">public</span> mrpt::utils::CMRPTException
<a name="l00050"></a>00050                 {
<a name="l00051"></a>00051                 <span class="keyword">public</span>:
<a name="l00052"></a><a class="code" href="classmrpt_1_1math_1_1_c_exception_not_def_pos.html#a7f4d479f8726dbb189431ad00d18164d">00052</a>                         <a class="code" href="classmrpt_1_1math_1_1_c_exception_not_def_pos.html#a7f4d479f8726dbb189431ad00d18164d">CExceptionNotDefPos</a>(<span class="keyword">const</span> <a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a> &amp;s) : <a class="code" href="classmrpt_1_1utils_1_1_c_m_r_p_t_exception.html" title="The base for MRPT-especific exceptions.">CMRPTException</a>(s) {  }
<a name="l00053"></a>00053                 };
<a name="l00054"></a>00054 
<a name="l00055"></a>00055 <span class="comment"></span>
<a name="l00056"></a>00056 <span class="comment">                /** A sparse matrix capable of efficient math operations (a wrapper around the CSparse library)</span>
<a name="l00057"></a>00057 <span class="comment">                  *  The type of cells is fixed to &quot;double&quot;.</span>
<a name="l00058"></a>00058 <span class="comment">                  *</span>
<a name="l00059"></a>00059 <span class="comment">                  *  There are two main formats for the non-zero entries in this matrix:</span>
<a name="l00060"></a>00060 <span class="comment">                  *             - A &quot;triplet&quot; matrix: a set of (r,c)=val triplet entries.</span>
<a name="l00061"></a>00061 <span class="comment">                  *             - A column-compressed sparse matrix.</span>
<a name="l00062"></a>00062 <span class="comment">                  *</span>
<a name="l00063"></a>00063 <span class="comment">                  *  The latter is the &quot;normal&quot; format, which is expected by most mathematical operations defined</span>
<a name="l00064"></a>00064 <span class="comment">                  *   in this class. There&#39;re two three ways of initializing and populating a sparse matrix:</span>
<a name="l00065"></a>00065 <span class="comment">                  *</span>
<a name="l00066"></a>00066 <span class="comment">                  *   &lt;ol&gt;</span>
<a name="l00067"></a>00067 <span class="comment">                  *    &lt;li&gt; &lt;b&gt;As a triplet (empty), then add entries, then compress:&lt;/b&gt;</span>
<a name="l00068"></a>00068 <span class="comment">                  *         \code</span>
<a name="l00069"></a>00069 <span class="comment">                  *             CSparseMatrix  SM(100,100);</span>
<a name="l00070"></a>00070 <span class="comment">                  *             SM.insert_entry(i,j, val);  // or</span>
<a name="l00071"></a>00071 <span class="comment">                  *             SM.insert_submatrix(i,j, MAT); //  ...</span>
<a name="l00072"></a>00072 <span class="comment">                  *             SM.compressFromTriplet();</span>
<a name="l00073"></a>00073 <span class="comment">                  *         \endcode</span>
<a name="l00074"></a>00074 <span class="comment">                  *    &lt;/li&gt;</span>
<a name="l00075"></a>00075 <span class="comment">                  *    &lt;li&gt; &lt;b&gt;As a triplet from a CSparseMatrixTemplate&lt;double&gt;:&lt;/b&gt;</span>
<a name="l00076"></a>00076 <span class="comment">                  *         \code</span>
<a name="l00077"></a>00077 <span class="comment">                  *             CSparseMatrixTemplate&lt;double&gt;  data;</span>
<a name="l00078"></a>00078 <span class="comment">                  *             data(row,col) = val;</span>
<a name="l00079"></a>00079 <span class="comment">                  *             ...</span>
<a name="l00080"></a>00080 <span class="comment">                  *             CSparseMatrix  SM(data);</span>
<a name="l00081"></a>00081 <span class="comment">                  *         \endcode</span>
<a name="l00082"></a>00082 <span class="comment">                  *    &lt;/li&gt;</span>
<a name="l00083"></a>00083 <span class="comment">                  *    &lt;li&gt; &lt;b&gt;From an existing dense matrix:&lt;/b&gt;</span>
<a name="l00084"></a>00084 <span class="comment">                  *         \code</span>
<a name="l00085"></a>00085 <span class="comment">                  *             CMatrixDouble data(100,100); // or</span>
<a name="l00086"></a>00086 <span class="comment">                  *             CMatrixFloat  data(100,100); // or</span>
<a name="l00087"></a>00087 <span class="comment">                  *             CMatrixFixedNumeric&lt;double,4,6&gt;  data; // etc...</span>
<a name="l00088"></a>00088 <span class="comment">                  *             CSparseMatrix  SM(data);</span>
<a name="l00089"></a>00089 <span class="comment">                  *         \endcode</span>
<a name="l00090"></a>00090 <span class="comment">                  *    &lt;/li&gt;</span>
<a name="l00091"></a>00091 <span class="comment">                  *</span>
<a name="l00092"></a>00092 <span class="comment">                  *   &lt;/ol&gt;</span>
<a name="l00093"></a>00093 <span class="comment">                  *</span>
<a name="l00094"></a>00094 <span class="comment">                  *  Due to its practical utility, there is a special inner class CSparseMatrix::CholeskyDecomp to handle Cholesky-related methods and data.</span>
<a name="l00095"></a>00095 <span class="comment">                  *</span>
<a name="l00096"></a>00096 <span class="comment">                  *</span>
<a name="l00097"></a>00097 <span class="comment">                  * \note This class was initially adapted from &quot;robotvision&quot;, by Hauke Strasdat, Steven Lovegrove and Andrew J. Davison. See http://www.openslam.org/robotvision.html</span>
<a name="l00098"></a>00098 <span class="comment">                  * \note CSparse is maintained by Timothy Davis: http://people.sc.fsu.edu/~jburkardt/c_src/csparse/csparse.html .</span>
<a name="l00099"></a>00099 <span class="comment">                  * \note See also his book &quot;Direct methods for sparse linear systems&quot;. http://books.google.es/books?id=TvwiyF8vy3EC&amp;pg=PA12&amp;lpg=PA12&amp;dq=cs_compress&amp;source=bl&amp;ots=od9uGJ793j&amp;sig=Wa-fBk4sZkZv3Y0Op8FNH8PvCUs&amp;hl=es&amp;ei=UjA0TJf-EoSmsQay3aXPAw&amp;sa=X&amp;oi=book_result&amp;ct=result&amp;resnum=8&amp;ved=0CEQQ6AEwBw#v=onepage&amp;q&amp;f=false</span>
<a name="l00100"></a>00100 <span class="comment">                  *</span>
<a name="l00101"></a>00101 <span class="comment">                  * \sa mrpt::math::CMatrixFixedNumeric, mrpt::math::CMatrixTemplateNumeric, etc.</span>
<a name="l00102"></a>00102 <span class="comment">                  * \ingroup mrpt_base_grp</span>
<a name="l00103"></a>00103 <span class="comment">                  */</span>
<a name="l00104"></a>00104                 <span class="keyword">class </span><a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> CSparseMatrix
<a name="l00105"></a>00105                 {
<a name="l00106"></a>00106                 <span class="keyword">private</span>:
<a name="l00107"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#af45bc10e45c938c73ce281f2aea239d5">00107</a>                         <a class="code" href="structcs__sparse.html">cs</a> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#af45bc10e45c938c73ce281f2aea239d5">sparse_matrix</a>;
<a name="l00108"></a>00108 <span class="comment"></span>
<a name="l00109"></a>00109 <span class="comment">                        /** Initialization from a dense matrix of any kind existing in MRPT. */</span>
<a name="l00110"></a>00110                         <span class="keyword">template</span> &lt;<span class="keyword">class</span> MATRIX&gt;
<a name="l00111"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a69f2b0a005c61fe8fcf4b0d8c0442c43">00111</a>                         <span class="keywordtype">void</span> construct_from_mrpt_mat(<span class="keyword">const</span> MATRIX &amp; C)
<a name="l00112"></a>00112                         {
<a name="l00113"></a>00113                                 std<a class="code" href="classstd_1_1vector.html">::vector&lt;int&gt;</a> row_list, col_list;  <span class="comment">// Use &quot;int&quot; for convenience so we can do a memcpy below...</span>
<a name="l00114"></a>00114                                 std<a class="code" href="classstd_1_1vector.html">::vector&lt;double&gt;</a> content_list;
<a name="l00115"></a>00115                                 <span class="keyword">const</span> <span class="keywordtype">int</span> nCol = C.getColCount();
<a name="l00116"></a>00116                                 <span class="keyword">const</span> <span class="keywordtype">int</span> nRow = C.getRowCount();
<a name="l00117"></a>00117                                 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c=0; c&lt;nCol; ++c)
<a name="l00118"></a>00118                                 {
<a name="l00119"></a>00119                                         col_list.push_back(row_list.size());
<a name="l00120"></a>00120                                         <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r=0; r&lt;nRow; ++r)
<a name="l00121"></a>00121                                                 <span class="keywordflow">if</span> (C.get_unsafe(r,c)!=0)
<a name="l00122"></a>00122                                                 {
<a name="l00123"></a>00123                                                         row_list.push_back(r);
<a name="l00124"></a>00124                                                         content_list.push_back(C(r,c));
<a name="l00125"></a>00125                                                 }
<a name="l00126"></a>00126                                 }
<a name="l00127"></a>00127                                 col_list.push_back(row_list.size());
<a name="l00128"></a>00128 
<a name="l00129"></a>00129                                 sparse_matrix.m = nRow;
<a name="l00130"></a>00130                                 sparse_matrix.n = nCol;
<a name="l00131"></a>00131                                 sparse_matrix.nzmax = content_list.size();
<a name="l00132"></a>00132                                 sparse_matrix.i = (<span class="keywordtype">int</span>*)malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)*row_list.size());
<a name="l00133"></a>00133                                 sparse_matrix.p = (<span class="keywordtype">int</span>*)malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)*col_list.size());
<a name="l00134"></a>00134                                 sparse_matrix.x = (<span class="keywordtype">double</span>*)malloc(<span class="keyword">sizeof</span>(<span class="keywordtype">double</span>)*content_list.size());
<a name="l00135"></a>00135 
<a name="l00136"></a>00136                                 <a class="code" href="group__mrpt__system__os.html#gae1184cfb1f617787dc4c9da98becbe3a" title="An OS and compiler independent version of &quot;memcpy&quot;.">::memcpy</a>(sparse_matrix.i, &amp;row_list[0], <span class="keyword">sizeof</span>(row_list[0])*row_list.size() );
<a name="l00137"></a>00137                                 <a class="code" href="group__mrpt__system__os.html#gae1184cfb1f617787dc4c9da98becbe3a" title="An OS and compiler independent version of &quot;memcpy&quot;.">::memcpy</a>(sparse_matrix.p, &amp;col_list[0], <span class="keyword">sizeof</span>(col_list[0])*col_list.size() );
<a name="l00138"></a>00138                                 <a class="code" href="group__mrpt__system__os.html#gae1184cfb1f617787dc4c9da98becbe3a" title="An OS and compiler independent version of &quot;memcpy&quot;.">::memcpy</a>(sparse_matrix.x, &amp;content_list[0], <span class="keyword">sizeof</span>(content_list[0])*content_list.size() );
<a name="l00139"></a>00139 
<a name="l00140"></a>00140                                 sparse_matrix.nz = -1;  <span class="comment">// &lt;0 means &quot;column compressed&quot;, &quot;&gt;=0&quot; means triplet.</span>
<a name="l00141"></a>00141                         }
<a name="l00142"></a>00142 <span class="comment"></span>
<a name="l00143"></a>00143 <span class="comment">                        /** Initialization from a triplet &quot;cs&quot;, which is first compressed */</span>
<a name="l00144"></a>00144                         <span class="keywordtype">void</span> construct_from_triplet(<span class="keyword">const</span> <a class="code" href="structcs__sparse.html">cs</a> &amp; triplet);
<a name="l00145"></a>00145 <span class="comment"></span>
<a name="l00146"></a>00146 <span class="comment">                        /** To be called by constructors only, assume previous pointers are trash and overwrite them */</span>
<a name="l00147"></a>00147                         <span class="keywordtype">void</span> construct_from_existing_cs(<span class="keyword">const</span> <a class="code" href="structcs__sparse.html">cs</a> &amp;sm);
<a name="l00148"></a>00148 <span class="comment"></span>
<a name="l00149"></a>00149 <span class="comment">                        /** free buffers (deallocate the memory of the i,p,x buffers) */</span>
<a name="l00150"></a>00150                         <span class="keywordtype">void</span> internal_free_mem();
<a name="l00151"></a>00151 <span class="comment"></span>
<a name="l00152"></a>00152 <span class="comment">                        /** Copy the data from an existing &quot;cs&quot; CSparse data structure */</span>
<a name="l00153"></a>00153                         <span class="keywordtype">void</span>  copy(<span class="keyword">const</span> <a class="code" href="structcs__sparse.html">cs</a>  * <span class="keyword">const</span> sm);
<a name="l00154"></a>00154 <span class="comment"></span>
<a name="l00155"></a>00155 <span class="comment">                        /** Fast copy the data from an existing &quot;cs&quot; CSparse data structure, copying the pointers and leaving NULLs in the source structure. */</span>
<a name="l00156"></a>00156                         <span class="keywordtype">void</span>  copy_fast(<a class="code" href="structcs__sparse.html">cs</a>  * <span class="keyword">const</span> sm);
<a name="l00157"></a>00157 
<a name="l00158"></a>00158                 <span class="keyword">public</span>:
<a name="l00159"></a>00159 <span class="comment"></span>
<a name="l00160"></a>00160 <span class="comment">                        /** @name Constructors, destructor &amp; copy operations</span>
<a name="l00161"></a>00161 <span class="comment">                            @{  */</span>
<a name="l00162"></a>00162 <span class="comment"></span>
<a name="l00163"></a>00163 <span class="comment">                        /** Create an initially empty sparse matrix, in the &quot;triplet&quot; form.</span>
<a name="l00164"></a>00164 <span class="comment">                          *  Notice that you must call &quot;compressFromTriplet&quot; after populating the matrix and before using the math operatons on this matrix.</span>
<a name="l00165"></a>00165 <span class="comment">                          *  The initial size can be later on extended with insert_entry() or setRowCount() &amp; setColCount().</span>
<a name="l00166"></a>00166 <span class="comment">                          * \sa insert_entry, setRowCount, setColCount</span>
<a name="l00167"></a>00167 <span class="comment">                          */</span>
<a name="l00168"></a>00168                         <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a>(<span class="keyword">const</span> <span class="keywordtype">size_t</span> nRows=0, <span class="keyword">const</span> <span class="keywordtype">size_t</span> nCols=0);
<a name="l00169"></a>00169 <span class="comment"></span>
<a name="l00170"></a>00170 <span class="comment">                        /** A good way to initialize a sparse matrix from a list of non NULL elements.</span>
<a name="l00171"></a>00171 <span class="comment">                          *  This constructor takes all the non-zero entries in &quot;data&quot; and builds a column-compressed sparse representation.</span>
<a name="l00172"></a>00172 <span class="comment">                          */</span>
<a name="l00173"></a>00173                         <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;
<a name="l00174"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a67af500c83f70e8b8b33b4d50fae4759">00174</a>                         <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_template.html">CSparseMatrixTemplate&lt;T&gt;</a> &amp; data)
<a name="l00175"></a>00175                         {
<a name="l00176"></a>00176                                 <a class="code" href="mrpt__macros_8h.html#ad30ea0382c594c0e2efe88212e9352b0">ASSERTMSG_</a>(!data.<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_template.html#a6b717486d2d69655b30d110db4165bd7" title="Are there no elements set to !=0 ?">empty</a>(), <span class="stringliteral">&quot;Input data must contain at least one non-zero element.&quot;</span>)
<a name="l00177"></a>00177                                 sparse_matrix.i = NULL; <span class="comment">// This is to know they shouldn&#39;t be tried to free()</span>
<a name="l00178"></a>00178                                 sparse_matrix.p = NULL;
<a name="l00179"></a>00179                                 sparse_matrix.x = NULL;
<a name="l00180"></a>00180 
<a name="l00181"></a>00181                                 <span class="comment">// 1) Create triplet matrix</span>
<a name="l00182"></a>00182                                 <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a>  triplet(data.<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_template.html#a791dd49435a4bed1d3c340939807697c" title="Returns the amount of rows in this matrix.">getRowCount</a>(),data.<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_template.html#ad3d8491c5a4dfb46dabf00be2e595d16" title="Returns the amount of columns in this matrix.">getColCount</a>());
<a name="l00183"></a>00183                                 <span class="comment">// 2) Put data in:</span>
<a name="l00184"></a>00184                                 <span class="keywordflow">for</span> (<span class="keyword">typename</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_template.html" title="A sparse matrix container (with cells of any type), with iterators.">CSparseMatrixTemplate&lt;T&gt;::const_iterator</a> it=data.<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_template.html#afcf8eb5ac80e0f37ad19adca335faf6d" title="Returns an iterator which points to the starting point of the matrix.">begin</a>();it!=data.<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_template.html#ad22beed94e2b53572d00cae7c4fbb65c" title="Returns an iterator which points to the end of the matrix.">end</a>();++it)
<a name="l00185"></a>00185                                         triplet.<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#abc4058c15d5a02f8d56853de8cbab18b" title="ONLY for TRIPLET matrices: Insert an element into a &quot;cs&quot;, without checking if the matrix is in Triple...">insert_entry_fast</a>(it-&gt;first.first,it-&gt;first.second, it-&gt;second);
<a name="l00186"></a>00186 
<a name="l00187"></a>00187                                 <span class="comment">// 3) Compress:</span>
<a name="l00188"></a>00188                                 construct_from_triplet(triplet.sparse_matrix);
<a name="l00189"></a>00189                         }
<a name="l00190"></a>00190 
<a name="l00191"></a>00191 
<a name="l00192"></a>00192                         <span class="comment">// We can&#39;t do a simple &quot;template &lt;class ANYMATRIX&gt;&quot; since it would be tried to match against &quot;cs*&quot;...</span>
<a name="l00193"></a>00193 <span class="comment"></span>
<a name="l00194"></a>00194 <span class="comment">                        /** Constructor from a dense matrix of any kind existing in MRPT, creating a &quot;column-compressed&quot; sparse matrix. */</span>
<a name="l00195"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a9adcd5be76c48044671b4d63de30120a">00195</a>                         <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T,<span class="keywordtype">size_t</span> N,<span class="keywordtype">size_t</span> M&gt; <span class="keyword">inline</span> <span class="keyword">explicit</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a9adcd5be76c48044671b4d63de30120a" title="Constructor from a dense matrix of any kind existing in MRPT, creating a &quot;column-compressed&quot; sparse m...">CSparseMatrix</a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_matrix_fixed_numeric.html" title="A numeric matrix of compile-time fixed size.">CMatrixFixedNumeric&lt;T,N,M&gt;</a> &amp;MAT) { construct_from_mrpt_mat(MAT); }
<a name="l00196"></a>00196 <span class="comment"></span>
<a name="l00197"></a>00197 <span class="comment">                        /** Constructor from a dense matrix of any kind existing in MRPT, creating a &quot;column-compressed&quot; sparse matrix. */</span>
<a name="l00198"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#acea14c946787fe0be313d17df3eea221">00198</a>                         <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T&gt;  <span class="keyword">inline</span> <span class="keyword">explicit</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#acea14c946787fe0be313d17df3eea221" title="Constructor from a dense matrix of any kind existing in MRPT, creating a &quot;column-compressed&quot; sparse m...">CSparseMatrix</a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_matrix_template_numeric.html" title="A matrix of dynamic size.">CMatrixTemplateNumeric&lt;T&gt;</a> &amp;MAT) { construct_from_mrpt_mat(MAT); }
<a name="l00199"></a>00199 <span class="comment"></span>
<a name="l00200"></a>00200 <span class="comment">                        /** Copy constructor */</span>
<a name="l00201"></a>00201                         <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp; other);
<a name="l00202"></a>00202 <span class="comment"></span>
<a name="l00203"></a>00203 <span class="comment">                        /** Copy constructor from an existing &quot;cs&quot; CSparse data structure */</span>
<a name="l00204"></a>00204                         <span class="keyword">explicit</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a>(<span class="keyword">const</span> <a class="code" href="structcs__sparse.html">cs</a>  * <span class="keyword">const</span> sm);
<a name="l00205"></a>00205 <span class="comment"></span>
<a name="l00206"></a>00206 <span class="comment">                        /** Destructor */</span>
<a name="l00207"></a>00207                         <span class="keyword">virtual</span> ~<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a>();
<a name="l00208"></a>00208 <span class="comment"></span>
<a name="l00209"></a>00209 <span class="comment">                        /** Copy operator from another existing object */</span>
<a name="l00210"></a>00210                         <span class="keywordtype">void</span> operator = (<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp; other);
<a name="l00211"></a>00211 <span class="comment"></span>
<a name="l00212"></a>00212 <span class="comment">                        /** Erase all previous contents and leave the matrix as a &quot;triplet&quot; 1x1 matrix without any data. */</span>
<a name="l00213"></a>00213                         <span class="keywordtype">void</span> clear();
<a name="l00214"></a>00214 <span class="comment"></span>
<a name="l00215"></a>00215 <span class="comment">                        /** @}  */</span>
<a name="l00216"></a>00216 <span class="comment"></span>
<a name="l00217"></a>00217 <span class="comment">                        /** @name Math operations (the interesting stuff...)</span>
<a name="l00218"></a>00218 <span class="comment">                                @{ */</span>
<a name="l00219"></a>00219 
<a name="l00220"></a>00220                         <span class="keywordtype">void</span> add_AB(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp; A,<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp; B); <span class="comment">//!&lt; this = A+B</span>
<a name="l00221"></a>00221 <span class="comment"></span>                        <span class="keywordtype">void</span> <a class="code" href="eigen__plugins_8h.html#a7f39ab70bf340ee5bc203aad960d57e0">multiply_AB</a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp; A,<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp; B); <span class="comment">//!&lt; this = A*B</span>
<a name="l00222"></a>00222 <span class="comment"></span>                        <span class="keywordtype">void</span> <a class="code" href="eigen__plugins_8h.html#a768efc255b5ecad2750092f47313d549">multiply_Ab</a>(<span class="keyword">const</span> <a class="code" href="structmrpt_1_1dynamicsize__vector.html" title="The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...">mrpt::vector_double</a> &amp;b, <a class="code" href="structmrpt_1_1dynamicsize__vector.html" title="The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...">mrpt::vector_double</a> &amp;out_res) <span class="keyword">const</span>; <span class="comment">//!&lt; out_res = this * b</span>
<a name="l00223"></a>00223 <span class="comment"></span>
<a name="l00224"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#ac6ffc42c8bf4b24ac6632add222caef0">00224</a>                         <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> <a class="code" href="group__container__ops__grp.html#ga5a1ef801e13687370311dd36eaae6e08" title="a+b (element-wise sum)">operator + </a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp; other)<span class="keyword"> const</span>
<a name="l00225"></a>00225 <span class="keyword">                        </span>{
<a name="l00226"></a>00226                                 <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> RES;
<a name="l00227"></a>00227                                 RES.<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a0e28abd9010a84b6a777c97496cb8eb6" title="this = A+B">add_AB</a>(*<span class="keyword">this</span>,other);
<a name="l00228"></a>00228                                 <span class="keywordflow">return</span> RES;
<a name="l00229"></a>00229                         }
<a name="l00230"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#ae270652280c21219cb6fb54b3b8c6b37">00230</a>                         <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> <a class="code" href="group__container__ops__grp.html#ga6f2d8625a637a5a65585065331b5b0c5" title="a*b (element-wise multiplication)">operator * </a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp; other)<span class="keyword"> const</span>
<a name="l00231"></a>00231 <span class="keyword">                        </span>{
<a name="l00232"></a>00232                                 <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> RES;
<a name="l00233"></a>00233                                 RES.<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#aac6d33b70dac52676ab0b7e933d77e80" title="this = A*B">multiply_AB</a>(*<span class="keyword">this</span>,other);
<a name="l00234"></a>00234                                 <span class="keywordflow">return</span> RES;
<a name="l00235"></a>00235                         }
<a name="l00236"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#ac53f79478dd3ad93d38a64fca27d1212">00236</a>                         <span class="keyword">inline</span> mrpt<a class="code" href="structmrpt_1_1dynamicsize__vector.html" title="The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...">::vector_double</a> <a class="code" href="group__container__ops__grp.html#ga6f2d8625a637a5a65585065331b5b0c5" title="a*b (element-wise multiplication)">operator * </a>(<span class="keyword">const</span> <a class="code" href="structmrpt_1_1dynamicsize__vector.html" title="The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...">mrpt::vector_double</a> &amp; other)<span class="keyword"> const </span>{
<a name="l00237"></a>00237                                 mrpt<a class="code" href="structmrpt_1_1dynamicsize__vector.html" title="The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...">::vector_double</a> res;
<a name="l00238"></a>00238                                 <a class="code" href="eigen__plugins_8h.html#a768efc255b5ecad2750092f47313d549">multiply_Ab</a>(other,res);
<a name="l00239"></a>00239                                 <span class="keywordflow">return</span> res;
<a name="l00240"></a>00240                         }
<a name="l00241"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#ad5dd8abf27f0cc2a312751f829da1772">00241</a>                         <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group__container__ops__grp.html#ga28127b8dfe78fea7644c4f2a3517cdef" title="a+=b (element-wise sum)">operator += </a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp; other) {
<a name="l00242"></a>00242                                 this-&gt;add_AB(*<span class="keyword">this</span>,other);
<a name="l00243"></a>00243                         }
<a name="l00244"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a63b605043228deb4187a7bdce0c50f0c">00244</a>                         <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="group__container__ops__grp.html#gabc43a80aa18fe8ffdfe69fed3ad115a9" title="a*=b (element-wise multiplication)">operator *= </a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp; other) {
<a name="l00245"></a>00245                                 this-&gt;<a class="code" href="eigen__plugins_8h.html#a7f39ab70bf340ee5bc203aad960d57e0">multiply_AB</a>(*<span class="keyword">this</span>,other);
<a name="l00246"></a>00246                         }
<a name="l00247"></a>00247                         <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> transpose() <span class="keyword">const</span>;
<a name="l00248"></a>00248 <span class="comment"></span>
<a name="l00249"></a>00249 <span class="comment">                        /** @}  */</span>
<a name="l00250"></a>00250 
<a name="l00251"></a>00251 <span class="comment"></span>
<a name="l00252"></a>00252 <span class="comment">                        /** @ Access the matrix, get, set elements, etc.</span>
<a name="l00253"></a>00253 <span class="comment">                            @{ */</span>
<a name="l00254"></a>00254 <span class="comment"></span>
<a name="l00255"></a>00255 <span class="comment">                        /** ONLY for TRIPLET matrices: insert a new non-zero entry in the matrix.</span>
<a name="l00256"></a>00256 <span class="comment">                          *  This method cannot be used once the matrix is in column-compressed form.</span>
<a name="l00257"></a>00257 <span class="comment">                          *  The size of the matrix will be automatically extended if the indices are out of the current limits.</span>
<a name="l00258"></a>00258 <span class="comment">                          * \sa isTriplet, compressFromTriplet</span>
<a name="l00259"></a>00259 <span class="comment">                          */</span>
<a name="l00260"></a>00260                         <span class="keywordtype">void</span> insert_entry(<span class="keyword">const</span> <span class="keywordtype">size_t</span> row, <span class="keyword">const</span> <span class="keywordtype">size_t</span> col, <span class="keyword">const</span> <span class="keywordtype">double</span> val );
<a name="l00261"></a>00261 <span class="comment"></span>
<a name="l00262"></a>00262 <span class="comment">                        /** ONLY for TRIPLET matrices: Insert an element into a &quot;cs&quot;, without checking if the matrix is in Triplet format and without extending the matrix extension/limits if (row,col) is out of the current size. */</span>
<a name="l00263"></a>00263                         <span class="keywordtype">void</span> insert_entry_fast(<span class="keyword">const</span> <span class="keywordtype">size_t</span> row, <span class="keyword">const</span> <span class="keywordtype">size_t</span> col, <span class="keyword">const</span> <span class="keywordtype">double</span> val );
<a name="l00264"></a>00264 <span class="comment"></span>
<a name="l00265"></a>00265 <span class="comment">                        /** ONLY for TRIPLET matrices: insert a given matrix (in any of the MRPT formats) at a given location of the sparse matrix.</span>
<a name="l00266"></a>00266 <span class="comment">                          *  This method cannot be used once the matrix is in column-compressed form.</span>
<a name="l00267"></a>00267 <span class="comment">                          *  The size of the matrix will be automatically extended if the indices are out of the current limits.</span>
<a name="l00268"></a>00268 <span class="comment">                          *  Since this is inline, it can be very efficient for fixed-size MRPT matrices.</span>
<a name="l00269"></a>00269 <span class="comment">                          * \sa isTriplet, compressFromTriplet, insert_entry</span>
<a name="l00270"></a>00270 <span class="comment">                          */</span>
<a name="l00271"></a>00271                         <span class="keyword">template</span> &lt;<span class="keyword">class</span> MATRIX&gt;
<a name="l00272"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a894f92cdcb91d4f700d5724bf11e0382">00272</a>                         <span class="keyword">inline</span> <span class="keywordtype">void</span> insert_submatrix(<span class="keyword">const</span> <span class="keywordtype">size_t</span> row, <span class="keyword">const</span> <span class="keywordtype">size_t</span> col, <span class="keyword">const</span> MATRIX &amp;M )
<a name="l00273"></a>00273                         {
<a name="l00274"></a>00274                                 <span class="keywordflow">if</span> (!isTriplet()) <a class="code" href="mrpt__macros_8h.html#aaa3f404ea85a6575a7139f8d101370ba">THROW_EXCEPTION</a>(<span class="stringliteral">&quot;insert_entry() is only available for sparse matrix in &#39;triplet&#39; format.&quot;</span>)
<a name="l00275"></a>00275                                 <span class="keyword">const</span> <span class="keywordtype">size_t</span> nR = M.getRowCount();
<a name="l00276"></a>00276                                 <span class="keyword">const</span> <span class="keywordtype">size_t</span> nC = M.getColCount();
<a name="l00277"></a>00277                                 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> r=0;r&lt;nR;r++)
<a name="l00278"></a>00278                                         <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> c=0;c&lt;nC;c++)
<a name="l00279"></a>00279                                                 insert_entry_fast(row+r,col+c, M.get_unsafe(r,c));
<a name="l00280"></a>00280                                 <span class="comment">// If needed, extend the size of the matrix:</span>
<a name="l00281"></a>00281                                 sparse_matrix.m = std::max(sparse_matrix.m, <span class="keywordtype">int</span>(row+nR));
<a name="l00282"></a>00282                                 sparse_matrix.n = std::max(sparse_matrix.n, <span class="keywordtype">int</span>(col+nC));
<a name="l00283"></a>00283                         }
<a name="l00284"></a>00284 
<a name="l00285"></a>00285 <span class="comment"></span>
<a name="l00286"></a>00286 <span class="comment">                        /** ONLY for TRIPLET matrices: convert the matrix in a column-compressed form.</span>
<a name="l00287"></a>00287 <span class="comment">                          * \sa insert_entry</span>
<a name="l00288"></a>00288 <span class="comment">                          */</span>
<a name="l00289"></a>00289                         <span class="keywordtype">void</span> compressFromTriplet();
<a name="l00290"></a>00290 <span class="comment"></span>
<a name="l00291"></a>00291 <span class="comment">                        /** Return a dense representation of the sparse matrix.</span>
<a name="l00292"></a>00292 <span class="comment">                          * \sa saveToTextFile_dense</span>
<a name="l00293"></a>00293 <span class="comment">                          */</span>
<a name="l00294"></a>00294                         <span class="keywordtype">void</span> get_dense(<a class="code" href="classmrpt_1_1math_1_1_c_matrix_template_numeric.html" title="A matrix of dynamic size.">CMatrixDouble</a> &amp;outMat) <span class="keyword">const</span>;
<a name="l00295"></a>00295 <span class="comment"></span>
<a name="l00296"></a>00296 <span class="comment">                        /** Static method to convert a &quot;cs&quot; structure into a dense representation of the sparse matrix.</span>
<a name="l00297"></a>00297 <span class="comment">                          */</span>
<a name="l00298"></a>00298                         <span class="keyword">static</span> <span class="keywordtype">void</span> cs2dense(<span class="keyword">const</span> <a class="code" href="structcs__sparse.html">cs</a>&amp; SM, <a class="code" href="classmrpt_1_1math_1_1_c_matrix_template_numeric.html" title="A matrix of dynamic size.">CMatrixDouble</a> &amp;outMat);
<a name="l00299"></a>00299 <span class="comment"></span>
<a name="l00300"></a>00300 <span class="comment">                        /** save as a dense matrix to a text file \return False on any error.</span>
<a name="l00301"></a>00301 <span class="comment">                          */</span>
<a name="l00302"></a>00302                         <span class="keywordtype">bool</span> saveToTextFile_dense(<span class="keyword">const</span> <a class="code" href="classstd_1_1string.html" title="STL class.">std::string</a> &amp;filName);
<a name="l00303"></a>00303 
<a name="l00304"></a>00304                         <span class="comment">// Very basic, standard methods that MRPT methods expect for any matrix:</span>
<a name="l00305"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a1214329cf1365c3438c0f78a92603eb8">00305</a>                         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a1214329cf1365c3438c0f78a92603eb8">getRowCount</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> sparse_matrix.m; }
<a name="l00306"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#af8abe241e9f40a99b6baa0bf7925b5e2">00306</a>                         <span class="keyword">inline</span> <span class="keywordtype">size_t</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#af8abe241e9f40a99b6baa0bf7925b5e2">getColCount</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> sparse_matrix.n; }
<a name="l00307"></a>00307 <span class="comment"></span>
<a name="l00308"></a>00308 <span class="comment">                        /** Change the number of rows in the matrix (can&#39;t be lower than current size) */</span>
<a name="l00309"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a10a20d1ac9b6d243517632b106940230">00309</a>                         <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a10a20d1ac9b6d243517632b106940230" title="Change the number of rows in the matrix (can&#39;t be lower than current size)">setRowCount</a>(<span class="keyword">const</span> <span class="keywordtype">size_t</span> nRows) { <a class="code" href="mrpt__macros_8h.html#a47eb5a445c2bf3d9190396510ea9683e">ASSERT_</a>(nRows&gt;=(<span class="keywordtype">size_t</span>)sparse_matrix.m); sparse_matrix.m = nRows; }
<a name="l00310"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a7c712ee22308a4192a607e94781a534e">00310</a>                         <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a7c712ee22308a4192a607e94781a534e">setColCount</a>(<span class="keyword">const</span> <span class="keywordtype">size_t</span> nCols) { <a class="code" href="mrpt__macros_8h.html#a47eb5a445c2bf3d9190396510ea9683e">ASSERT_</a>(nCols&gt;=(<span class="keywordtype">size_t</span>)sparse_matrix.n); sparse_matrix.n = nCols; }
<a name="l00311"></a>00311 <span class="comment"></span>
<a name="l00312"></a>00312 <span class="comment">                        /** Returns true if this sparse matrix is in &quot;triplet&quot; form. \sa isColumnCompressed */</span>
<a name="l00313"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a8c4fb86b861bc3cfd690551c25722e94">00313</a>                         <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a8c4fb86b861bc3cfd690551c25722e94" title="Returns true if this sparse matrix is in &quot;triplet&quot; form.">isTriplet</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> sparse_matrix.nz&gt;=0; }  <span class="comment">// &lt;0 means &quot;column compressed&quot;, &quot;&gt;=0&quot; means triplet.</span>
<a name="l00314"></a>00314 <span class="comment"></span>
<a name="l00315"></a>00315 <span class="comment">                        /** Returns true if this sparse matrix is in &quot;column compressed&quot; form. \sa isTriplet */</span>
<a name="l00316"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a9b9eb4fd3d1a54d4ced1a2fe2cd5c2ac">00316</a>                         <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html#a9b9eb4fd3d1a54d4ced1a2fe2cd5c2ac" title="Returns true if this sparse matrix is in &quot;column compressed&quot; form.">isColumnCompressed</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> sparse_matrix.nz&lt;0; }  <span class="comment">// &lt;0 means &quot;column compressed&quot;, &quot;&gt;=0&quot; means triplet.</span>
<a name="l00317"></a>00317 <span class="comment"></span>
<a name="l00318"></a>00318 <span class="comment">                        /** @} */</span>
<a name="l00319"></a>00319 
<a name="l00320"></a>00320 <span class="comment"></span>
<a name="l00321"></a>00321 <span class="comment">                        /** @name Cholesky factorization</span>
<a name="l00322"></a>00322 <span class="comment">                            @{  */</span>
<a name="l00323"></a>00323 <span class="comment"></span>
<a name="l00324"></a>00324 <span class="comment">                        /** Auxiliary class to hold the results of a Cholesky factorization of a sparse matrix.</span>
<a name="l00325"></a>00325 <span class="comment">                          *  Usage example:</span>
<a name="l00326"></a>00326 <span class="comment">                          *   \code</span>
<a name="l00327"></a>00327 <span class="comment">                          *     CSparseMatrix  SM(100,100);</span>
<a name="l00328"></a>00328 <span class="comment">                          *     SM.insert_entry(i,j, val); ...</span>
<a name="l00329"></a>00329 <span class="comment">                          *     SM.compressFromTriplet();</span>
<a name="l00330"></a>00330 <span class="comment">                          *</span>
<a name="l00331"></a>00331 <span class="comment">                          *     // Do Cholesky decomposition:</span>
<a name="l00332"></a>00332 <span class="comment">                          *             CSparseMatrix::CholeskyDecomp  CD(SM);</span>
<a name="l00333"></a>00333 <span class="comment">                          *     CD.get_inverse();</span>
<a name="l00334"></a>00334 <span class="comment">                          *     ...</span>
<a name="l00335"></a>00335 <span class="comment">                          *   \endcode</span>
<a name="l00336"></a>00336 <span class="comment">                          *</span>
<a name="l00337"></a>00337 <span class="comment">                          * \note Only the upper triangular part of the input matrix is accessed.</span>
<a name="l00338"></a>00338 <span class="comment">                          * \note This class was initially adapted from &quot;robotvision&quot;, by Hauke Strasdat, Steven Lovegrove and Andrew J. Davison. See http://www.openslam.org/robotvision.html</span>
<a name="l00339"></a>00339 <span class="comment">                          * \note This class designed to be &quot;uncopiable&quot;.</span>
<a name="l00340"></a>00340 <span class="comment">                          * \sa The main class: CSparseMatrix</span>
<a name="l00341"></a>00341 <span class="comment">                          */</span>
<a name="l00342"></a>00342                         <span class="keyword">class </span><a class="code" href="base_2include_2mrpt_2base_2link__pragmas_8h.html#a6045fa0129b1a3d6c8bf895470e66574">BASE_IMPEXP</a> CholeskyDecomp  : <span class="keyword">public</span> mrpt::utils::<a class="code" href="classmrpt_1_1utils_1_1_c_uncopiable.html" title="The base class of classes that cannot be copied: compile-time errors will be issued on any copy opera...">CUncopiable</a>
<a name="l00343"></a>00343                         {
<a name="l00344"></a>00344                         <span class="keyword">private</span>:
<a name="l00345"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#a93f179dd287779e018e95829cf3a5c68">00345</a>                                 <a class="code" href="structcs__symbolic.html">css</a> * <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#a93f179dd287779e018e95829cf3a5c68">m_symbolic_structure</a>;
<a name="l00346"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#a38a4c14675e0045a800633651774b90d">00346</a>                                 <a class="code" href="structcs__numeric.html">csn</a> * <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#a38a4c14675e0045a800633651774b90d">m_numeric_structure</a>;
<a name="l00347"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#ac391e5c78a90a580d501f8141364d727">00347</a>                                 <span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> *<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#ac391e5c78a90a580d501f8141364d727" title="A const reference to the original matrix used to build this decomposition.">m_originalSM</a>;  <span class="comment">//!&lt; A const reference to the original matrix used to build this decomposition.</span>
<a name="l00348"></a>00348 <span class="comment"></span>
<a name="l00349"></a>00349                         <span class="keyword">public</span>:<span class="comment"></span>
<a name="l00350"></a>00350 <span class="comment">                                /** Constructor from a square definite-positive sparse matrix A, which can be use to solve Ax=b</span>
<a name="l00351"></a>00351 <span class="comment">                                  *   The actual Cholesky decomposition takes places in this constructor.</span>
<a name="l00352"></a>00352 <span class="comment">                                  *  \note Only the upper triangular part of the matrix is accessed.</span>
<a name="l00353"></a>00353 <span class="comment">                                  *  \exception std::runtime_error On non-square input matrix.</span>
<a name="l00354"></a>00354 <span class="comment">                                  *  \exception mrpt::math::CExceptionNotDefPos On non-definite-positive matrix as input.</span>
<a name="l00355"></a>00355 <span class="comment">                                  */</span>
<a name="l00356"></a>00356                                 <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html" title="Auxiliary class to hold the results of a Cholesky factorization of a sparse matrix.">CholeskyDecomp</a>(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp;A);
<a name="l00357"></a>00357 <span class="comment"></span>
<a name="l00358"></a>00358 <span class="comment">                                /** Destructor */</span>
<a name="l00359"></a>00359                                 <span class="keyword">virtual</span> ~<a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html" title="Auxiliary class to hold the results of a Cholesky factorization of a sparse matrix.">CholeskyDecomp</a>();
<a name="l00360"></a>00360 <span class="comment"></span>
<a name="l00361"></a>00361 <span class="comment">                                /** Return the L matrix (L*L&#39; = M), as a dense matrix. */</span>
<a name="l00362"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#a683ec672fe111c51f8077dfe91a02b5b">00362</a>                                 <span class="keyword">inline</span> <a class="code" href="classmrpt_1_1math_1_1_c_matrix_template_numeric.html" title="A matrix of dynamic size.">CMatrixDouble</a> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#a683ec672fe111c51f8077dfe91a02b5b" title="Return the L matrix (L*L&#39; = M), as a dense matrix.">get_L</a>()<span class="keyword"> const </span>{ <a class="code" href="classmrpt_1_1math_1_1_c_matrix_template_numeric.html" title="A matrix of dynamic size.">CMatrixDouble</a> L; <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#a683ec672fe111c51f8077dfe91a02b5b" title="Return the L matrix (L*L&#39; = M), as a dense matrix.">get_L</a>(L); <span class="keywordflow">return</span> L; }
<a name="l00363"></a>00363 <span class="comment"></span>
<a name="l00364"></a>00364 <span class="comment">                                /** Return the L matrix (L*L&#39; = M), as a dense matrix. */</span>
<a name="l00365"></a>00365                                 <span class="keywordtype">void</span> get_L(<a class="code" href="classmrpt_1_1math_1_1_c_matrix_template_numeric.html" title="A matrix of dynamic size.">CMatrixDouble</a> &amp;out_L) <span class="keyword">const</span>;
<a name="l00366"></a>00366 <span class="comment"></span>
<a name="l00367"></a>00367 <span class="comment">                                /** Return the vector from a back-substitution step that solves: Ux=b   */</span>
<a name="l00368"></a><a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#a68d1c1d3ac8e5636d61cf9ad6d6ef438">00368</a>                                 <span class="keyword">inline</span> mrpt<a class="code" href="structmrpt_1_1dynamicsize__vector.html" title="The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...">::vector_double</a> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#a68d1c1d3ac8e5636d61cf9ad6d6ef438" title="Return the vector from a back-substitution step that solves: Ux=b.">backsub</a>(<span class="keyword">const</span> <a class="code" href="structmrpt_1_1dynamicsize__vector.html" title="The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...">mrpt::vector_double</a> &amp;b)<span class="keyword"> const </span>{ mrpt<a class="code" href="structmrpt_1_1dynamicsize__vector.html" title="The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...">::vector_double</a> res; <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix_1_1_cholesky_decomp.html#a68d1c1d3ac8e5636d61cf9ad6d6ef438" title="Return the vector from a back-substitution step that solves: Ux=b.">backsub</a>(b,res); <span class="keywordflow">return</span> res; }
<a name="l00369"></a>00369 <span class="comment"></span>
<a name="l00370"></a>00370 <span class="comment">                                /** Return the vector from a back-substitution step that solves: Ux=b   */</span>
<a name="l00371"></a>00371                                 <span class="keywordtype">void</span> backsub(<span class="keyword">const</span> <a class="code" href="structmrpt_1_1dynamicsize__vector.html" title="The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...">mrpt::vector_double</a> &amp;b, <a class="code" href="structmrpt_1_1dynamicsize__vector.html" title="The base class of MRPT vectors, actually, Eigen column matrices of dynamic size with specialized cons...">mrpt::vector_double</a> &amp;result_x) <span class="keyword">const</span>;
<a name="l00372"></a>00372 <span class="comment"></span>
<a name="l00373"></a>00373 <span class="comment">                                /** Update the Cholesky factorization from an updated vesion of the original input, square definite-positive sparse matrix.</span>
<a name="l00374"></a>00374 <span class="comment">                                  *  NOTE: This new matrix MUST HAVE exactly the same sparse structure than the original one.</span>
<a name="l00375"></a>00375 <span class="comment">                                  */</span>
<a name="l00376"></a>00376                                 <span class="keywordtype">void</span> update(<span class="keyword">const</span> <a class="code" href="classmrpt_1_1math_1_1_c_sparse_matrix.html" title="A sparse matrix capable of efficient math operations (a wrapper around the CSparse library) The type ...">CSparseMatrix</a> &amp;new_SM);
<a name="l00377"></a>00377                         };
<a name="l00378"></a>00378 
<a name="l00379"></a>00379 <span class="comment"></span>
<a name="l00380"></a>00380 <span class="comment">                        /** @} */</span>
<a name="l00381"></a>00381 
<a name="l00382"></a>00382                 }; <span class="comment">// end class CSparseMatrix</span>
<a name="l00383"></a>00383 
<a name="l00384"></a>00384         }
<a name="l00385"></a>00385 }
<a name="l00386"></a>00386 <span class="preprocessor">#endif</span>
</pre></div></div>
</div>
<br><hr><br> <table border="0" width="100%"> <tr> <td> Page generated by <a href="http://www.doxygen.org" target="_blank">Doxygen 1.7.5</a> for MRPT 0.9.5 SVN: at Sun Sep 25 17:20:18 UTC 2011</td><td></td> <td width="100"> </td> <td width="150">  </td></tr> </table>  </body></html>