| United States-English |
|
|
|
![]() |
HP Fortran Compiler for HP-UX: HP Fortran Programmer's Reference > Chapter 4 ArraysArray-valued functions |
|
A function may be array-valued; that is, its return value may evaluate to an array of values rather than to a scalar. Array-valued functions may appear in any array expression except:
Array-valued functions may also be used in an array expression wherever a scalar function reference is allowed but must be conformable—that is, the function result must have the same shape as the expression. The following sections describe intrinsic functions and user-defined functions that are array-valued. Elemental procedures and transformation procedures have particular relevance to array expressions. Elemental procedures—for example, SQRT and SIN—are specified for scalar arguments, but with an array argument they return an array-valued result with the same shape as the argument. Each element of the result is as if the function were applied to each corresponding element of the argument. A transformational procedure—for example, RESHAPE, SUM, and MATMUL—generally has one or more array arguments that the procedure operates on as a whole, and usually returns an array-valued result whose elements may depend not only on the corresponding elements of the arguments but also on the values of other elements of the arguments. User-defined functions can return either a scalar-valued result or an array-valued result. A scalar function can appear in an array expression; its effect is to broadcast its value throughout a conformable array. A reference to a user-defined array-valued function must obey the rules for functions in general, and must also conform to the shape of the expression in which it appears. User-defined functions are described in “External procedures”. The following code segment illustrates two array-valued functions, genrand (user-defined) and RESHAPE (intrinsic):
|
|||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||