Boost logo

Ublas :

From: Hongyu Miao (jackymiao_at_[hidden])
Date: 2007-09-16 22:27:27


Problem Description:
  The following codes will generate some strange results:

    boost::numeric::ublas::matrix<double> A4(4,6);
        for (i=0; i<A4.size1(); i++)
        {
                for (j=0; j<A4.size2(); j++)
                {
                        A4(i,j) = i*A4.size2()-j;
                }
        }
    std::cout << A4 << std::endl;

  The results shoulde be
        [4,6]((0,-1,-2,-3,-4,-5),(6,5,4,3,2,1),(12,11,10,9,8,7),(18,17,16,15,14,13))

  However, I actually got:

    [4,6]((0,4.29497e+009,4.29497e+009,4.29497e+009,4.29497e+009,4.29497e+009),(6,5,4,3,2,1),(12,11,10,9,8,7),(18,17,16,15,14,13))

  If I change the code as follows, the problem is gone:
     ...
     int nTemp = A4.size2();
         A4(i,j) = i*nTemp-j;
     ...

  So the problem must be caused by

     A4(i,j) = i*A4.size2()-j;

  Any idea about this bug? Thanks.