Ayush Chaurasia
Ayush Chaurasia

Reputation: 647

Operating on slices of Cube in armadillo

I am trying to get used to armadillo linear algebra library for c++ and I cannot figure out hot to operate on slices(matrices) of a cube. Whenever I try to operate on a slice, the program compiles but does not give any output, not even the outputs of statement before the slice operation. Here's the code:

#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
}

the problem is that the code works fine if the last line is removed. Why does this happen? Is there a better way to operate on matrices inside a cube ?

Upvotes: 1

Views: 1912

Answers (1)

kedarps
kedarps

Reputation: 861

Use directions given in the accepted answer to this question, to install Armadillo on Windows using Visual Studio.

If you have asked the Linker to use blas_win64_MT.lib and lapack_win64_MT.lib libraries, make sure to add the respective .dll's in the same directory as your .exe file. Then using this code, I get the desired output.

#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;
}

Output in command window:

Armadillo Cube Demo

Hope that helps!

Upvotes: 1

Related Questions