octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Array API changes


From: David Grundberg
Subject: Re: Array API changes
Date: Tue, 23 Feb 2010 12:44:06 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090812)

Jaroslav Hajek wrote:
hi all,

I made the major changes to Array interfaces previously discussed on this list:
http://old.nabble.com/proposal-for-changing-Array-interface-td27253527.htm

This is another significant step to a stable liboctave API:
http://hg.savannah.gnu.org/hgweb/octave/rev/12884915a8e4

The big picture:
The Array class hierarchy in 3.2.x was unnecessarily complicated, with
some classes of almost duplicate functionality (Array-Array2-ArrayN,
MArray-MArray2-MArrayN).
These are in fact relics, because Array<T> itself can handle both 2D
and ND arrays, and any array can be treated as linear by linear
indexing. There are no genuine 1D arrays in Octave. Using (n) as
dimensions usually meant (n, 1) in liboctave, but sometimes (1, n)
(e.g. resize). OTOH, in Octave it usually means (n, n). (e.g. zeros,
ones, resize).

Summary:
The 1D Array<T> constructors are gone. Array<T> is always at least 2D,
so the 1D constructors were confusing, and against the above stated
politics. Further, the initialized 1D ctor was in conflict with a 2D
ctor signature.
You should no longer write
Array<double> x (n);
there are no 1D arrays, so don't do this. In fact it will still work,
but give a deprecation warning (under GCC). Instead, specify
explicitly either row or column vector:
Array<double> x (1, n);
Array<double> y (n, 1);

Array<T> (octave_idx_type, T) won't work (it conflicts with the 2d ctor).

Ditto for Array<T>::resize, Array<T>::clear. In this way, you can
avoid the pitfalls where column vectors were unexpectedly changed to
row vectors.
Array <double> x(n); // x is column vector now
x.resize (1).resize (n); // x is row vector now!!

resize (n) will still work, but is deprecated. resize (n, T) won't work.

Similarly, dim_vector (n) is deprecated. use (1, n) or (n, 1) explicitly.
In those classes where the vector orientation is implied - RowVector,
ColumnVector, string_vector, or octave_value_list, you can still use
1D constructors, i.e.

ColumnVector c(3);
ColumnVector c(3, 1.0);

are still OK.

The MArrayN and MArray2 classes are gone (ArrayN was removed
previously). classes like Matrix or ColumnVector now derive directly
from MArray.
charMatrix and boolMatrix still derive from Array2, I'll fix that later.

Comments? Suggestions?


Great work!


reply via email to

[Prev in Thread] Current Thread [Next in Thread]