相关疑难解决方法(0)

C中的优化矩阵乘法

我正在尝试比较矩阵乘法的不同方法.第一个是常规方法:

do
{
    for (j = 0; j < i; j++)
    {
        for (k = 0; k < i; k++)
        {
            suma = 0;
            for (l = 0; l < i; l++)
                suma += MatrixA[j][l]*MatrixB[l][k];
                MatrixR[j][k] = suma;
            }
        }
    }
    c++;
} while (c<iteraciones);
Run Code Online (Sandbox Code Playgroud)

第二个包括首先转置矩阵B然后按行进行乘法运算:

int f, co;
for (f = 0; f < i; f++) {
    for ( co = 0; co < i; co++) {
        MatrixB[f][co] = MatrixB[co][f];
    }
}

c = 0;
do
{
    for (j …
Run Code Online (Sandbox Code Playgroud)

c matrix

22
推荐指数
5
解决办法
5万
查看次数

使用Eigen比使用我自己的类更糟糕的表现

几周前,我问了一个关于矩阵乘法性能的问题.

有人告诉我,为了提高程序的性能,我应该使用一些专门的矩阵类而不是我自己的类.

StackOverflow用户推荐:

  • 的uBLAS
  • EIGEN
  • BLAS

起初我想使用uBLAS然而阅读文档,结果证明这个库不支持矩阵 - 矩阵乘法.

毕竟我决定使用EIGEN库.所以我交换了我的矩阵类Eigen::MatrixXd- 然而事实证明,现在我的应用程序比以前工作得更慢.使用EIGEN之前的时间是68秒,在将我的矩阵类交换到EIGEN矩阵程序后运行87秒.

花费最多时间的程序部分看起来像那样

TemplateClusterBase* TemplateClusterBase::TransformTemplateOne( vector<Eigen::MatrixXd*>& pointVector, Eigen::MatrixXd& rotation ,Eigen::MatrixXd& scale,Eigen::MatrixXd& translation )
{   
    for (int i=0;i<pointVector.size();i++ )
    {
        //Eigen::MatrixXd outcome =
        Eigen::MatrixXd outcome = (rotation*scale)* (*pointVector[i])  + translation;
        //delete  prototypePointVector[i];      // ((rotation*scale)* (*prototypePointVector[i])  + translation).ConvertToPoint();
        MatrixHelper::SetX(*prototypePointVector[i],MatrixHelper::GetX(outcome));
        MatrixHelper::SetY(*prototypePointVector[i],MatrixHelper::GetY(outcome));
        //assosiatedPointIndexVector[i]    = prototypePointVector[i]->associatedTemplateIndex = i;
    }

    return this;
}
Run Code Online (Sandbox Code Playgroud)

Eigen::MatrixXd AlgorithmPointBased::UpdateTranslationMatrix( int clusterIndex )
{
    double membershipSum = 0,outcome = 0;
    double currentPower = …
Run Code Online (Sandbox Code Playgroud)

c++ performance matrix eigen

10
推荐指数
4
解决办法
2万
查看次数

标签 统计

matrix ×2

c ×1

c++ ×1

eigen ×1

performance ×1