<div dir="ltr"><div>Dear community</div><div><br></div><div>Dr. Eddelbuettel suggested me to ask here.</div><div><br></div><div>I am trying to implement <em>Dulmage-Mendelsohn decomposition</em> in R. CSparse already has a function to do this, and it's not exported in Matrix so I took the C files and tried to use them in R.<br></div><div><br></div><div>I decided to sketch this into an R Package with Rcpp: <a href="https://github.com/pachamaltese/dulmagemendelsohn">https://github.com/pachamaltese/dulmagemendelsohn</a></div><div><br></div><div>The final goal is to find a permutation matrix, so that the original matrix is rearranged into a block diagonal matrix:<br></div><div><br></div><div><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC1" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"><span style="font-family:monospace"><span class="gmail-pl-smi">matrix_input</span> <span class="gmail-pl-k"><-</span> <span class="gmail-pl-k">matrix</span>(</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC2" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"><span style="font-family:monospace"> c(<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">7</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC3" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">3</span>,</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC4" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c1">5</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">1</span>,<span class="gmail-pl-c1">0</span>,</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC5" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">2</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC6" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">1</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>),</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC7" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-v">ncol</span> <span class="gmail-pl-k">=</span> <span class="gmail-pl-c1">5</span>, <span class="gmail-pl-v">nrow</span> <span class="gmail-pl-k">=</span> <span class="gmail-pl-c1">5</span></span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC8" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"><span style="font-family:monospace">)</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC9" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">
<span style="font-family:monospace"><br></span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC10" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"><span style="font-family:monospace"><span class="gmail-pl-en">dm_decomposition</span> <span class="gmail-pl-k"><-</span> <span class="gmail-pl-k">function</span>(<span class="gmail-pl-smi">matrix_input</span>) {</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC11" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c"><span class="gmail-pl-c">#</span> the actual decomposition happens here</span></span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC12" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c"><span class="gmail-pl-c">#</span> ... "MAGIC" ...</span></span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC13" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><br></span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC14" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c"><span class="gmail-pl-c">#</span> but here is an example output</span></span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC15" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-k">matrix</span>(</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC16" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"><span style="font-family:monospace"> c(<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">7</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC17" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c1">5</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">1</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC18" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">2</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC19" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">3</span>,</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC20" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">0</span>,<span class="gmail-pl-c1">1</span>,<span class="gmail-pl-c1">0</span>),</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC21" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"> <span style="font-family:monospace"><span class="gmail-pl-v">ncol</span> <span class="gmail-pl-k">=</span> <span class="gmail-pl-c1">5</span>, <span class="gmail-pl-v">nrow</span> <span class="gmail-pl-k">=</span> <span class="gmail-pl-c1">5</span></span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC22" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"><span style="font-family:monospace"> )</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC23" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line"><span style="font-family:monospace">}</span></td>
</tr>
<tr>
</tr></tbody></table><table class="gmail-highlight gmail-tab-size gmail-js-file-line-container"><tbody><tr><td id="gmail-LC24" class="gmail-blob-code gmail-blob-code-inner gmail-js-file-line">
<span style="font-family:monospace"><br></span></td>
</tr>
<tr>
</tr></tbody></table><span style="font-family:monospace">dm_decomposition(<span class="gmail-pl-smi">matrix_input</span>)</span></div><div><br></div><div>Can you please provide me some guidance to get this working?</div><div><br></div><div>I am by no means a C/C++ expert, I just have experience with statistics and writing R packages.<br></div><div><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div style="font-size:small"><div dir="ltr" style="font-size:12.8px"><div style="font-size:small"><div><span style="font-size:24pt;font-family:"arial black",sans-serif;color:rgb(1,104,179);line-height:13.8px">——</span><span style="font-size:24pt;font-family:"arial black",sans-serif;color:rgb(238,58,67);line-height:13.8px">———</span></div><div><br></div><i>Mauricio Vargas Sepúlveda 帕夏</i><br></div>Do you like Data Science? visit <a href="http://pacha.hk/" target="_blank">pacha.hk</a></div><div dir="ltr" style="font-size:12.8px">你爱科学数据专吗?你走<a href="http://pacha.hk/" target="_blank">pacha.hk</a></div></div></div></div></div></div></div></div>