Boost logo

Ublas :

Subject: [ublas] Problems with identity_matrix<> / lu_substitute()
From: Pietro.Mele_at_[hidden]
Date: 2009-10-08 14:03:11


I have a problem compiling this code when instead of a numerical constant I use a variable or a const int as a size parameter to B(identity_matrix<float>(size)).
And even when it compiles using the numerical value, it runs only with values in the 1-4 range. A 5 will make it crash (Floating exception).

Thank you for your help.

Pietro


#include ...
using namespace boost::numeric::ublas;

int main()
{
    int size = 4;
  
//    matrix<float>  A(4, 4),  B(identity_matrix<float>(4));                     // OK with 1, 2, 3, 4.  Crash with 5, 6, ... (Floating exception)

    matrix<float>  A(size, size),  B(identity_matrix<float>(size));          // I will get a compile time error here ***, even if size is a const int
   
    for (int i = 0; i < size; ++i)
        for (int j = 0; j < size; ++j)
            A(i,j) =
rand() % 10;
       
    permutation_matrix<> pm(size);
   
    int result = lu_factorize<matrix<float>, permutation_matrix<> >(A, pm);
   
    if ( 0 == result ) {
        lu_substitute(A, pm, B);           // *** Here is where the error is generated
    }
    else
        cout << "Error at row " << result << endl;
}


Error message:

./testLUboost.cpp: In function `int main()':
./testLUboost.cpp:41: warning: the address of `boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > > B(boost::numeric::ublas::identity_matrix<float, std::allocator<float> >)', will always evaluate as `true'
./testLUboost.cpp:59: warning: the address of `boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > > B(boost::numeric::ublas::identity_matrix<float, std::allocator<float> >)', will always evaluate as `true'
/cadusr/cfd/pmele/libraries/boost_1_40_0/boost/numeric/ublas/lu.hpp: In function `void boost::numeric::ublas::lu_substitute(const M&, const boost::numeric::ublas::permutation_matrix<PMT, PMA>&, MV&) [with M = boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > >, PMT = size_t, PMA = boost::numeric::ublas::unbounded_array<size_t, std::allocator<size_t> >, MV = boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > > ()(boost::numeric::ublas::identity_matrix<float, std::allocator<float> >)]':
./testLUboost.cpp:56:   instantiated from here
/cadusr/cfd/pmele/libraries/boost_1_40_0/boost/numeric/ublas/lu.hpp:300: error: no matching function for call to `lu_substitute(const boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > >&, boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > > (&)(boost::numeric::ublas::identity_matrix<float, std::allocator<float> >))'
/cadusr/cfd/pmele/libraries/boost_1_40_0/boost/numeric/ublas/lu.hpp: In function `void boost::numeric::ublas::swap_rows(const PM&, MV&) [with PM = boost::numeric::ublas::permutation_matrix<size_t, boost::numeric::ublas::unbounded_array<size_t, std::allocator<size_t> > >, MV = boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > > ()(boost::numeric::ublas::identity_matrix<float, std::allocator<float> >)]':
/cadusr/cfd/pmele/libraries/boost_1_40_0/boost/numeric/ublas/lu.hpp:299:   instantiated from `void boost::numeric::ublas::lu_substitute(const M&, const boost::numeric::ublas::permutation_matrix<PMT, PMA>&, MV&) [with M = boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > >,PMT = size_t, PMA = boost::numeric::ublas::unbounded_array<size_t, std::allocator<size_t> >, MV = boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > > ()(boost::numeric::ublas::identity_matrix<float, std::allocator<float> >)]'
./testLUboost.cpp:56:   instantiated from here
/cadusr/cfd/pmele/libraries/boost_1_40_0/boost/numeric/ublas/lu.hpp:85: error: `boost::numeric::ublas::matrix<float, boost::numeric::ublas::basic_row_major<size_t, ptrdiff_t>, boost::numeric::ublas::unbounded_array<float, std::allocator<float> > > ()(boost::numeric::ublas::identity_matrix<float, std::allocator<float> >)' is not a class, struct, or union type


Boost 1.40.0
O.S.:  Linux (RedHat)
gcc:  3.4.6
kernel:  2.6.9-55.ELsmp









Pietro Mele
CFD Software Developer
T. +44 1235 777700
F. +44 1235 764705
attwilliams.com
____________________

Williams Grand Prix Engineering Limited. Registered in England no. 1297497. VAT no. GB292559325. This email is confidential. If you are not the addressee, please contact us by reply.