
On 4/13/07, Marco <mrcekets@gmail.com> wrote:
On Fri, 13 Apr 2007 20:26:17 +0200, Daniel Walker <daniel.j.walker@gmail.com> wrote:
On 4/13/07, Neal Becker <ndbecker2@gmail.com> wrote:
I just posted something on ublas, but I think it may be of more general interest.
I have been using boost::range heavily, and find it useful for generic interfaces. I think it is also useful to have a multi-dimensional extension to range. In particular, a 2-d extension would help in creating algorithms that can accept a variety of 2-d structures.
For example, range has size, begin, end.
range2d would have size1, size2, begin1, begin2.
I think this is an interesting idea, and I've been looking into a little while. You could make this multi-dimensional not just 2d. How about something like ..
// get the number of lines in the plane at index 0 of a 3d space plane_type& space_2d = span(space_3d, 0); range_size< plane_type >::type n_2d = size(space_2d);
I'm not sure if span is the right name for it, and this has got to be encroaching on UBLAS' domain. But it's doable for ranges. I just tried the following, which I believe will work for arbitrary dimensions.
Mathematically speaking, the term "span" is inappropriate: span is usually used in linear algebra to denote the space generated by all linear combinations of a set of vectors; so if you have two indipendent vectors belonging to the plane they generate the whole plane (they are a system of generators for the plane). On the contrary you do not want to expand space_3d. The right term, IMHO, could be "slice" because you want to slice space_3d in order to get one of its affine subspace.
Thanks. I thought "span" might not be right. I wasn't sure if slice only referred to 1d vectors or if it could be a subspace of any dimension. std::slice produces a sequence of indices, but I guess those could be all the points in any n-dimensional space. The function I gave doesn't exactly give you points, at least not points you can immediately/directly loop over, so I'm not sure if it's quite the same as std::slice. Actually, I'm not sure that this is what Neal originally wanted since the size of the 2d "slice" is the number of lines and not the number of points. Maybe a good name for the function would be "subspace"... or better yet it could be called "slice" if it were extended to return a range of iterator adaptors (along the lines of John Femiani's earlier comments) that enumerate all the points. But this may be reinventing the wheel since there are already libraries for stuff like this. Daniel