Boost logo

Ublas :

From: Preben Hagh Strunge Holm (preben_at_[hidden])
Date: 2007-03-08 04:33:20


Preben Hagh Strunge Holm skrev:
> Hi
>
> When I compile with -O2 I have problems - with no optimization there's
> no problem at all.
>
> What I do is:
>
> -----
> namespace ublas = boost::numeric::ublas;
>
> ...
>
> void MechComputer::ConstraintCorrection(const ublas::vector<double>& m,
> ublas::vector<double>& q,
> ublas::vector<double>& v,
> double qerror,
> double verror,
> unsigned int limit) {
> 614 // Loop
> 615 unsigned int count = 0;
> 616 ublas::vector<double> G = _system.Constraints(q);
> 617 ublas::compressed_matrix<double> dG = _system.DConstraints(q);
> 618 ublas::vector<double> dGv = prod(dG,v);
> 619 std::cout << "...619..." << std::endl;
> -----
>
> there is no problem until line 618 - it never get's to line 619..
>
> Since this is a function the ublas::vector<double> dGv = prod(dG,v)
> should be assigned on the stack at the moment of the creation of prod(dG,v).
>
> However this seems to become a problem (sometimes).
>
> Here is the debug-session from gdb:
> -----
> 618 ublas::vector<double> dGv = prod(dG,v);
> (gdb) n
> 617 ublas::compressed_matrix<double> dG =
> _system.DConstraints(q);
> (gdb)
> 618 ublas::vector<double> dGv = prod(dG,v);
> (gdb)
> 2598 return size1_;
> (gdb)
> 618 ublas::vector<double> dGv = prod(dG,v);
> (gdb)
> 65 if (size_) {
> (gdb)
> 64 alloc_(a), size_ (size) {
> (gdb)
> 65 if (size_) {
> (gdb)
> 87 if (__builtin_expect(__n > this->max_size(), false))
> (gdb)
> 90 return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
> (gdb)
> 66 data_ = alloc_.allocate (size_);
> (gdb)
> 74 vector_assign<scalar_assign> (*this, ae);
> (gdb)
> Assertion failed in file
> ../../RobWork/ext/boost/numeric/ublas/detail/vector_assign.hpp at line 371:
> detail::expression_type_check (v, cv)
> Qt has caught an exception thrown from an event handler. Throwing
> exceptions from an event handler is not supported in Qt. You must
> reimplement QApplication::notify() and catch all exceptions there.
>
> terminate called after throwing an instance of
> 'boost::numeric::ublas::external_logic'
> what(): external logic
>
> Program received signal SIGABRT, Aborted.
> 0xffffe410 in __kernel_vsyscall ()
> (gdb)
> -----
>
> so what is wrong with this? Why does vector_assign fail here? And only
> when optimization is done?
>
>
> Can anyone explain this to me? Do I assign the ublas::vector incorrectly?

Some further information:

Just before crashing I try to print _v:
--------------------------------------------------------------
(gdb) print _v
$1 =
{<boost::numeric::ublas::vector_container<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double, std::allocator<double> >
> >> =
{<boost::numeric::ublas::vector_expression<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double, std::allocator<double> >
> >> =
{<boost::numeric::ublas::ublas_expression<boost::numeric::ublas::vector<double,
boost::numeric::ublas::unbounded_array<double, std::allocator<double> >
> >> = {<No data fields>}, static complexity = <optimized out>}, static
complexity = 0},
   data_ =
{<boost::numeric::ublas::storage_array<boost::numeric::ublas::unbounded_array<double,
std::allocator<double> > >> =
{<boost::numeric::ublas::nonassignable_::nonassignable> = {<No data
fields>}, <No data fields>},
     alloc_ = {<__gnu_cxx::new_allocator<double>> = {<No data fields>},
<No data fields>}, size_ = 72, data_ = 0x837bde8}}
--------------------------------------------------------------

and printing dG:
--------------------------------------------------------------
(gdb) print dG
$3 =
{<boost::numeric::ublas::matrix_container<boost::numeric::ublas::compressed_matrix<double,
boost::numeric::ublas::basic_row_major<unsigned int, int>, 0u,
boost::numeric::ublas::unbounded_array<unsigned int,
std::allocator<unsigned int> >,
boost::numeric::ublas::unbounded_array<double, std::allocator<double> >
> >> =
{<boost::numeric::ublas::matrix_expression<boost::numeric::ublas::compressed_matrix<double,
boost::numeric::ublas::basic_row_major<unsigned int, int>, 0u,
boost::numeric::ublas::unbounded_array<unsigned int,
std::allocator<unsigned int> >,
boost::numeric::ublas::unbounded_array<double, std::allocator<double> >
> >> =
{<boost::numeric::ublas::ublas_expression<boost::numeric::ublas::compressed_matrix<double,
boost::numeric::ublas::basic_row_major<unsigned int, int>, 0u,
boost::numeric::ublas::unbounded_array<unsigned int,
std::allocator<unsigned int> >,
boost::numeric::ublas::unbounded_array<double, std::allocator<double> >
> >> = {<No data fields>},
       static complexity = <optimized out>}, static complexity =
<optimized out>}, size1_ = 66, size2_ = 72,
   capacity_ = 1056, filled1_ = 67, filled2_ = 822,
   index1_data_ =
{<boost::numeric::ublas::storage_array<boost::numeric::ublas::unbounded_array<unsigned
int, std::allocator<unsigned int> > >> =
{<boost::numeric::ublas::nonassignable_::nonassignable> = {<No data
fields>}, <No data fields>},
     alloc_ = {<__gnu_cxx::new_allocator<unsigned int>> = {<No data
fields>}, <No data fields>}, size_ = 67,
     data_ = 0x837b718},
   index2_data_ =
{<boost::numeric::ublas::storage_array<boost::numeric::ublas::unbounded_array<unsigned
int, std::allocator<unsigned int> > >> =
{<boost::numeric::ublas::nonassignable_::nonassignable> = {<No data
fields>}, <No data fields>},
     alloc_ = {<__gnu_cxx::new_allocator<unsigned int>> = {<No data
fields>}, <No data fields>}, size_ = 1056,
     data_ = 0x837f170},
   value_data_ =
{<boost::numeric::ublas::storage_array<boost::numeric::ublas::unbounded_array<double,
std::allocator<double> > >> =
{<boost::numeric::ublas::nonassignable_::nonassignable> = {<No data
fields>}, <No data fields>},
     alloc_ = {<__gnu_cxx::new_allocator<double>> = {<No data fields>},
<No data fields>}, size_ = 1056, data_ = 0x8382398},
   static zero_ = 0}
(gdb)
--------------------------------------------------------------

It's nice to see that the matrix is of size:
size1_ = 66, size2_ = 72

but I don't know if it's nice to see that index1_data_ and index2_data_
doesn't match these sizes. _index1_data_ is of size 67 and index2_data_
of size 1056... Does this matter?

Thanks for helping

Best regards,
Preben Holm