使用高级构造函数将数组转换为armadillo vec

时间:2017-04-25 13:54:43

标签: c++ armadillo

我正在尝试将ODE_vector类型的对象转换为armadillo vec,以便新对象将继承armadillo库的线性代数功能。作为问题的一个简单示例,我正在使用C ++数组进行演示:

#include <iostream>
#include <random>
#include <armadillo>

using namespace std;
using namespace arma;

int main() {

double b1 = 0.2;
double b2 = 0.1;
const double state[2] = {b1, b2};

rowvec B(&state[0], 2);
cout << B << endl;

mat A(2,2); A.fill(0.2); A.diag().ones();
cout << A << endl;

cout << B(0) * A(0,0) << endl;    // x

return 0;

}

b1和b2中包含的数据保存在B的元素中,以便运行此脚本返回以下内容:

   0.2000
   0.1000

   1.0000   0.2000
   0.2000   1.0000

0.2

但是,如果我用

替换上面的第x行
cout << B * A << endl;

我得到的错误表明B没有继承标准的犰狳线性代数功能:

[ 50%] Building CXX object CMakeFiles/untitled.dir/main.cpp.o
[100%] Linking CXX executable untitled
CMakeFiles/untitled.dir/main.cpp.o: In function `void arma::blas::gemv<double>(char const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)':
/usr/include/armadillo_bits/wrapper_blas.hpp:36: undefined reference to `wrapper_dgemv_'
CMakeFiles/untitled.dir/main.cpp.o: In function `void arma::blas::gemm<double>(char const*, char const*, int const*, int const*, int const*, double const*, double const*, int const*, double const*, int const*, double const*, double*, int const*)':
/usr/include/armadillo_bits/wrapper_blas.hpp:71: undefined reference to `wrapper_dgemm_'
collect2: error: ld returned 1 exit status
CMakeFiles/untitled.dir/build.make:94: recipe for target 'untitled' failed
make[3]: *** [untitled] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/untitled.dir/all' failed
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/untitled.dir/rule' failed
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
Makefile:118: recipe for target 'untitled' failed
make: *** [untitled] Error 2

任何人都可以解释如何正确使用高级构造函数(arma documentation)来实现这一点吗?

由于

1 个答案:

答案 0 :(得分:0)

您需要在乘法中使用正确的格式。 B型是2x1,A是2x2。改为

mat B(&state[0], 1,2);

rowvec B(&state[0], 2);