In response to the recent inquiries about multidimensional arrays in
Octave, I am posting a beta version of small toolbox which I put together
last year. I had been waiting to write up better documentation before
releasing it, but now I don't see having much time for the forseeable
future. Hopefully, the scripts will still be of use, as I tried to
document the files internally.
The approach is a bit clunky in that the multidimensional arrays are
implemented as structures, but it is functional for simple tasks. I also
went for generality over efficiency, so there isn't an inherent limit to
the number of dimensions possible, but I'm fairly sure that the routines
aren't that fast.
See the attached README file for details. In the attached archive, there
are also some examples regarding the use of such arrays for some simple
calculations in elasticity theory.
Thanks to Ted Harding and others who had posted some comments to this list
in 1997 regarding how such arrays could be implemented. Thanks also to
the U.S. National Research Council for a research associateship during
which I wrote these scripts. Of course, the responsibility for any errors
is mine alone. Unfortunately, I don't really have time to provide any
support.
If people find this toolbox useful, it would probably make sense to put
these files into octave-forge. How would I go about doing that?
--Ron
------------------------------------------------------------------------
Multidimensional Array Toolbox for Octave
(Beta version 0.5, 19 Aug 2003)
by Ronald Kumon
*************************************************************
WARNING: These scripts are in beta form. I believe that
they work properly, but you use them at your own risk.
The author takes no responsibility for the results of these
scripts. No support is available.
*************************************************************
Description:
The scripts in this directory provide some basic tools for
creating and manipulating the equivalent of multidimensional
arrays in Octave (at the time of this writing such arrays
are not natively implemented). With these scripts the
multidimensional arrays are implemented internally in Octave
as structures. The arrays (even two-dimensional arrays)
cannot be used with Octave's native matrices. There are,
however, scripts in the toolbox to convert between matrices
and arrays. The dimension of the arrays is not inherently
limited, although performance will likely be very slow for
many dimensions.
Array structures:
Each array structure consists of a scalar with the number of
dimensions (ndim), a vector with the number of elements in
each dimension (dims), and then a vector containing all the
elements (elems). The various scripts which manipulate the
arrays figure out how to access and display the elements in
a somewhat intuitive way.
Octave version:
These scripts have been tested on Octave 2.0.*.
I do not know about their behavior on other versions.
Licensing:
GNU Public License (GPL)
Installation:
The files in the compressed archive "array.tar.gz" should
be unpacked to a directory which is somewhere on your Octave
path.
Documentation:
Please see the files themselves for documentation. If properly
installed, a basic description of each file is available by
using Octave's "help" function along with the name of the script.
Basic Testing:
There are a couple of test scripts which give some idea about
how some of the scripts work.
testdefmat.m: Defines some arrays
testcontr.m : Tests some array contractions
More Examples:
The subdirectory "elasticity" has some scripts which show how
the arrays could be used to implement some basic calculations
in the theory of linear elasticity.
Needed improvements:
1. Better documentation.
2. More error-checking.
3. More efficient implementation, perhaps with special
functions for three-dimensional arrays.
4. Ability to interact more easily with Octave's matrices.
5. More testing for correctness and robustness.
MATLAB compatibility:
None, really, because MATLAB has multidimensional arrays
built in. However, I tried to make the behavior of these
scripts similar to MATLAB where I thought it was sensible
to do so.
Summary of scripts:
arr2mat.m : Convert array (2D or less) to matrix
arradd.m : Add two arrays
arrassg.m : Assigns elements to an array
arrcompare.m : Compare arrays
arrcontr.m : Contract arrays over specified index ranges
arrcoord2index.m : Converts matrix coordinates to array indices
arrdef.m : Defines array structure
arrdim.m : Gives array dimension
arrdirprod.m : Computes array direct product
arrdisplay.m : Displays array
arrelemassg.m : Assigns individual element to array location
arrelemval.m : Provides individual value of array location
arrforloops.m : Generates nested for loops
arrindex2coord.m : Converts array indices to matrix coordinates
arrindexorderdec.m: Generates matrix with decimal elements
corresponding to index values (for testing)
arrindexorder.m : Generates matrix with array coordinates (for testing)
arrindexperm.m : Permutes array elements in specified manner
arrkronecker.m : Generates 2D array for Kronecker delta
arrlevicivita3.m : Generates 3D array for Levi-Civita symbol
arrscalmult.m : Multiplies array by scalar multiple
arrsize.m : Provides array size
arrsubarr.m : Extracts subarray from specified locations
arrsubarrmatrix.m : An alternative way to extract subarrays
arrsubarrranges.m : An alternative way to extract subarrays
arrsubassg.m : Assigns subarray to larger array
arrtrace.m : Computes trace of tensor
arrtranspose.m : Generates transpose of 2D array
arrval.m : Converts array structure to column vector
is_tensor.m : Tests array to see if it is a tensor (or at
least that all dimensions have same number of indices)
mat2arr.m : Convert matrix to 2D array