All Topics  
Array programming

 

   Email Print
   Bookmark   Link






 

Array programming



 
 
In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, array programming languages (also known as vector or multidimensional languages) generalize operations on scalar
Scalar (computing)

In computing, a scalar is a variable or field that can hold only one value at a time; as opposed to composite variables like array, List , object composition, etc....
s to apply transparently to vectors, matrices
Matrix (mathematics)

In mathematics, a matrix is a rectangular array of numbers, as shown at the right. In addition to a number of elementary, entrywise operations such as matrix addition a key notion is matrix multiplication....
, and higher dimensional array
Array

In computer science, an array is a data structure consisting of a group of element s that are accessed by index . In most programming languages each element has the same data type and the array occupies a contiguous area of computer memory....
s.

Array programming primitives concisely express broad ideas about data manipulation. The level of conciseness can be dramatic in certain cases: it is not uncommon to find array programming language one-liners
One-liner program

A one-liner is textual input to the command-line of an operating system Shell that performs some function in just one line of input.The one liner can be...
 that require more than a couple of pages of Java code.






Discussion
Ask a question about 'Array programming'
Start a new discussion about 'Array programming'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
, array programming languages (also known as vector or multidimensional languages) generalize operations on scalar
Scalar (computing)

In computing, a scalar is a variable or field that can hold only one value at a time; as opposed to composite variables like array, List , object composition, etc....
s to apply transparently to vectors, matrices
Matrix (mathematics)

In mathematics, a matrix is a rectangular array of numbers, as shown at the right. In addition to a number of elementary, entrywise operations such as matrix addition a key notion is matrix multiplication....
, and higher dimensional array
Array

In computer science, an array is a data structure consisting of a group of element s that are accessed by index . In most programming languages each element has the same data type and the array occupies a contiguous area of computer memory....
s.

Array programming primitives concisely express broad ideas about data manipulation. The level of conciseness can be dramatic in certain cases: it is not uncommon to find array programming language one-liners
One-liner program

A one-liner is textual input to the command-line of an operating system Shell that performs some function in just one line of input.The one liner can be...
 that require more than a couple of pages of Java code.

APL
APL programming language

APL is an array programming language based on a notation invented in 1957 by Kenneth E. Iverson while at Harvard University. It originated as an attempt to provide consistent notation for the teaching and analysis of topics related to the application of computers....
, designed by Ken Iverson
Kenneth E. Iverson

Kenneth Eugene Iverson was a Canadian computer scientist noted for the development of the APL programming language in 1962. He was honored with the Turing Award in 1979 for his contributions to mathematical notation and programming language theory....
, was the first programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 to provide array programming capabilities. The mnemonic APL refers to the title of his seminal book "A Programming Language" and not to arrays per se. Iverson's contribution to rigor and clarity was probably more important than the simple extension of dimensions to functions.

Concepts

The fundamental idea behind array programming is that operations apply at once to an entire set of values. This makes it a high-level programming
High-level programming language

In computing, a high-level programming language is a programming language with strong Abstraction from the details of the computer. In comparison to low-level programming languages, it may use natural language elements, be easier to use, or more Porting across platforms....
 model as it allows the programmer to think and operate on whole aggregates of data, without having to resort to explicit loops of individual scalar operations.

The basis behind array programming and thinking is to find and exploit the properties of data where individual elements are similar and/or adjacent. Unlike object orientation which implicitly breaks down data to its constituent parts (or scalar
Scalar

A scalar is a variable that only has magnitude , e.g. a speed of 40 km/h. Compare it with vector, a quantity comprising both magnitude and Direction , e.g....
 quantities), array orientation looks to group data and apply a uniform handling.

Function rank is an important concept to array programming languages in general, by analogy to tensor
Tensor

A tensor is an object which extends the notion of Scalar , Vector , and Matrix . The term has slightly different meanings in mathematics and physics....
 rank in mathematics: functions that operate on data may be classified by the number of dimensions they act on. Ordinary multiplication, for example, is a scalar ranked function because it operates on zero-dimensional data (individual numbers). The cross product
Cross product

In mathematics, the cross product is a binary operation on two vector s in a three-dimensional Euclidean space that results in another vector which is orthogonal to the plane containing the two input vectors....
 operation is an example of a vector rank function because it operates on vectors, not scalars. Matrix multiplication
Matrix multiplication

In mathematics, matrix multiplication is the operation of multiplying a matrix with either a scalar or another matrix. This article gives an overview of the various ways to perform matrix multiplication....
 is an example of a 2-rank function, because it operates on 2-dimensional objects (matrices). Collapse operators reduce the dimensionality of an input data array by one or more dimensions. For example, summing over elements collapses the input array by 1 dimension.

Uses

Array programming is very well suited to implicit parallelization; a topic of much research nowadays. Further, Intel and compatible CPUs developed and produced after 1997 contained various instruction set extensions, starting from MMX and continuing through SSSE3
SSSE3

Supplemental Streaming SIMD Extension 3 is Intel's name for the Streaming SIMD Extensions instruction set's fourth iteration. The previous version was SSE3, and Intel have added an S rather than increment the version number, as they appear to consider it merely a revision of SSE3....
 and 3DNow!
3DNow!

3DNow! is the trade name of a multimedia extension created by AMD for its processors, starting with the K6-2 in 1998. It is an addition of SIMD instructions to the traditional x86 instruction set, designed to improve a central processing unit's ability to perform the vector processing requirements of many graphic-intensive applications....
, which include rudimentary SIMD
SIMD

In computing, SIMD is a technique employed to achieve data level parallelism....
 array capablilties. Array processing is distinct from parallel processing
Parallel computing

Parallel computing is a form of computing in which many calculations are carried out simultaneously, operating on the principle that large problems can often be divided into smaller ones, which are then solved Concurrency ....
 in that one physical processor performs operations on a group of items simulataneously while parallel processing aims to split a larger problem into smaller ones (MIMD
MIMD

In computing, MIMD is a technique employed to achieve parallelism. Machines using MIMD have a number of processors that function Asynchrony and independently....
) to be solved piecemeal by numerous processors. Processors with two or more cores are increasingly common today.

Languages

The canonical examples of array programming languages are APL, its successor J, and Fortran 90
Fortran

Fortran is a general-purpose programming language, procedural programming language, imperative programming language programming language that is especially suited to numerical analysis and scientific computing....
. Others include: A+
A+ (programming language)

A+ is an array programming language, a dialect of APL with aggressive extensions. Arthur Whitney developed the "A" portion of A+, while other developers at Morgan Stanley extended it, adding a graphical user interface and other language features....
, Analytica
Analytica

Analytica is a visual software package developed by for creating, analyzing and communicating quantitative decision models. Analytica includes hierarchical influence diagrams for visual creation and view of models, intelligent arrays for management of multidimensional data, Monte Carlo simulation for analyzing risk and uncertainty, and a g...
, IDL, K
K (programming language)

K is a proprietary array processing language developed by Arthur Whitney and commercialized by Kx Systems. The language serves as the foundation for KDB, an in-memory, column-based database, and other related financial products....
, Mathematica
Mathematica

Mathematica is a computational software program used widely in scientific, engineering, and mathematical fields and other areas of technical computing....
, MATLAB
MATLAB

MATLAB is a Numerical analysis environment and programming language. Maintained by The MathWorks, MATLAB allows easy matrix manipulation, plotting of function and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages....
, NumPy, GNU Octave
GNU Octave

Octave is a computer program for performing numerical analysis which is mostly compatible with MATLAB. It is part of the GNU Project. It is free software under the terms of the GNU General Public License....
, PDL
Perl Data Language

PDL is a set of array programming extensions to the Perl.PDL is an extension to Perl v5, intended for scientific and other data intensive programming tasks....
, R
R (programming language)

In computing, R is a programming language and software environment for statistics computing and graphics. It is an implementation of the S programming language with lexical scoping semantics inspired by Scheme ....
, S-Lang
S-Lang (programming language)

S-Lang is an interpreted language programming language designed by John E. Davis to provide extensibility to C-based applications in the form of an embedded interpreter....
, SAC
SAC programming language

SAC is a strict purely functional programming language programming language which design is focused on the needs of numerical applications. Emphasis is laid on efficient support for array processing....
, Nial and ZPL.

Category:Array programming languages provides an exhaustive list.


Examples

In scalar languages like FORTRAN 77
Fortran

Fortran is a general-purpose programming language, procedural programming language, imperative programming language programming language that is especially suited to numerical analysis and scientific computing....
, C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
, Pascal
Pascal (programming language)

Pascal is an influential imperative programming and Procedural programming programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structure....
, Ada
Ada (programming language)

Ada is a structured programming, statically typed, Imperative programming, and Object-oriented programming high-level language computer programming programming language, extended from Pascal and other languages....
, etc. operations apply only to single values, so a+b expresses the addition of two numbers. In such languages adding two arrays requires indexing and looping:

FORTRAN 77

00 DO 10 I = 1, N DO 10 J = 1, N 10 A(J,I) = A(J,I) + B(J,I) C for (i = 0; i < n; i++) for (j = 0; j < n; j++) a[i][j] += b[i][j]; PASCAL for i:=1 to n do for j:=1 to n do a[i,j] := a[i,j] + b[i,j]; This need to loop and index to perform operations on arrays is both tedious and error prone.

In array languages, operations are generalized to apply to both scalars and arrays. Thus, a+b expresses the sum of two scalars if a and b are scalars, or the sum of two arrays if they are arrays. When applied to arrays, the operations act on corresponding elements as illustrated in the loops above. Indeed, when the array language compiler/interpreter encounters a statement like:

A := A + B

where A and B are two-dimensional arrays, it generates code that is effectively the same as the C loops shown above. An array language, therefore, simplifies programming but may come at a cost known as the abstraction penalty . Because the additions are performed in isolation to the rest of the coding, it may not produce the optimally most efficient
Algorithmic efficiency

In computer science, efficiency is used to describe properties of an algorithm relating to how much of various types of resources it consumes. The two most frequently encountered are...
 code (for example if additions of other elements of the same array are subsequently encountered during the same execution, causing unecessary repeated lookups). Even the most sophisticated optimizing compiler would have an extremely hard time amalgamating two or more apparently disparate functions which might appear in different program sections or sub-routines (yet this would be entirely obvious to a programmer who would naturally try to ensure the sums were aggregated on the same 'pass' of the array to minimize overhead
Computational overhead

In computer science, overhead is generally considered any combination of excess or indirect computation time, memory, bandwidth, or other resources that are required to attain a particular goal....
).

As another example, the following generates the inner product of two arrays (matrix multiplication) in the array language Nial
Nial

Nial is a high-level array programming language developed from about 1981 by Mike Jenkins of Queen's University, Kingston, Kingston, Ontario, Canada....
:

a inner[+,*] b

Notice how the operations are sequenced on the arrays.

See also


  • Array slicing
    Array slicing

    In computer programming, array slicing is an operation that extracts certain elements from an array and packages them as another array, possibly with different number of indices and different index ranges....


External links