// test_prod.cpp: Exploring syntax for matrix-matrix multiplication in uBLAS #define BIND_FORTRAN_LOWERCASE_UNDERSCORE #include #include #include #include #include #include using namespace boost::numeric::bindings::lapack; using namespace boost::numeric::ublas; int main(int argc, char* argv[]) { // Now try to compute some matrix products // Question 1: Is there a neater syntax to set all elements of a matrix to zero? matrix, column_major> A4(zero_matrix> (4, 4)); A4(0,0)=2; A4(0,1)=4; A4(1,0)=1; A4(1,1)=3; A4(2,0)=0; A4(2,3)=std::complex(7.1,-3.88); A4(3,0)=0; A4(3,1)=3.2; matrix, column_major> B4(zero_matrix> (4, 4)); B4(0,0)=11; B4(0,1)=3; B4(1,0)=1.2; B4(1,1)=-1; B4(2,0)=1; B4(2,3)=std::complex(9,1); B4(3,0)=-3.338; B4(3,1)=3.2; // Question 2: Is there a better way to pretty-print a matrix for debugging? std::cout << std::endl << std::endl << "A4 = " << A4 << std::endl; std::cout << std::endl << std::endl << "B4 = " << B4 << std::endl; matrix, column_major> vecs4 (4,4); vector> w4(4); // Question 3: Is this syntax the "correct" way to call geev? geev(A4,w4,(matrix, column_major>*)NULL,&vecs4,boost::numeric::bindings::lapack::optimal_workspace()); std::cout << "eigenvals (w4) = " << w4 << std::endl << "eigenvecs (vecs4) = " << vecs4 << std::endl; // Now test multiplying matrices together: std::cout << "Testing matrix products: " << std::endl; std::cout << "vecs4 * A4 = " << prod(vecs4,A4) << std::endl; std::cout << "vecs4 * A4 = " << matrix, column_major>(prod(vecs4,A4)) << std::endl; // Question 4: Why does this next line fail? //std::cout << "vecs4 * A4 = " << prod, column_major>>(vecs4,A4) << std::endl; // Question 5: Why can I not do prod(prod(...)) like in this next line? //std::cout << "vecs4 * A4 * vecs4 = " << prod(prod(vecs4,A4),vecs4) << std::endl; return 0; }