Boost logo

Ublas :

Subject: [ublas] Nested product of matrices and the BOOST_UBLAS_SIMPLE_ET_DEBUG macro
From: Marco Guazzone (marco.guazzone_at_[hidden])
Date: 2010-07-14 11:18:46


Hi,

Is there a way to nest product of matrices like this (see last lines):

--- [code] ---
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <cstddef>
#include <iostream>

namespace ublas = boost::numeric::ublas;

int main()
{
    typedef ublas::matrix<double> matrix_type;

    const std::size_t n = 2;

    matrix_type A(n,n,1);
    matrix_type B(n,n,2);
    matrix_type C(n,n,3);

    matrix_type X;

    X = ublas::prod(ublas::prod(A,B), C);

    std::cout << "A*B*C = " << X << std::endl;
}
--- [/code] ---

If I compile this, the compiler (GCC 4.4.4) issues these errors:

--- [error] ---
In file included from
/home/marco/tmp/boost-trunk/boost/numeric/ublas/matrix.hpp:17,
                 from matrix_nested_prod.cpp:1:
/home/marco/tmp/boost-trunk/boost/numeric/ublas/matrix_expression.hpp:
In function ‘typename
boost::numeric::ublas::matrix_matrix_binary_traits<typename
E1::value_type, E1, typename E2::value_type, E2>::result_type
boost::numeric::ublas::prod(const
boost::numeric::ublas::matrix_expression<E>&, const
boost::numeric::ublas::matrix_expression<E2>&) [with E1 =
boost::numeric::ublas::matrix_matrix_binary<boost::numeric::ublas::matrix<double,
boost::numeric::ublas::basic_row_major<long unsigned int, long int>,
boost::numeric::ublas::unbounded_array<double, std::allocator<double>
> >, boost::numeric::ublas::matrix<double,
boost::numeric::ublas::basic_row_major<long unsigned int, long int>,
boost::numeric::ublas::unbounded_array<double, std::allocator<double>
> >, boost::numeric::ublas::matrix_matrix_prod<boost::numeric::ublas::matrix<double,
boost::numeric::ublas::basic_row_major<long unsigned int, long int>,
boost::numeric::ublas::unbounded_array<double, std::allocator<double>
> >, boost::numeric::ublas::matrix<double,
boost::numeric::ublas::basic_row_major<long unsigned int, long int>,
boost::numeric::ublas::unbounded_array<double, std::allocator<double>
> >, double> >, E2 = boost::numeric::ublas::matrix<double,
boost::numeric::ublas::basic_row_major<long unsigned int, long int>,
boost::numeric::ublas::unbounded_array<double, std::allocator<double>
> >]’:
matrix_nested_prod.cpp:19: instantiated from here
/home/marco/tmp/boost-trunk/boost/numeric/ublas/matrix_expression.hpp:4815:
error: invalid application of ‘sizeof’ to incomplete type
‘boost::STATIC_ASSERTION_FAILURE<false>’
matrix_nested_prod.cpp:19: instantiated from here
/home/marco/tmp/boost-trunk/boost/numeric/ublas/matrix_expression.hpp:4815:
error: invalid application of ‘sizeof’ to incomplete type
‘boost::STATIC_ASSERTION_FAILURE<false>’
--- [/error] ---

Strangely, it compiles and runs OK if I defines the
"BOOST_UBLAS_SIMPLE_ET_DEBUG" macro
  g++ -DBOOST_UBLAS_SIMPLE_ET_DEBUG -Wall -pedantic -ansi -lm ...

I've found this macro is used in the "matrix_matrix_binary_traits" class:

#ifndef BOOST_UBLAS_SIMPLE_ET_DEBUG
        typedef expression_type result_type;
#else
        typedef typename E1::matrix_temporary_type result_type;
#endif

but I don't know its purpose (and when to enable/disable it).

Any idea?

Thank you very much!!

Cheers,

-- Marco