Boost logo

Ublas :

From: Daniele (asloxx_at_[hidden])
Date: 2007-10-16 06:32:09


Ok, in a hurry, I think I've make some mistakes, but I've tracked down the
problem to this:
    ublas::matrix<double> A(2, 2), B(2, 2), C(2, 2);
    // initialize A and B ...
    C = prod(A, ublas::matrix<double>(prod(B, A))); // C = A*B*A this works
    C = prod(A, prod(B, A)); // C = A*B*A this doesn't work
Somebody knows why do I have to use a temporary for this expression, or am I
doing something wrong again?
Daniele

On 10/16/07, Daniele <asloxx_at_[hidden]> wrote:
>
> Hi all,
> I'm rather new to boost::ublas, and I was trying to use it to do some
> simple math in a C++ program (no big speed requirement here, yet).
> I have some code like the following (see below for a complete test):
>
> ublas::slice sl(0, 6, 3);
> // matlab equiv (I think): P([1 4], [1 4]) = A*P([1 4], [1 4])*A'
> + Q
> A and Q are 2x2, P is 6x6
> project(P, sl, sl) = prod(A, prod(project(P, sl, sl), trans(A))) +
> Q;
>
> but I get a static assertion triggered. This is the error gcc gives me
> (gcc 4.1.2, gentoo linux):
>
> /usr/include/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<double,
> boost::numeric::ublas::basic_row_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >,
> E2 =
> boost::numeric::ublas::matrix_matrix_binary<boost::numeric::ublas::matrix_slice<boost::numeric::ublas::matrix<double,
> boost::numeric::ublas::basic_row_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<double, std::allocator<double> > > >,
> boost::numeric::ublas::matrix_unary2<boost::numeric::ublas::matrix<double,
> boost::numeric::ublas::basic_row_major<unsigned int, int>,
> boost::numeric::ublas::unbounded_array<double, std::allocator<double> > >,
> boost::numeric::ublas::scalar_identity<double> >,
> boost::numeric::ublas::matrix_matrix_prod<double, double, double> >]':
> ublas_test.cpp:27: instantiated from here
> /usr/include/boost/numeric/ublas/matrix_expression.hpp:4637: error:
> invalid application of 'sizeof' to incomplete type
> 'boost::STATIC_ASSERTION_FAILURE<false>'
>
> and this is the assertion in matrix_expression.hpp:4647:
>
> BOOST_STATIC_ASSERT (E1::complexity == 0 && E2::complexity == 0)
>
> Any clue on what am I doing wrong?
>
>
> Thanks,
> Daniele
>
> P.S. this is the complete test program that I was trying to compile:
> #include <iostream>
> // boost ublas headers
> #include <boost/numeric/ublas/vector.hpp>
> #include <boost/numeric/ublas/matrix.hpp>
> #include <boost/numeric/ublas/io.hpp>
> #include <boost/numeric/ublas/vector_proxy.hpp>
> #include <boost/numeric/ublas/matrix_proxy.hpp>
>
> using namespace std;
> namespace ublas = boost::numeric::ublas;
>
>
> int main(void)
> {
> using ublas::project;
> ublas::matrix<double> P(4, 4);
> ublas::matrix<double> A(2, 2);
> ublas::matrix<double> Q(2, 2);
>
> // initialize P, A, Q ...
>
> ublas::slice sl(0, 6, 3);
> // matlab equiv (I think: P([1 4], [1 4]) = A*P([1 4], [1 4])*A' + Q
> project(P, sl, sl) = prod(A, prod(project(P, sl, sl), trans(A))) + Q;
>
> cout << P << endl;
> }
>
>