Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to print an Armadillo matrix or vector in Visual Studio Debug?

I'm wondering whether there is any method to show vector/matrix entries values in the debugging section on Visual Studio (in particular VS2012).

This question is very similar to the one posted in:

Is there a way to print an Armadillo matrix in gdb?

however I did not manage to figure out whether this approach also applies to VS.

Thanks.

like image 325
dspGI Avatar asked Dec 12 '14 18:12

dspGI


2 Answers

This .natvis XML code works fine in visual studio 2013. I added @Claes Rolen XML in visual studio 2013 and that dose not work fine for me.

The trick is to use <IndexListItems> to visualize armadillo matrix

declare and initialize code

mat tMat(3, 3);

for (int i = 0; i < 3; i++)
{
    for (int j = 0; j < 3; j++)
        tMat(i, j) = i + j;
}

.Natvis File

    <?xml version="1.0" encoding="utf-8"?> 
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010"> 


  <Type Name="arma::Col&lt;*&gt;">
    <DisplayString>{{ Size = {n_elem} }}</DisplayString>
    <Expand>
      <Item Name="[size]">n_elem</Item>
      <ArrayItems>
        <Size>n_elem </Size>
        <ValuePointer>mem</ValuePointer>
      </ArrayItems>
    </Expand>
  </Type>

  <Type Name="arma::Mat&lt;*&gt;">
    <DisplayString>{{ {n_rows} x {n_cols} = {n_elem} }}</DisplayString>
    <Expand>
      <IndexListItems>
        <Size>n_cols</Size>
        <ValueNode >
          mem+($i*n_rows),[n_rows]
        </ValueNode>
      </IndexListItems>
    </Expand>
  </Type>



  <Type Name="arma::subview_col&lt;*&gt;">
    <DisplayString>{{ {n_rows} }}</DisplayString>
    <Expand>
      <ArrayItems>
        <Size>n_rows</Size>
        <ValuePointer>colmem</ValuePointer>
      </ArrayItems>
    </Expand>
  </Type>






</AutoVisualizer> 

And Result image in debugger:

enter image description here

like image 76
saeed Avatar answered Sep 21 '22 00:09

saeed


You may use visualizers in Visual Studio, don´t know from which version but in Visual Studio 2015 you may add a .natvis file to the project.

arma.natvis:

<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
    <Type Name="arma::Col&lt;*&gt;">
        <DisplayString>{{ Size = {n_elem} }}</DisplayString>
        <Expand>
            <Item Name="[size]">n_elem</Item>
            <ArrayItems>
              <Size>n_elem </Size>
              <ValuePointer>mem</ValuePointer>
            </ArrayItems>
        </Expand>
    </Type>
    <Type Name="arma::Mat&lt;*&gt;">
        <DisplayString>{{ Size = {n_rows} x {n_cols} }}</DisplayString>
        <Expand>
            <Item Name="[size]">n_elem</Item>
            <ArrayItems>
                <Direction>Backward</Direction>
                <Rank>2</Rank>
                <Size>$i==0 ? n_rows : n_cols</Size>
                <ValuePointer>mem</ValuePointer>
            </ArrayItems>
        </Expand>
    </Type>
</AutoVisualizer>

This will show you readable data for the basic ARMADILLO types.

An example of how some types are showed: enter image description here

like image 34
Claes Rolen Avatar answered Sep 17 '22 00:09

Claes Rolen