[Oberon] Offer and request, 1d/2d arrays
Alan Freed
AlFreed at ohio.net
Wed Jul 23 21:58:00 CEST 2003
Hi Doug,
> Just a silly comment or two.
> It has always struck me that mathamatics and computer science at the
> notational level are so different although they share deep
> similarities at the theoretical level.
> For example
>
> CS
> Mod.AddAA (x, y, res, offset, len);
> MATH
> res = x + y
Mod.AddAA is a low-level procedure. Overloaded operators are also
defined for all basic
arithmetic operations. There are advantages for both approaches,
depending on the need at
hand, so both are being constructed.
What Felix did not mention is that the Array modules are put into
wrappers in Vector and
Matrix modules, where the latter are OBJECT's, while the former are
POINTER TO ARRAY's.
The intent is that the Array modules will be used for low-level work,
whereas the Vector
and Matrix modules will be used for high-level work.
> The context of the mathematical discussion specifies the type of x, y,
> and res as well as the meaning of '+'.
>
> Operator overloading is used in some languages to achieve the
> notational similarity and yet doing so quickly leads to strange
> missuse and unreadable code. But the mathematical form still remains
> clearer (at least if the mathematician does a fair job). Why?
Care in use and clarity in choice of variable names have a lot to do
with this.
> Also mixed numeric types are easily used in mathematics and yet are
> (purposefully) made difficult in computer science,
> e.g.
> TYPE x, res = ARRAY OF REAL; y = ARRAY OF INTEGER;
> MATH
> res = x + y
> CS
> Mod.AddAA( "can't do it" )
>
> By "can't do it" I mean that a first level attempt fails and one would
> need to create a generic Add routine and then perform some kind of
> type test "IS" on the arguments.
>
> TYPE Numeric = POINTER TO ABSTRACT RECORD END;
> PROCEDURE Add (x, y, res: Numeric; offset, len: LONGINT);
> BEGIN
> IF x IS ...
> ...
> END
> END Add;
>
> where now one can conceive of
> TYPE
> IntArray = POINTER TO RECORD(Numeric) val: ARRAY OF INTEGER END;
> RealArray = POINTER TO RECORD(Numeric) val: ARRAY OF REAL END;
> x, res: RealArray;
> y: IntArray;
>
> Mod.Add(x, y, res, offset, len);
>
> But this is quite inefficient. Any better solutions?
The code that we are putting together (which will go by the name CAPO -
Computation Analysis
Platform in Oberon) can handle integers, fixed-point rationals,
floating-point reals, and complex
numbers. It can also address 1 and 2 dimensional arrays where the
arithmetic operators are all
overloaded such that, e.g., one could write
VAR x: VecRe.Vector; y, z: VecCplx.Vector;
...
z := x + y
and this would be properly handled.
> Personal comment: I probably would wrap your suggestion for the AddAA
> function in one of my own to eliminate the use of offset and len since
> I never do such a thing, i.e.
>
> PROCEDURE MyAddAA (VAR x, y, res: ARRAY OF LONGINT);
> BEGIN
> ASSERT(LEN(x)=LEN(y));
> ASSERT(LEN(y)=LEN(res));
> Mod.AddAA(x, y, res, 0, LEN(x));
> END MyAddAA
That is fine by us.
Our objective is to provide a very robust platform upon which
computational applications
can be rapidily developed in Oberon. This has been a dream of mine for
over a decade,
and I believe we are about to realize it.
Al
>
>
> -Doug
>
> Felix Friedrich wrote:
>
>> Hello everybody,
>>
>> as we are just preparing generic modules for operations on one and
>> two dimensional arrays
>> (of Integer,Rational,Real,Cplx variables), I would like to ask all of
>> you for comments on typically needed features for modules of that kind.
>>
>> As future versions of Oberon/Aos will probably provide the
>> functionalities that are just being collected, announcing desired
>> features will be of use for all of us.
>>
>> We are currently working on
>> - monadic and dyadic Operators (+,-,*,/,MOD,DIV) [Array,
>> Array-Array, Array-Value]
>> - additional features on ARRAY OF / ARRAY OF ARRAY OF including
>> -- Norms, Distances, MinMax, MeanSsq, kSmallest/Median
>> -- Patterned Access (Copy,Add,Div etc. )
>> -- Access on Indexes (Remove,Insert,Shift)
>> -- Extract/Put Row/Col (on 2d only)
>> -- SwapRows/SwapCols/Transpose (on 2d only)
>>
>> A short version of the current interface of (the Integer) modules is
>> appended below [the operators as +,-,*etc. are omited].
>>
>> Comments/Requests/Questions/Concerns welcome !
>>
>> Felix.
>>
>>
>> Array1d
>>
>> Array = POINTER TO ARRAY OF LONGINT;
>>
>> PROCEDURE Abs (VAR x: ARRAY OF LONGINT; VAR res: ARRAY OF
>> LONGINT; offset, len: LONGINT);
>> PROCEDURE AddAA (VAR x, y: ARRAY OF LONGINT; VAR res: ARRAY OF
>> LONGINT; offset, len: LONGINT);
>> PROCEDURE AddAV (VAR x: ARRAY OF LONGINT; y: LONGINT; VAR res:
>> ARRAY OF LONGINT; offset, len: LONGINT);
>> PROCEDURE AddAVPat (VAR x: ARRAY OF LONGINT; y: LONGINT; VAR res:
>> ARRAY OF LONGINT; srcoffset, srcstep, destoffset, deststep, piecelen,
>> pieces: LONGINT);
>> PROCEDURE ApplyMap (map: Map; VAR res: ARRAY OF LONGINT; offset,
>> len: LONGINT);
>> PROCEDURE ApplyMapPat (map: Map; VAR res: ARRAY OF LONGINT;
>> offset, step, piecelen, pieces: LONGINT);
>> PROCEDURE Copy (VAR x: ARRAY OF LONGINT; VAR res: ARRAY OF
>> LONGINT; srcoffset, destoffset, len: LONGINT);
>> PROCEDURE CopyPat (VAR x: ARRAY OF LONGINT; VAR res: ARRAY OF
>> LONGINT; srcoffset, srcstep, destoffset, deststep, piecelen, pieces:
>> LONGINT);
>> PROCEDURE DIV (): Array;
>> PROCEDURE DivAA (VAR x, y: ARRAY OF LONGINT; VAR res: ARRAY OF
>> LONGINT; offset, len: LONGINT);
>> PROCEDURE DivAV (VAR x: ARRAY OF LONGINT; y: LONGINT; VAR res:
>> ARRAY OF LONGINT; offset, len: LONGINT);
>> PROCEDURE DivAVPat (VAR x: ARRAY OF LONGINT; y: LONGINT; VAR res:
>> ARRAY OF LONGINT; srcoffset, srcstep, destoffset, deststep, piecelen,
>> pieces: LONGINT);
>> PROCEDURE DivVA (x: LONGINT; VAR y: ARRAY OF LONGINT; VAR res:
>> ARRAY OF LONGINT; offset, len: LONGINT);
>> PROCEDURE DivVAPat (x: LONGINT; VAR y: ARRAY OF LONGINT; VAR res:
>> ARRAY OF LONGINT; srcoffset, srcstep, destoffset, deststep, piecelen,
>> pieces: LONGINT);
>> PROCEDURE EqualsAA (VAR x, y: ARRAY OF LONGINT; offset, len:
>> LONGINT): BOOLEAN;
>> PROCEDURE Fill (x: LONGINT; VAR res: ARRAY OF LONGINT; offset,
>> len: LONGINT);
>> PROCEDURE FillPat (x: LONGINT; VAR res: ARRAY OF LONGINT; offset,
>> step, piecelen, pieces: LONGINT);
>> PROCEDURE HammingDist (VAR x, y: ARRAY OF LONGINT; xoffset,
>> yoffset, len: LONGINT): LONGINT;
>> PROCEDURE HammingWeight (VAR x: ARRAY OF LONGINT; offset, len:
>> LONGINT): LONGINT;
>> PROCEDURE HammingWeightPat (map: Map; VAR x: ARRAY OF LONGINT;
>> offset, step, piecelen, pieces: LONGINT): LONGINT;
>> PROCEDURE InsertBlock (VAR x: ARRAY OF LONGINT; offset, len:
>> LONGINT);
>> PROCEDURE L1Dist (VAR x, y: ARRAY OF LONGINT; xoffset, yoffset,
>> len: LONGINT): LONGINT;
>> PROCEDURE L1Norm (VAR x: ARRAY OF LONGINT; offset, len: LONGINT):
>> LONGINT;
>> PROCEDURE L1NormPat (map: Map; VAR x: ARRAY OF LONGINT; offset,
>> step, piecelen, pieces: LONGINT): LONGINT;
>> PROCEDURE L2Dist (VAR x, y: ARRAY OF LONGINT; xoffset, yoffset,
>> len: LONGINT): LONGINT;
>> PROCEDURE L2Norm (VAR x: ARRAY OF LONGINT; offset, len: LONGINT):
>> LONGINT;
>> PROCEDURE L2NormPat (map: Map; VAR x: ARRAY OF LONGINT; offset,
>> step, piecelen, pieces: LONGINT): LONGINT;
>> PROCEDURE LInftyDist (VAR x, y: ARRAY OF LONGINT; xoffset,
>> yoffset, len: LONGINT): LONGINT;
>> PROCEDURE LInftyNorm (VAR x: ARRAY OF LONGINT; offset, len:
>> LONGINT): LONGINT;
>> PROCEDURE LInftyNormPat (map: Map; VAR x: ARRAY OF LONGINT;
>> offset, step, piecelen, pieces: LONGINT): LONGINT;
>> PROCEDURE Long (VAR x: ARRAY OF LONGINT; res: ARRAY OF
>> MathH.HUGEINT; len: LONGINT);
>> PROCEDURE Max (VAR x: ARRAY OF LONGINT; offset, len: LONGINT; VAR
>> maxpos: LONGINT): LONGINT;
>> PROCEDURE MeanSsq (VAR x: ARRAY OF LONGINT; offset, len: LONGINT;
>> VAR mean, ssq: REAL);
>> PROCEDURE Median (VAR a: ARRAY OF LONGINT; len: LONGINT): LONGINT;
>> PROCEDURE Min (VAR x: ARRAY OF LONGINT; offset, len: LONGINT; VAR
>> minpos: LONGINT): LONGINT;
>> PROCEDURE MinMax (VAR x: ARRAY OF LONGINT; offset, len: LONGINT;
>> VAR min, max: LONGINT; minpos, maxpos: LONGINT);
>> PROCEDURE MinMaxPat (map: Map; VAR x: ARRAY OF LONGINT; offset,
>> step, piecelen, pieces: LONGINT; VAR min, max: LONGINT; minpos,
>> maxpos: LONGINT);
>> PROCEDURE ModAA (VAR x, y: ARRAY OF LONGINT; VAR res: ARRAY OF
>> LONGINT; offset, len: LONGINT);
>> PROCEDURE ModAV (VAR x: ARRAY OF LONGINT; y: LONGINT; VAR res:
>> ARRAY OF LONGINT; offset, len: LONGINT);
>> PROCEDURE ModAVPat (VAR x: ARRAY OF LONGINT; y: LONGINT; VAR res:
>> ARRAY OF LONGINT; srcoffset, srcstep, destoffset, deststep, piecelen,
>> pieces: LONGINT);
>> PROCEDURE ModVA (x: LONGINT; VAR y: ARRAY OF LONGINT; VAR res:
>> ARRAY OF LONGINT; offset, len: LONGINT);
>> PROCEDURE ModVAPat (x: LONGINT; VAR y: ARRAY OF LONGINT; VAR res:
>> ARRAY OF LONGINT; srcoffset, srcstep, destoffset, deststep, piecelen,
>> pieces: LONGINT);
>> PROCEDURE MultAA (VAR x, y: ARRAY OF LONGINT; VAR res: ARRAY OF
>> LONGINT; offset, len: LONGINT);
>> PROCEDURE MultAV (VAR x: ARRAY OF LONGINT; y: LONGINT; VAR res:
>> ARRAY OF LONGINT; offset, len: LONGINT);
>> PROCEDURE MultAVPat (VAR x: ARRAY OF LONGINT; y: LONGINT; VAR
>> res: ARRAY OF LONGINT; srcoffset, srcstep, destoffset, deststep,
>> piecelen, pieces: LONGINT);
>> PROCEDURE Negate (VAR x: ARRAY OF LONGINT; VAR res: ARRAY OF
>> LONGINT; offset, len: LONGINT);
>> PROCEDURE RemoveBlock (VAR x: ARRAY OF LONGINT; offset, len:
>> LONGINT);
>> PROCEDURE ScalarProduct (VAR x, y: ARRAY OF LONGINT; VAR res:
>> LONGINT; offset, len: LONGINT);
>> PROCEDURE SetLen (VAR a: Array; len: LONGINT);
>> PROCEDURE ShiftBlock (VAR x: ARRAY OF LONGINT; from, to, len:
>> LONGINT);
>> PROCEDURE Short (VAR x: ARRAY OF LONGINT; res: ARRAY OF INTEGER;
>> len: LONGINT);
>> PROCEDURE Sort (VAR x: ARRAY OF LONGINT; offset, len: LONGINT);
>> PROCEDURE SortByIndex (VAR x: ARRAY OF LONGINT; VAR index: ARRAY
>> OF LONGINT; offset, len: LONGINT);
>> PROCEDURE SortWithIndex (VAR x: ARRAY OF LONGINT; VAR index:
>> ARRAY OF LONGINT; offset, len: LONGINT);
>> PROCEDURE SubtractAA (VAR x, y: ARRAY OF LONGINT; VAR res: ARRAY
>> OF LONGINT; offset, len: LONGINT);
>> PROCEDURE SubtractAV (VAR x: ARRAY OF LONGINT; y: LONGINT; VAR
>> res: ARRAY OF LONGINT; offset, len: LONGINT);
>> PROCEDURE SubtractAVPat (VAR x: ARRAY OF LONGINT; y: LONGINT; VAR
>> res: ARRAY OF LONGINT; srcoffset, srcstep, destoffset, deststep,
>> piecelen, pieces: LONGINT);
>> PROCEDURE SubtractVA (VAR x: LONGINT; VAR y: ARRAY OF LONGINT;
>> VAR res: ARRAY OF LONGINT; offset, len: LONGINT);
>> PROCEDURE SubtractVAPat (x: LONGINT; VAR y: ARRAY OF LONGINT; VAR
>> res: ARRAY OF LONGINT; srcoffset, srcstep, destoffset, deststep,
>> piecelen, pieces: LONGINT);
>> PROCEDURE kSmallest (k: LONGINT; VAR a: ARRAY OF LONGINT; len:
>> LONGINT): LONGINT;
>> PROCEDURE kSmallestModify (k: LONGINT; VAR a: ARRAY OF LONGINT;
>> len: LONGINT): LONGINT;
>>
>>
>> Array2d:
>>
>> Array = POINTER TO ARRAY OF ARRAY OF LONGINT;
>>
>> PROCEDURE Col (x: LONGINT; VAR s: ARRAY OF ARRAY OF LONGINT):
>> Array1dInt.Array;
>> PROCEDURE Copy (VAR src: ARRAY OF ARRAY OF LONGINT; VAR dest:
>> ARRAY OF ARRAY OF LONGINT; srcx, srcy, destx, desty, w, h: LONGINT);
>> PROCEDURE CopyCol (x: LONGINT; VAR s: ARRAY OF ARRAY OF LONGINT;
>> VAR res: ARRAY OF LONGINT; srcoffset, destoffset, len: LONGINT);
>> PROCEDURE CopyRow (y: LONGINT; VAR s: ARRAY OF ARRAY OF LONGINT;
>> VAR res: ARRAY OF LONGINT; srcoffset, destoffset, len: LONGINT);
>> PROCEDURE CopyToCol (VAR s: ARRAY OF LONGINT; x: LONGINT; VAR
>> res: ARRAY OF ARRAY OF LONGINT; srcoffset, destoffset, len: LONGINT);
>> PROCEDURE CopyToRow (VAR s: ARRAY OF LONGINT; y: LONGINT; VAR
>> res: ARRAY OF ARRAY OF LONGINT; srcoffset, destoffset, len: LONGINT);
>> PROCEDURE Fill (val: LONGINT; VAR res: ARRAY OF ARRAY OF LONGINT;
>> x, y, w, h: LONGINT);
>> PROCEDURE MeanSsq (VAR s: ARRAY OF ARRAY OF LONGINT; x, y, w, h:
>> LONGINT; VAR mean, ssq: REAL);
>> PROCEDURE Median (VAR s: ARRAY OF ARRAY OF LONGINT; x, y, w, h:
>> LONGINT): LONGINT;
>> PROCEDURE MinMax (VAR s: ARRAY OF ARRAY OF LONGINT; x, y, w, h:
>> LONGINT; VAR min, max, minx, miny, maxx, maxy: LONGINT);
>> PROCEDURE Row (y: LONGINT; VAR s: ARRAY OF ARRAY OF LONGINT):
>> Array1dInt.Array;
>> PROCEDURE SwapCols (VAR s: ARRAY OF ARRAY OF LONGINT; x1, x2:
>> LONGINT);
>> PROCEDURE SwapRows (VAR s: ARRAY OF ARRAY OF LONGINT; y1, y2:
>> LONGINT);
>> PROCEDURE Transposed (VAR s: ARRAY OF ARRAY OF LONGINT): Array;
>> PROCEDURE kSmallest (k: LONGINT; VAR s: ARRAY OF ARRAY OF
>> LONGINT; x, y, w, h: LONGINT): LONGINT;
>>
>>
>> --
>>
>> Felix Friedrich
>>
>> Institut für Biomathematik und Biometrie
>> GSF - Forschungszentrum für Umwelt und Gesundheit, GmbH
>> Ingolstädter Landstraße 1, D-85764 Neuherberg
>>
>> Tel: ++49 89 3187 2436
>> email: friedrich at gsf.de
>>
>> --
>>
>> --
>> Oberon at inf.ethz.ch mailing list for ETH Oberon and related systems
>> http://www.lists.inf.ethz.ch/mailman/listinfo/oberon
>>
>>
>
>
> --
> Oberon at inf.ethz.ch mailing list for ETH Oberon and related systems
> http://www.lists.inf.ethz.ch/mailman/listinfo/oberon
>
>
--
Alan D. Freed, Ph.D. E-mail: Alan.D.Freed at nasa.gov (Tuesdays & Thursdays)
Polymers Branch FreedA at bme.ri.ccf.org (Mondays)
NASA's Glenn Research Center AlFreed at ohio.net (Wednesdays & Fridays)
More information about the Oberon
mailing list