BZDEV: Support for multicomponent arrays

From: Todd Veldhuizen (tveldhui@oonumerics.org)
Date: Thu Jun 18 1998 - 18:21:35 EST


I've implemented some support for multicomponent arrays in Blitz++.
If you have an array like:

Array<TinyVector<float,3>,2> A(32,32); // A 32x32 array of 3-tuples

You can now get a view of a single component by using chopComponent:

Array<float,2> B = A.chopComponent(float(), 0, 3); // Get 1st component of 3

This syntax is a bit messy and unsafe, though, so I've also made
operator[] on arrays do the same thing:

A[2] = 5; // Set the 3rd element of every 3-tuple to 5
A[0](Range(10,20),Range(10,20)) = 1; // Set the 1st element of some 3-tuples

This requires a traits class to tell Array<T,N> how many components
there are in T and what type they are.

More interesting example:

class RGB24 {
   unsigned char r, g, b;

public:
   enum { red = 0, green = 1, blue = 2 };
};

// This macro tells Blitz++ that RGB24 has 3 elements of type "unsigned char"
BZ_DECLARE_MULTICOMPONENT_TYPE(RGB24, unsigned char, 3);

  .
  .

Array<RGB24,2> A(128,128); // A 128x128 colour image
A[RGB24::red] = 0; // Zero the red component

This might cause problems with structure padding on some architectures;
I'll probably have to implement it more carefully.

I've also implemented real() and imag() functions for complex arrays:

Array<complex<float>,2> C(30,30);
real(C) = 1.0;
imag(C) = 0.0;

This uses the same multicomponent stuff described above.

Still to do: a "zip" function which will package several scalar expressions
into a multicomponent expression, for example:

Array<float,1> theta(16);
Array<complex<float>,1> trig(16);

C = zip<complex<float> >(cos(theta), sin(theta));

// Equivalent to:
// for (i=0; i < N; ++i)
// C[i] = complex<float>(cos(theta),sin(theta));

This can be pictured as a "zipper" which takes two expressions of
type float and zips them into an expression of type complex<float>.

--------------------- blitz-dev list --------------------------------
* To subscribe/unsubscribe: mail to majordomo@oonumerics.org, with
"subscribe blitz-dev" or "unsubscribe blitz-dev" in the body of the message
* Blitz++ web page: http://oonumerics.org/blitz/



This archive was generated by hypermail 2b29 : Wed Feb 20 2002 - 04:30:05 EST