• Aucun résultat trouvé

Matrix indexing

Dans le document hA pubs\latex\fpe\edl\...) (Page 56-61)

Indexing vectors, matrices and arrays

7.3 Matrix indexing

This section describes the meaning of various types of index which you can use in the two parallel subscript positions of a matrix (denoted by M).

7.3.1 Indexed matrix selection

When you select in an expression, a matrix variable, or a matrix expression in parentheses, a scalar, vector or matrix object could be selected according to the type of the indexing expressions in the two parallel subscript positions.

Type of indexing expression Selection performed

Null, Null The entire matrix is selected. The same effect is ob tained by giving the matrix name with no following parentheses.

For example:

M(,)

or simply M

44 manlO2.O1 AMT

7.3. Matrix indexing 45

Null, Integer scalar expression (IS) A vector is selected corresponding to the IS’ column (Integer scalar expression (IS), Null) (row) of M. For example:

M(,3) M(I+J,)

In the first example a vector which is a copy of the third column of the matrix M is selected.

In the second example a vector which is a copy of the (I+J)th row of the matrix M is selected

Null, Logical vector expression (LV) LV has to have one .TRUE. component. A vector is Se-(Logical vector expression (LV), Null) lected corresponding to the ith column (row) of M, where

LV(i) is the .TRUE. component of LV. For example:

M( ,IV.EQ.3)

would be valid if a single component of the integer vec tor IV had the value 3; in this case, the column of M corresponding to this component would be selected Null, Integer vector expression (IV) A vector is selected made up of one component from (Integer vector expression (IV), null) each row (column) of M. The component selected from the i1’ row (column) is that in the

j’

column (row) where j=IV(i)

Null, Logical matrix expression (LM) LM has to have one and only one .TRUE. component in (Logical matrix expression (LM), Null) each row (column). A vector is selected whose i1 com ponent is M(i,j) (or M(j, 1)) where LM(i,j) (or LM(j, 1)) is the single .TRUE. component

Null, + The entire matrix is selected and shifted one place to (+, Null) the west (north); that is, column (row) i of the selected matrix is equal to column (row) 1+1 of M. No shift is performed if the relevant dimensionhas a size of 1. The value of the last column (row) of the selected matrix is determined by the options specified in the local GEOM ETRY statement (see section 7.6)

Null, The entire matrix is selected and shifted one place to

(—,

Null) the east (south); that is, column (row) i of th selected matrix is equal to column (row) i-i of M. No shift is performed if the relevant dimension has a size of 1. The value of the first column (row) of the selected matrix is determined by the options specified in the local GEOM ETRY statement (see section 7.6)

FORTRAN-PLUS enhanced manlO2.O1 45

In any of the above cases, you can replace the null indexing expression by a non-null indexing expression, with the following effects:

• If the other indexing expression is either + or —,you can replace the null indexing expression by an integer scalar, logical vector, integer vector, or logical matrix expression. The selec tions performed by the replacement indexing constructs are as described above, except that the indexed matrix variable or expression is shifted in the appropriate direction before the selections are performed

• If the other indexing expression is either + or —, you can also replace the null indexing expression by + or—,in which case the indexed matrix variable or expression is shifted twice, in the appropriate directions, to select its value, The order in which the shifts are performed is immaterial

• If the other indexing expression is anything other than + or —, you can replace the null indexing expression by either an integer scalar expression or a logical vector expression. The indexing expression that replaces the null indexing expression will perform the appropri ate vector indexing (see section 7.2.1) on the vector object selected by the other indexing expression

7.3.2 Indexed matrix referencing

When a matrix, M, is updated on the left hand side of an assignment statement, you can identify the whole or a subset of the components of matrix M for updating, by specifying particular types of index in its two parallel subscript positions.

Type of index Effect

Null, Null The entire matrix is referenced for updating. The same effect is obtained by giving the matrix name or expres sion with no following parentheses

Null, Integer scalar expression (IS) Components in the IS” column (row) of M are identified (Integer scalar expression (IS), Null) for updating.

If the expression (on the right hand side of the assign ment statement) being used to assign to M is a vector, the vector is implicitly expanded by columns (rows) be fore indexed assignment is performed; that is, the vector is implicitly expanded to a matrix of the same shape as M and each of whose columns (rows) is a copy of the vector. The size of the vector has to be the same as the number of rows (columns) in M

46 manlO2.O1 AMT

7.3. Matrix indexing 47

Null, Logical vector expression (LV) Components in each column (row) of M corresponding (Logical vector expression (LV), Null) to a .TRUE. component in LV are identified for updat

ing.

If the expression (on the right hand side of the assign ment statement) being used to assign to M is a vector, the vector is implicitly expanded by columns (rows) be fore indexed assignment is performed; that is, the vector is implicitly expanded to a matrix of the same shape as M and each of whose columns (rows) is a copy of the vector. The size of the vectorhas to be the same as the number of rows (columns) in M

Null, Integer vector expression (IV) One component in each row (column) of M is identi (Integer vector expression (IV), Null) fled for updating. The component identified from row

(column) i is that in column (row)

j

where j=IV(i).

If the expression (on the right hand side of the assign ment statement) being used to assign to M is a vector, the vector is implicitly expanded by columns (rows) be fore indexed assignment is performed; that is, the vector is implicitly expanded to a matrix of the same shape as M and each of whose columns (rows) is a copy of the vector. The size of the vector has to be the same as the number of rows (columns) in M

Null, Logical matrix expression (LM) Each component of the indexed matrix variable that cor (Logical matrix expression (LM), Null) responds to a .TRUE. component in LM is identified for

updating.

If the expression (on the right hand side of the assign ment statement) being used to assign to M is a vector, the vector is implicitly expanded by columns (rows) be fore indexed assignment is performed; that is, the vector is implicitly expanded to a matrix of the same shape as M and each of whose columns (rows) is a copy of the vector. The size of the vectorhas to be the same as the number of rows (columns) in M

Integer scalar expression (IS1), Integer scalar expression (1S2)

The single component M(IS1,1S2) is identified for up dating

Integer scalar expression (IS), Integer vector expression (IV) (Integer vector expression (IV), Integer scalar expression (IS))

The single component (IS,j) (component (j,IS)) of M is identified for updating, where j=IV(IS)

FQRTRAN-PL US enhanced man 102.01 47

Integer scalar expression (IS), Logical matrix expression (LM) (Logical matrix expression (LM), Integer scalar expression (IS))

Each component in row (column) IS of M correspond ing to a .TRUE. component in the corresponding row (column) of LM is identified for updating

Integer vector expression (IV), Logical vector expression (LV) (Logical vector expression (LV), Integer vector expression (IV))

For each i, IV identifies one component from the i1 column (row) of M namely the

jr”

component where jIV(i). Of these components, only those corresponding to .TRUE. values in LV are identified for updating Logical vector expression (Lvi), Logical vector expression (LV2)

Components M(i,j) such that LV1(i) and LV2(j) are .TRUE. are identified for updating

Logical matrix expression (LM), Logical vector expression (LV) (Logical vector expression (LV), Logical matrix expression (LM))

The logical matrix expression identifies those elements of M corresponding to .TRUE. values in LM. Of those, the components identified for updating are just those in columns (rows) corresponding to .TRUE. components in the logical vector expression

You can identify for updating zero, one, or more matrix variable components by replacing both indexing expressions with a single indexing expression, as follows:

Indexing expression Effect

Logical matrix expression Each component of the indexed matrix variable that cor responds to a .TRUE. component in the logical matrix expression is identified for updating

Integer scalar expression A single component of the indexed matrix variable is identified for updating. This is the technique of reduced rank indexing (see section 7.5)

All components identified for updating in any of the indexing constructs described in this section are processed in parallel.

a

48 manlO2.O1 AMT

Dans le document hA pubs\latex\fpe\edl\...) (Page 56-61)