Boost logo

Ublas :

From: Manoj Rajagopalan (rmanoj_at_[hidden])
Date: 2006-11-18 18:13:24


Hi,

   I am writing a function named initialize that I'd like to work for
both matrix<> and matrix_range<> objects. Since both inherit
matrix_expression<> at some level, the type for the matrix parameter is
matrix_expression.

   The following code snippet compiles but on running the initialize()
function outputs the size of my 5 x 7 matrix to be 2212603904 x 78716607 !!!

    Would anyone know why this is happening? Looks like the conversion
of a negative int to an unsigned type somewhere but how would this enter
the picture?

Thanks in advance,
Manoj

// ------------- Code Snippet ---------------------

template<typename E>
void initialize(matrix_expression<E> A,
                 typename E::value_type const& value)
{
     E& A_ref = static_cast<E&>(A);
     cout << "initialize: size = (" << A_ref.size1() << ','
          << A_ref.size2() << ')' << endl;
     A_ref = scalar_matrix<typename E::value_type>(A_ref.size1(),
A_ref.size2(), value);
}

int main(void)
{
     matrix<int> A(5, 7);
     initialize(A, 4);
     // initialize(subrange(A, 1, 3, 1, 3), 8);
     pretty_print(A); // my function to display the matrix as a rectangle
     return 0;
}