2

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.

This 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?

Rafael S. Calsaverini
  • 13,582
  • 19
  • 75
  • 132
  • I don't fully understand what is going on but I have found a few things out. Your code does work if I change the symatrix typedef into double type symmetric_matrix and int matrix. So it appears that the prod function does like your return type. – Joseph Lisee May 02 '11 at 18:47

1 Answers1

2

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.

Joseph Lisee
  • 3,439
  • 26
  • 21
  • That may be the problem. That's a shame though, cause the square of a symmetric matrix is also symmetric. Anyway, I should use a general matrix type. :( – Rafael S. Calsaverini May 03 '11 at 00:37