Hello
there,
I've observed an
unexpected result when I use vector_slice with the following
code:
typedef
boost::numeric::ublas::vector<double> udvector;
typedef
boost::numeric::ublas::vector<float> uvector;
size_t block_size = 3;
uvector v1(9);
udvector
v2(9);
for(size_t i=0; i<9; i++)
{
v1[i] = i;
v2[i] =
i+10;
}
cout <<
"v1="<<v1<<endl;
cout <<
"v2="<<v2<<endl;
boost::numeric::ublas::slice vs(0, 1,
block_size);
const
boost::numeric::ublas::vector_slice<const udvector> blk_v1(v1,
vs);
cout << "blk_v1=" << blk_v1
<< endl;
udvector
blk_v2(boost::numeric::ublas::project(v2, vs));
cout << "blk_v1=" << blk_v1
<< endl;
The ouput of the above code :
v1=[9](0,1,2,3,4,5,6,7,8)
v2=[9](10,11,12,13,14,15,16,17,18)
blk_v1=[3](0,1,2)
blk_v1=[3](10,11,12)
The last line
of the output shows that the content of the
vector_slice<const udvector> blk_v1 is wrong. I wonder if the problem is
due to the fact that vector_slice has the different type (double) as the vector v1(float). However, there is not any compilation warnings or errors for
this. Moreover, the problem doesn't show up if we just switch the
order of the two lines such that :
udvector blk_v2(boost::numeric::ublas::project(v2,
vs))
const boost::numeric::ublas::vector_slice<const
udvector> blk_v1(v1, vs);
could anyone
explain, thank you
Myt est environment:
Linux centos, gcc3_4, boost 1_38
Wenxuan
Teng