Problem with boost ublas matrix product
I'm trying to use the ublas part of Boost but I'm not able to multiply matrices and assign the result to other matrices for some reason.
开发者_如何学CThis works:
#include <boost/numeric/ublas/symmetric.hpp>
#include <boost/numeric/ublas/io.hpp>
using namespace boost::numeric::ublas;
typedef symmetric_matrix<int,lower> symatrix;
int main() {
int N = 10;
symatrix foo(N,N);
for (int i = 0; i < N; i++)
for(int j = 0; j <= i; j++) {
foo(i,j) = i - j + 1;
}
symatrix goo(foo);
//goo = prod(foo,foo);
std::cout << prod(foo,foo)<< std::endl;
}
But if I uncomment the line goo = prod(foo,foo);
or try something like:
symatrix goo = prod(foo,foo);
I get a runtime error I can't decipher.
Check failed in file /usr/include/boost/numeric/ublas/detail/matrix_assign.hpp at line 761:
detail::expression_type_check (m, cm)
terminate called after throwing an instance of 'boost::numeric::ublas::external_logic'
what(): external logic
Aborted
How do I multiply matrices and assign the result?
You are not guaranteed to always get a symmetric matrix back when you multiply two symmetric matrices. So this error might be related to that, although I have no idea why the code works when I change your type to a symmetric_matrix type to a double.
精彩评论