Boost logo

Boost Users :

From: jhr.walter_at_[hidden]
Date: 2003-04-07 02:22:15


Hi Stephan,

you wrote:

> (I am using boost 1.30 & gcc 3.2)
>
> the following program:
>
> #include <boost/numeric/ublas/matrix.hpp>
> #include <boost/numeric/ublas/io.hpp>
>
> int main () {
> using namespace boost::numeric::ublas;
> matrix<double> m (4, 4);
> for (unsigned int i = 0; i < m.size1 (); ++ i)
> for (unsigned int j = 0; j < m.size2 (); ++ j)
> m(i, j) = 1;
>
> std::cout << m << std::endl;
>
> // multiply a slice of the matrix with 2....
> project (m, slice (2, 1, m.size1()-2), slice (1, 0, m.size1()-2)) *=
2;
>
> // interesting result ... the slice has been multiplied with 4
> std::cout << m << std::endl;
> }
>
> gives the following output:
>
> [4,4]((1,1,1,1),(1,1,1,1),(1,1,1,1),(1,1,1,1))
> [4,4]((1,1,1,1),(1,1,1,1),(1,4,1,1),(1,4,1,1))
>
> Why is the slice multiplied with 4 and not with 2?? Do I make some
> fundamental mistake?

The second slice 'slice (1, 0, m.size1()-2)' is degenerate in specifying a
stride of 0, but a size of 2. With the modification

    // multiply a slice of the matrix with 2....
    // project (m, slice (2, 1, m.size1()-2), slice (1, 0, m.size1()-2)) *=
2;
    project (m, slice (2, 1, m.size1()-2), slice (1, 0, 1)) *= 2;

I get the result

[4,4]((1,1,1,1),(1,1,1,1),(1,1,1,1),(1,1,1,1))
[4,4]((1,1,1,1),(1,1,1,1),(1,2,1,1),(1,2,1,1))

which is what I'd expect.

> Everything works fine if I am using a
> matrix_vector_slice.
>
> My second (stupid?)

Nope ;-)

> question is the following: Is it intentional, that it
> is not possible to compile:
>
> #include <boost/numeric/ublas/matrix.hpp>
> #include <boost/numeric/ublas/io.hpp>
>
> int main () {
> using namespace boost::numeric::ublas;
> matrix<double> m (4, 4);
> for (unsigned int i = 0; i < m.size1 (); ++ i)
> for (unsigned int j = 0; j < m.size2 (); ++ j)
> m(i, j) = 4*i+j;
>
> std::cout << m << std::endl;
>
> swap(row(m,0), row(m,2));
>
> std::cout << m << std::endl;
> }

No. This one compiles with ICC 7.0 and fails with GCC 3.2.1. I'll
investigate that later.

> whereas
>
> matrix_row<matrix<double> > l(m, 0);
> matrix_row<matrix<double> > r(m, 2);
>
> swap(l, r); /* swap the rows */
>
> works fine.

Interesting.

Thanks for your feedback,

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