Hello, I just wanted to clarify if the following behavior is correct. As far as I understood, in matrix and vector range function, the 1st argument defines the starting point and the second defines the length of the range. The following code I ran on gcc 2.96 shows that the behavior is different when starting at 0 and starting somewhere else. Is this a bug, or am I misunderstanding something? Thank you, Julian // define some vector r(3) std::cout << r << "\n\n"; boost::numeric::ublas::vector<double> rr = r(range(0, 0)); std::cout << rr << "\n\n"; rr = r(range(0, 1)); std::cout << rr << "\n\n"; rr = r(range(0, 2)); std::cout << rr << "\n\n"; rr = r(range(0, 3)); std::cout << rr << "\n\n"; //rr = r(range(1, 0)); // THIS RESULTS IN ASSERTION ERROR //std::cout << rr << "\n\n"; rr = r(range(1, 1)); std::cout << rr << "\n\n"; rr = r(range(1, 2)); std::cout << rr << "\n\n"; rr = r(range(1, 3)); std::cout << rr << "\n\n"; OUTPUT: [3](0,1,2) [0]() [1](0) [2](0,1) [3](0,1,2) [0]() [1](1) [2](1,2)
Hi Julian, you wrote:
I just wanted to clarify if the following behavior is correct. As far as I understood, in matrix and vector range function, the 1st argument defines the starting point and the second defines the length of the range.
It looks like the documentation is imperfect here (I'll try to improve): a range is specified like the usual STL iterator range from the [ first to the last ) element.
The following code I ran on gcc 2.96 shows that the behavior is different when starting at 0 and starting somewhere else. Is this a bug, or am I misunderstanding something?
Best, Joerg
cerenoc wrote:
I just wanted to clarify if the following behavior is correct. As far as I understood, in matrix and vector range function, the 1st argument defines the starting point and the second defines the length of the range.
No. First argument defines the starting point, but the second defines `one past the end', similar to iterator ranges: [begin, end). For example: range (0, 1) => 0 range (0, 3) => 0 1 2 range (1, 3) => 1 2 range (2, 3) => 2 range (3, 3) => empty range (4, 3) => assertation error [On the other hand, when defining a slice, length is given by the third argument (first is starting point, second is step (or stride)); e.g.: slice (0, 1, 3) => 0 1 2 slice (1, 1, 3) => 1 2 3 slice (1, 2, 3) => 1 3 5 ] Regards, fres
participants (3)
-
cerenoc
-
jhr.walter@t-online.de
-
Kresimir Fresl