OCTAVE: Is Array3 available as a 3D array datatype in Octave interperter?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

OCTAVE: Is Array3 available as a 3D array datatype in Octave interperter?

braddock-2
A 3-dimensional array datatype would be infinitely useful to me in Octave.

I'm interested in either knowing how to use one, or implementing one
myself.  I see there is an Array3 class in liboctave/Array3.cc, but there
is no documentation on how to use it in the octave interpreter (if that's
possible...there is only one reference to the class in a
`grep Array3 src/*.cc`).

Is there any way to implement a 3D array in Octave?  The closest I can
figure out using the obvious datatypes would be to make a data structure
of matricies with some nasty eval's to access the elements.

Thanks a googol!

        -Braddock


Reply | Threaded
Open this post in threaded view
|

Re: OCTAVE: Is Array3 available as a 3D array datatype in Octave

Ted.Harding
( Re Message From: Braddock Gaskill )

>
> A 3-dimensional array datatype would be infinitely useful to me in Octave.
>
> I'm interested in either knowing how to use one, or implementing one
> myself.  I see there is an Array3 class in liboctave/Array3.cc, but there
> is no documentation on how to use it in the octave interpreter (if that's
> possible...there is only one reference to the class in a
> `grep Array3 src/*.cc`).
>
> Is there any way to implement a 3D array in Octave?  The closest I can
> figure out using the obvious datatypes would be to make a data structure
> of matricies with some nasty eval's to access the elements.
>
> Thanks a googol!
>
> -Braddock

It ain't quite as bad as that ... You can take a hint from C, where an
array is a linear block accessed by a computed pointer. The following is a
skeleton example to implement a d-dimensional array, exemplified with d=4.
Maybe it could be a touch more elegant, and it needs array-bound checks
and such before it's fit to be let out on its own, but you get the idea.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
A.n_dims = 4;
A.dims = [2;2;3;3];
A.elems = [
  1111; 1112; 1113; 1121; 1122; 1123; 1131; 1132; 1133;
  1211; 1212; 1213; 1221; 1222; 1223; 1231; 1232; 1233;
  2111; 2112; 2113; 2121; 2122; 2123; 2131; 2132; 2133;
  2211; 2212; 2213; 2221; 2222; 2223; 2231; 2232; 2233; ];

function x = elem(X,j) # X a d-dim array, j a d-vector of "coordinates"
  d = X.n_dims; k = X.dims; k = flipud(cumprod(flipud(k)));
  i = j(d); for r=1:d-1, i = i+(j(r)-1)*k(r+1); endfor
  x = X.elems(i);
endfunction
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
octave-2:13> elem(A,[1;1;1;1])
ans = 1111
octave-2:14> elem(A,[1;1;2;1])
ans = 1121
octave-2:15> elem(A,[2;1;3;2])
ans = 2132
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
You could also try further tricks (e.g. using NaN) to access sub-arrays,
e.g.  elem(A,[1,NaN,NaN,NaN]) would return the 2x3x3 array with i1=1,
elem(A,[1,NaN,3,NaN) the 2x3 with i1=1, i3=3
(not forgetting to recompute .n_dims and .dims).

Hope this helps,
Ted.                                    ([hidden email])


Reply | Threaded
Open this post in threaded view
|

Re: OCTAVE: Is Array3 available as a 3D array datatype in Octave interperter?

Thomas Hoffmann-3
In reply to this post by braddock-2
Yesterday I looked into the user contributed files section of
MATLAB. Under lineraalgebra you can find a file named "array". The
header says:

%Abstract
 
%The collection of M-files for matlab make it possibel to work with
%3-dim and higher dimensional arrays and perform for example the FFT in
%arbitrary dimensions.
 
%The idea of writing this files came to me when I discussed with a
%colleague (a solid state physicist) about MATLAB. We came to the
%conclusion, that he can't use it because there are no possibilities
%to work with 3-dimensional arrays and to perform for example the
%3-dimensional Fourier transformation, which he needs a lot. That
%was the reason why I thought about a general concept to work with
%such arrays in MATLAB. The concept is now allready extended to higher
%dimensions, so that one can do the FFT for arbitrary dimensions.
 
Maybe this can be of use for you.

Thomas.


Reply | Threaded
Open this post in threaded view
|

Re: OCTAVE: Is Array3 available as a 3D array datatype in Octave interperter?

John W. Eaton-6
In reply to this post by braddock-2
As others have pointed out, there are several different ways to
simulate N-dimensional arrays in Octave.  None of them are really very
appealing, but they will work in a pinch.

I hope that a future version of Octave will support real N-dimensional
arrays that can at least contain real and complex numbers, but perhaps
even any data type that Octave supports.  There is some work being
done in this direction, but things are not moving very fast.  It does
not seem to be a simple problem.  If anyone is interested in working
on it, please send me mail.

Thanks,

jwe