7

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.

Community
  • 1
  • 1
dspGI
  • 71
  • 5

2 Answers2

5

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

saeed
  • 2,477
  • 2
  • 23
  • 40
  • 1
    how can I cite this answer in my thesis?? – The_Learner Aug 23 '19 at 05:00
  • just google [it](https://meta.stackexchange.com/questions/49760/citing-stack-overflow-discussions). – saeed Aug 23 '19 at 19:50
  • such a nice library like armadillo should contribute these tricks to documentations and forums in the term of debug helpers. – saeed Aug 23 '19 at 19:59
  • Thank you very much. Just to confirm, have you developed the Natvis file, if not could you please provide the original source of this program. Seems like it is not developed by the original Armadillo developers Sanderson and Curtin, as I could not find the source?? – The_Learner Sep 05 '19 at 05:39
  • I've developed this natvis file by reading Microsoft documentations, you may have a look if you want to get more out of it. This contribute was done by me. – saeed Sep 07 '19 at 13:24
3

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

Claes Rolen
  • 1,446
  • 1
  • 9
  • 21