yorick banner

Home

Manual

Packages

Global Index

Keywords

Quick Reference

Back: Indexing Forward: Index Range   FastBack: Interpolating Up: Indexing FastForward: Sorting         Top: Yorick Contents: Table of Contents Index: Concept Index About: About this document

2.3.1 Scalar indices and array order

An array of objects is stored in consecutive locations in memory (where each location is big enough to hold one of the objects). An array x of three numbers is stored in the order [x(1), x(2), x(3)] in three consecutive slots in memory. A three-by-two array y means nothing more than an array of two arrays of three numbers each. Thus, the six numbers are stored in two contiguous blocks of three numbers each: [[x(1,1), x(2,1), x(3,1)], [x(1,2), x(2,2), x(3,2)]].

A multi-dimensional array may be referenced using fewer indices than its number of dimensions. Hence, in the previous example, x(5) is the same as x(2,2), since the latter element is stored fifth.

Although most of Yorick's syntax follows the C language, array indexing is designed to resemble FORTRAN array indexing. In Yorick, as in FORTRAN, the first (leftmost) dimension of an array is always the index which varies fastest in memory. Furthermore, the first element along any dimension is at index 1, so that a dimension of length three can be referenced by index 1 (the first element), index 2 (the second element), or index 3 (the third element).

If this inconsistency bothers you, here is why Yorick indexing is like FORTRAN indexing: In C, an array of three numbers, for example, is a data type on the same footing as the data type of each of its three members; by this trick C sidesteps the issue of multi-dimensional arrays --- they are singly arrays of objects of an array data type. While this picture accurately reflects the way the multi-dimensional array is stored in memory, it does not reflect the way a multi-dimensional array is used in a scientific computer program.

In such a program, the fact that the array is stored with one or the other index varying fastest is irrelevent -- you are equally likely to want to consider as a "data type" a slice at a constant value of the first dimension as of the second. Furthermore, the length of every dimension varies as you vary the resolution of the calculation in the corresponding physical direction.


Back: Indexing Forward: Index Range   FastBack: Interpolating Up: Indexing FastForward: Sorting         Top: Yorick Contents: Table of Contents Index: Concept Index About: About this document