Rank (computer programming)
Encyclopedia
In computer programming
Computer programming
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...

, rank with no further specifications is usually a synonym for (or refers to) "number of dimensions"; thus, a bi-dimensional array has rank two, a three-dimensional array has rank three and so on.
Strictly, no formal definition can be provided which applies to every programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....

, since each of them has its own concepts, semantics
Formal semantics of programming languages
In programming language theory, semantics is the field concerned with the rigorous mathematical study of the meaning of programming languages and models of computation...

 and terminology; the term may not even be applicable or, to the contrary, applied with a very specific meaning in the context of a given language.

In the case of APL
APL programming language
APL is an interactive array-oriented language and integrated development environment, which is available from a number of commercial and noncommercial vendors and for most computer platforms. It is based on a mathematical notation developed by Kenneth E...

 the notion applies to every operand; and dyad
Dyad
Dyad may refer to:*Dyad , a pair of sister chromatids occurring in prophase I of meiosis; may also be used to describe protein morphology*Dyad , Greek philosophers' principle of "twoness" or "otherness"...

s ("binary functions") have a left rank and a right rank.

The box below instead shows how rank of a type and rank of an array expression could be defined (in a semi-formal style) for C++ and illustrates a simple way to calculate them at compile time.

  1. include


/* Rank of a type
* -------------
*
* Let the rank of a type T be the number of its dimensions if
* it is an array; zero otherwise (which is the usual convention)
*/
template struct rank
{ static const std::size_t value = 0; };

template
struct rank
{ static const std::size_t value = 1 + rank::value; };

/* Rank of an expression
*
* Let the rank of an expression be the rank of its type
*/
template
char(&rankof(t(&)[n]))[n];


Given the code above the rank of a type T can be calculated at compile time by
rank::value


and the rank of an array-expression expr by
sizeof(rankof(expr))

See also

  • Rank (linear algebra)
    Rank (linear algebra)
    The column rank of a matrix A is the maximum number of linearly independent column vectors of A. The row rank of a matrix A is the maximum number of linearly independent row vectors of A...

    , for a definition of rank as applied to matrices
    Matrix (mathematics)
    In mathematics, a matrix is a rectangular array of numbers, symbols, or expressions. The individual items in a matrix are called its elements or entries. An example of a matrix with six elements isMatrices of the same size can be added or subtracted element by element...

  • Rank (J programming language), a concept of the same name in the J programming language
    J (programming language)
    The J programming language, developed in the early 1990s by Kenneth E. Iverson and Roger Hui, is a synthesis of APL and the FP and FL function-level languages created by John Backus....

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK