Boost logo

Boost Users :

From: jhr.walter_at_[hidden]
Date: 2003-04-29 01:57:40


Hi Zhang,

you wrote:

> I just write a simple program to test the efficiency of sparse matrix
> operation in uBLAS and get the following error message on a FreeBSD
> with gcc 2.95 :
>
> !gmake 2>&1| tee /tmp/v446688/2g++ -c test.cpp -I.
> -I/usr/local/include -Wall -g -O2 -march=i686 -pipe
> -ftemplate-depth-30 -g3 -O0 -o test.o
> g++ test.o -o a.out
> test.o: In function `pair<unsigned int, unsigned int> *
> __copy_backward<pair<unsigned int, unsigned int> *, pair<unsigned
> int, unsigned int> *, int>(pair<unsigned int, unsigned int> *,
> pair<unsigned int, unsigned int> *, pair<unsigned int,
> unsigned int> *, random_access_iterator_tag, int *)':
> /usr/include/g++/stl_algobase.h
>(.gnu.linkonce.t.norm_inf__Q45boost7numeric5ublast11type_traits1ZUiRCUi+0x1
5):
> undefined reference to `boost::numeric::ublas::type_traits<unsigned
> int>::imag(unsigned int const &)'
> /usr/include/g++/stl_algobase.h

[snip more linker messages]

> If I comment out the second prod() or use -DNDEBUG
> everything is ok. So I suspect the
> error is caused by debug code in sparse matrix prod operation.
>
> here is the main code block:

I've stumbled across a similar problem some time ago and silently fixed it
in my code base. The following (slightly edited ;-) test compiles fine for
me:

----------
#include <iostream>
#include <boost/progress.hpp>
#include <boost/numeric/ublas/matrix_sparse.hpp>

 int main(int argc,char* argv[]) {
     namespace ublas = boost::numeric::ublas;
     using namespace ublas;
     size_t d = 7000;
     ublas::vector<unsigned> v(d);
     ublas::matrix<unsigned> m (d,d);
     ublas::sparse_matrix<unsigned> ms (d,d);
     for (size_t i = 0;i < 10000;++i) {
         size_t r = (size_t)(drand48() * d);
         size_t c = (size_t)(drand48() * d);
         ++m(r,c);
         ++ms(r,c);
         ++v(r);
         ++v(c);
     }

    {
         boost::progress_timer t;
         std::cout << "matrix * vector" << std::endl;
         ublas::prod(m,v);
     }

    {
         boost::progress_timer t;
         std::cout << "sparse matrix * vector" << std::endl;
         ublas::prod(ms,v);
     }
 }

----------

The reason for the problem is that you're using integral types instead of
floating point types as far as I see. The class template
ublas::type_traits<> in traits.hpp currently contains some functions, which
are only declared, but not defined. So you've probably at least three
options to proceed:
- switch to floating point types
- fix the type_traits<> class yourself
- look into the latest development version at
http://groups.yahoo.com/group/ublas-dev/files

HTH,

Joerg


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net