【问题标题】:Is there a way to print an Armadillo matrix or vector in Visual Studio Debug?有没有办法在 Visual Studio Debug 中打印犰狳矩阵或向量?
【发布时间】:2014-12-12 18:53:49
【问题描述】:

我想知道是否有任何方法可以在 Visual Studio(特别是 VS2012)的调试部分中显示向量/矩阵条目值。

这个问题与发表在:

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

但是我没有弄清楚这种方法是否也适用于 VS。

谢谢。

【问题讨论】:

    标签: visual-studio debugging visual-studio-2012 visual-studio-debugging armadillo


    【解决方案1】:

    这个.natvis XML 代码在 Visual Studio 2013 中工作正常。我在 Visual Studio 2013 中添加了@Claes Rolen XML,但对我来说不能正常工作。

    诀窍是使用<IndexListItems> 可视化犰狳矩阵

    声明并初始化代码

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

    .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>{{ {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> 
    

    调试器中的结果图像:

    【讨论】:

    • 如何在我的论文中引用这个答案??
    • 只需谷歌it
    • 像犰狳这样一个不错的库应该以调试助手的形式将这些技巧贡献给文档和论坛。
    • 非常感谢。只是为了确认一下,您是否开发了 Natvis 文件,如果没有,请您提供该程序的原始来源。好像它不是由最初的 Armadillo 开发人员 Sanderson 和 Curtin 开发的,因为我找不到源??
    • 我通过阅读 Microsoft 文档开发了这个 natvis 文件,如果您想从中获得更多信息,可以看看。这个贡献是我做的。
    【解决方案2】:

    您可以在 Visual Studio 中使用可视化工具,不知道从哪个版本开始,但在 Visual Studio 2015 中,您可以将 .natvis 文件添加到项目中。

    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>
    

    这将显示基本ARMADILLO 类型的可读数据。

    显示某些类型的示例:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多