Boost logo

Boost :

From: Doug Gregor (gregod_at_[hidden])
Date: 2001-03-25 15:14:41


On Thursday 22 March 2001 03:56, you wrote:
> On Thu, 22 Mar 2001, Toon Knapen wrote:
> toon> Wow, are'nt we going to drown in requirements/specifications here ?
> toon> The discussion started at a multi-dim array, was extended to LA and
> toon> know we're talking about numerics in general.
> toon> All this stuff is super-interesting but let's take one step at a
> toon> time.
>
> Actually, I think it is really great that people have been posting
> requirements/specs. Please keep them coming!! In the next week or so I
> plan to collect and organize them.
>
> However, I agree that we should get some of the basic components like
> multi-dim arrays and matrix classes done first, since they will be needed
> by most other components.
>
> I've been working with Ron Garcia on the interface for multi-dim arrays
> the last couple days... still have more work to do there. One of the
> trickier parts is deciding on an interface for subarrays and slicing.
> Blitz++ uses the following notation for specifying subarrays and slices:
>
> A(0, Range(1,2), Range(2, 5)) // ranges are specified has closed intervals
>
> However, this interface results in an interface explosion and has a fixed
> limit on the number of dimensions that can be handled.
>
> Blitz++ has an alternate way to specify subarrays using RectDomain, and
> valarray has the gslice interface, however these approaches are not as
> easy to use.
>
> One possibility I'm looking at starts with the std::slice from valarray,
> but allows them to be combined to specify slices for N dimensions.
>
> A[slice(0)(1,2)(2,3)] // slices here are (start,size=1,stride=1)
> // another sensible option would be to
> // specify slices with half-open intervals
> // (start,finish,stride)
>
> If anyone has any good ideas on a nice interface for specifying subarrays,
> feel free to chime in :)

How about:

A[1 <= stride(1) < 2, 2 <= stride(2) <= 8]

Specifying intervals using function notation is unfortunate in C++ because
the use of parentheses or brackets doesn't match the mathematical notation.
The range (a, b) expressed mathematically is unambiguous, but if we have a
C++ functoin call interval(a, b) the user will always be sent back to the
documentation to figure out what happens at the endpoints. Using relational
operators it is unambiguous.

While I'm throwing out random syntax, an interface between the lambda library
and the multidim array/matrix/linear algebra library could allow for some
really nice code:

// A is M x N, B is N x R
indexer<int> i, j, k;
C[i, j] = sum(A[i, k] * B[k, j], for_all(0 <= k < N)),
        for_all(0 <= i < M, 0 <= j < R);

And for a really neat trick, have the library tile this loop nest :)

        Doug


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk