在犰狳中对立方体切片进行操作
Operating on slices of Cube in armadillo
我正在努力适应 C++ 的犰狳线性代数库,但我无法弄清楚如何对立方体的切片(矩阵)进行操作。每当我尝试对切片进行操作时,程序都会编译但不提供任何输出,甚至不提供切片操作之前的语句输出。
这是代码:
#include <armadillo>
#include <iostream>
using namespace arma;
using namespace std;
int main()
{
Cube<double> A(3 , 5 ,1, fill::randu);
Cube<double>B(5,3,1,fill::randu);
Mat<double>x =A.slice(0);
Mat<double>y = B.slice(0);
cout << x << "\n" << y << endl;
cout << x*y << endl; //code works fine if this line is removed
}
问题是如果删除最后一行,代码可以正常工作。为什么会这样?有没有更好的方法来操作立方体内的矩阵?
使用 问题的已接受答案中给出的说明,使用 Visual Studio 在 Windows 上安装 Armadillo。
如果您要求链接器使用 blas_win64_MT.lib
和 lapack_win64_MT.lib
库,请确保将相应的 .dll
添加到与您的 .exe
相同的目录中文件。然后使用此代码,我得到了所需的输出。
#include <armadillo>
#include <iostream>
using namespace std;
using namespace arma;
int main()
{
Cube<double> A(3, 5, 1, fill::randu);
Cube<double> B(5, 3, 1, fill::randu);
Mat<double> x = A.slice(0);
Mat<double> y = B.slice(0);
std::cout << "x:\n" << x << "\ny:\n" << y << std::endl;
std::cout << "x*y:\n" << x*y << std::endl;
}
命令输出window:
希望对您有所帮助!
我正在努力适应 C++ 的犰狳线性代数库,但我无法弄清楚如何对立方体的切片(矩阵)进行操作。每当我尝试对切片进行操作时,程序都会编译但不提供任何输出,甚至不提供切片操作之前的语句输出。 这是代码:
#include <armadillo>
#include <iostream>
using namespace arma;
using namespace std;
int main()
{
Cube<double> A(3 , 5 ,1, fill::randu);
Cube<double>B(5,3,1,fill::randu);
Mat<double>x =A.slice(0);
Mat<double>y = B.slice(0);
cout << x << "\n" << y << endl;
cout << x*y << endl; //code works fine if this line is removed
}
问题是如果删除最后一行,代码可以正常工作。为什么会这样?有没有更好的方法来操作立方体内的矩阵?
使用
如果您要求链接器使用 blas_win64_MT.lib
和 lapack_win64_MT.lib
库,请确保将相应的 .dll
添加到与您的 .exe
相同的目录中文件。然后使用此代码,我得到了所需的输出。
#include <armadillo>
#include <iostream>
using namespace std;
using namespace arma;
int main()
{
Cube<double> A(3, 5, 1, fill::randu);
Cube<double> B(5, 3, 1, fill::randu);
Mat<double> x = A.slice(0);
Mat<double> y = B.slice(0);
std::cout << "x:\n" << x << "\ny:\n" << y << std::endl;
std::cout << "x*y:\n" << x*y << std::endl;
}
命令输出window:
希望对您有所帮助!