代码之家  ›  专栏  ›  技术社区  ›  maxsieg

犰狳点积C++

  •  0
  • maxsieg  · 技术社区  · 7 年前

    我目前正在使用Ubuntu代码::blocks,在尝试做线性代数时遇到了一些问题。

    在编译器设置下>搜索目录>编译器i have“/usr/include”

    在编译器设置下>搜索目录>链接器i have“/user/lib”

    我的liblapack dev、libblas dev、libboost dev、libarmadillo dev通过apt get安装

    我评论了代码的哪一部分给了我错误。没有代码中的困难部分,我的代码运行良好,所以我认为armadillo安装得很好?为什么我不能访问它的所有功能?

    #include <iostream>
    #include <armadillo>
    using namespace arma;
    using namespace std;
    int main()
    {
        mat A;
        A<<1<<2<<endr<<3<<4;
        cout<<A;
        vec e=A.col(0);
        vec r=A.col(1);
        cout<<endl<<e<<endl<<r<<endl;//works perfectly up to here
        //if only there was not more of these codes
        cout<<e*r<<endl;//doesnt work from here anymore
        float y=dot(A,A);//from here on i get the error message:
        cout<<y<<endl;//'wrapper_ddot_' is not defined
        double z=as_scalar(e*r);//and wrapper_blas.hpp file opens
        double t=dot(e,r);
        cout<<z<<endl;//and points me to line 185
        return 0;//with an error
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Claes Rolen    7 年前

    代码中有一个bug。您正在使用 e*r 但它们都是2x1,所以你需要转置 e e.t()*r 所以你得到一个1x1乘积。下面三行也有同样的问题。如果你安装犰狳使用 apt-get 通常不需要添加blas/lapack LIB。使用 -larmadillo 链接器的标志。