Hi Stephan, you wrote:
(I am using boost 1.30 & gcc 3.2)
the following program:
#include
#include 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
#include 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
l(m, 0); matrix_row r(m, 2); swap(l, r); /* swap the rows */
works fine.
Interesting. Thanks for your feedback, Joerg