首页 \ 问答 \ 犰狳vs Eigen3时间差异(Armadillo vs Eigen3 Timing Difference)

犰狳vs Eigen3时间差异(Armadillo vs Eigen3 Timing Difference)

我希望这个讨论可能会帮助其他任何与Armadillo和Eigen有关的问题3。

我编写了一个包装类Mat,它包含来自armadillo库的arma :: Mat或来自Eigen3库的Eigen :: Matrix。 这是在编译时用一个标志来控制的。

另外,我已经写了一个使用Mat作为存储的Tensor类。 这个类的主要特征是使用Voigt符号来压缩高阶张量以正确存储在矩阵中。

最后,我编写了一个多次乘以二阶张量(即矩阵)和一阶张量(即矢量)的测试,并记录完成算子所需的时间。 我通过我的Mat类和Tensor类来做到这一点。

由于Tensor包裹了Mat,我预计它的时间会更长。 犰狳就是这种情况,平均接近20%。 但是,使用Eigen时,使用张量更快,这对我来说毫无意义。

有什么东西贴到任何人身上?

编辑:提供更多细节。

我已经首先将arma :: Mat包裹到myOwn :: armaMat和Eigen :: Matrix中myOwn :: eigenMat。 这两者都将Armadillo和Eigen的API包装到一个通用框架中。 最后,根据编译器标志,myOwn :: Mat包装armaMat或eigenMat。 我不确定我们打开的任何优化标志。

如上所述,myOwn :: Tensor使用myOwn :: Mat作为存储。 由于我将使用Tensor类的物理应用程序,它被模板化为2D(即,如果是2阶的2乘2)或3D(即3乘3)。 (相比之下,垫可以是任何尺寸)。

我用于计时目的的操作员是:2乘2矩阵(2阶张量)乘以2乘1矩阵(1阶张量)。 当仅使用Mat时,我基本上使用了犰狳或Eigen的表达模板。

当使用我的Tensor类时,我会重载operator *

template< typename T1, bool Sym >
moris::Mat< T1 >
operator*(
        moris::Tensor< T1, 2, 2, true > const & aTensor1,
        moris::Tensor< T1, 1, 2, Sym >  const & aTensor2 )
{

    moris::Mat< T1 > tVector(2, 1);

    tVector(0) = aTensor1[0]*aTensor2[0] + aTensor1[2]*aTensor2[1];
    tVector(1) = aTensor1[2]*aTensor2[0] + aTensor1[1]*aTensor2[1];

    return tVector;
}

Tensor上的[]运算符从底层存储Mat(通过Voigt约定)访问数据。


My hope is that this discussion might help anyone else having issues with Armadillo and Eigen3.

I've written a wrapper class, Mat, that wraps either an arma::Mat from the armadillo library or an Eigen::Matrix from the Eigen3 library. This is controlled with a flag at compile time.

Additionally, I've written a Tensor class which uses a Mat as storage. The primary feature of this class is the use of Voigt notation to condense higher order tensors to be properly stored in a matrix.

Finally, I've written a test that multiplies a 2nd order tensor (i.e. a matrix) and a 1st order tensor (i.e. a vector) multiple times and records the time it takes to complete the operators. I do this with my Mat class and with my Tensor class.

Because Tensor wraps Mat, I would expect its time to be larger. This is the case with Armadillo, close to 20% on average. However, when using Eigen, using Tensor is faster, which makes absolutely no sense to me.

Does anything stick out to anyone?

EDIT: Providing more details.

I've first wrapped arma::Mat into myOwn::armaMat and Eigen::Matrix into myOwn::eigenMat. Both of these simply wrap armadillo and Eigen's API into a common framework. Finally, based on a compiler flag, myOwn::Mat wraps an armaMat or an eigenMat. I'm not sure about any optimization flags we have turned on.

As described above, myOwn::Tensor uses myOwn::Mat as a storage. Because of the physical applications I'll be using the Tensor class for, it is templated to be 2D (i.e. 2-by-2 if it's 2nd order) or 3D (i.e. 3-by-3). (In contrast, Mat can be of any size).

The operator I'm using for timing purposes is: a 2-by-2 matrix (2nd order tensor) times a 2-by-1 matrix (1st order tensor). When using only Mat, I'm essentially using armadillo's or Eigen's expression templating.

When using my Tensor class, I'm overloading operator* as such:

template< typename T1, bool Sym >
moris::Mat< T1 >
operator*(
        moris::Tensor< T1, 2, 2, true > const & aTensor1,
        moris::Tensor< T1, 1, 2, Sym >  const & aTensor2 )
{

    moris::Mat< T1 > tVector(2, 1);

    tVector(0) = aTensor1[0]*aTensor2[0] + aTensor1[2]*aTensor2[1];
    tVector(1) = aTensor1[2]*aTensor2[0] + aTensor1[1]*aTensor2[1];

    return tVector;
}

The [] operator on Tensor accesses data form the underlying storage Mat (via Voigt convention).


原文:https://stackoverflow.com/questions/34622006
更新时间:2023-10-20 06:10

最满意答案

转到您提供Bootstrap链接和脚本的主文件或html页面并添加这些内容

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

检查这些原始脚本是否更改了视图


Go to your main file or html page where you have given Bootstrap links and scripts and add these

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

Check if these original script changes the view

相关问答

更多
  • 您需要编写jquery代码以从标签或DOM元素获取值并显示在相应的输入框上。 value = $(“#labelid”)。val(); 但是你需要使HTML标准化,就像使用标签的唯一ID一样。 you need to write jquery code to get values from labels or DOM elements and display on respective input boxes. value = $("#labelid").val(); But you need to mak ...
  • 删除'form-group'并尝试这样的事情...... .navbar-form {width:62%;white-space:nowrap;} 它不会完全填充正确的空间(由于浮动右侧导航),但它将占用大部分导航栏。 演示: http : //bootply.com/91377# Remove the 'form-group' and try something like this... .navbar-form {width:62%;white-space:nowrap;} It won't com ...
  • 很可能不包括Manifest中的xLargeScreens: http://developer.android.com/guide/topics/manifest/supports-screens-element.html 希望这是/并帮助。
  • 尝试仅在输入的父div元素上设置col类,然后输入元素将占用此父元素的100%全宽,因为Bootstrap的form-control css类。