Menu

Home Log in to Edit

Nasos Iliopoulos

x_array template class - THIS SITE IS UNDER CONSTRUCTION.

The x_array template class provides a common container interface for both fixed and dynamic data storage. The interface is trying to stay as close to the STL containers interface as possible, while extending some concepts as they naturally scale to higher dimensions.

Introduction

There have been various implementations of multi dimensional arrays for C++ with probably the most popular one the one found in boost libraries. Although this implementation fits well in programs that require dynamic data storage, it suffers when small fixed storage is desired. Examples of those arrays are small vectors in 3d or 2d space, small matrices (i.e. a projection matrix) etc.

On the other hand there are situations when an implementation can be benefited by requiring that some of the dimensions are fixed and others are not. Examples include the representation of color images and the representation of vectors as matrices with a single row (or column).

Because of the differences between fixed and dynamic arrays, a lot of libraries have been developed to deal with each of the two cases. A class that provides a common interface for multi-dimensional fixed, dynamic, and even "mixed" storage can provide the basis of generic functions and algorithms that can operate on any type of orthogonal containers.

Such thoughts intrigued us to design a multi-dimensional array class that adopts and interface like:

array <double, dyn, dyn, 3> rgbimage1;
rgbimage1( 5,5,0) = ...;
...

and

array <double, dyn, dyn> matrix;
array <double, dyn, 1> vec1, vec2;
array <double, 1, dyn > row_vec;
// Fill matrix and vec1;
....
/ Assuming you have a product implementation for matrices
vec2 = matrix*vec1; 
double inner_product = row_vec*vec1;

x_array features

  • Common interface for all array types.
  • Reduces to a c-style array when all the dimensions are chosen to be fixed.
  • Provides custom iterators for the traversal of the array over all dimensions.
  • Is generic and can also be used with STL algorithms.

Wiki sandbox

To experiment with the features of the wiki the following page was created:
[Wiki Sandbox]


Related

Wiki: Wiki Sandbox

Discussion

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.