Boost logo

Glas :

Re: [glas] multi-dimensional arrays?

From: Edwards, Harold C (hcedwar_at_[hidden])
Date: 2007-11-29 10:03:33


Some of our applications make complex use of multidimensional arrays,
for example the derivatives of a collection of tensors associated with
the Cartesian product of basis functions and quadrature points in a
hexahedral cell. One of the big software problems has been keeping up
with the array layout, i.e. the meaning of each dimension. The problem
of permuting indices periodically pops up due to poor documentation, and
the use of raw pointers.

A solution we came up with to address the multidimensional array
notation in C++ as well as using C++ typing to encourage documentation
of the arrays was the following array class.

template< typename Scalar,
          class TagDim1, class TagDim2, ... , class TagDim8 = TagIgnore>
class Array ;

Where the 'dimension tags' are things like:

class CartesianVectorTag {};
class BasisFunctionTag {};
class QuadraturePointTag {};

Leading to "modestly typed" multidimensional arrays:

typedef
Array<double,CartesianVectorTag,BasisFunctionTag,QuadraturePointTag>
ElementGradients ;

The Array template class provided dimensions and the expected indexing
operators.

Carter Edwards

 

-----Original Message-----
From: glas-bounces_at_[hidden] [mailto:glas-bounces_at_[hidden]]
On Behalf Of Karl Meerbergen
Sent: Thursday, November 29, 2007 1:20 AM
To: Generic Linear Algorithm Software
Subject: Re: [glas] multi-dimensional arrays?

Dear Neal,

I think we could add multi-dimensional arrays to glas. Could you make a
list of desired functionaties?

As a coincidence I attended a seminar yesterday on higher order tensors.

The notation and concepts from this community could help.

Best,

Karl

Neal Becker wrote:

>On Wednesday 28 November 2007, Evgenii Rudnyi wrote:
>
>
>> >I'm enthusiastically following mtl4 and glas developments.
>> >One thing that
>> >neither seems to address is arrays of dimension >2. Is this true?
>>
>>NumPy supports multidimensional arrays:
>>
>>http://www.scipy.org/NumPy
>>
>>
>>
>
>Yes it does. Unfortunately, it doesn't have a nice c++ interface,
AFAIK.
>
>What I'd like is to be able to write generic algorithms in c++ that can

>use various multi-dimensional containers, and then expose them to
python.
>
>So far, what I've done is expose various container types to python
>(ublas,
>blitz++) using boost::python. Then, instantiate algorithms using these
>containers to expose to python.
>
>Each lib has it's own issues. ublas, for example, doesn't conform to
>all of container concept (lacks constructor taking a pair of
>iterators), but that's pretty easy to work around.
>
>blitz takes a little work, because it lacks proper iterators. I have
>built boost::iterator adapters that handle that (perhaps not
efficiently, though).
>
>I don't know how to use numpy to get a nice generic interface on the
c++ side.
>_______________________________________________
>glas mailing list
>glas_at_[hidden]
>http://lists.boost.org/mailman/listinfo.cgi/glas
>
>