Size returns the total number of elements in array «A».
When applied to a scalar (a zero-dimensional array), it returns 1.
Size does not count elements that are contained within a reference. So if a reference occurs in a cell of an array, it will be counted as one, even if it points to an array that contains many cells.
Length of an index
To get the length of an index, use IndexLength(I). (introduced in Analytica 5.0).
When used on an index,
Size(I) usually, but not always, returns the length of the index. However, because Size actually returns the size of the value of its parameter, this does not give the index length when the parameter is a self-indexed array, or when the parameter is the dynamic index in a dynamic loop (usually the Time index).
When the identifier is the local identifier that has been declared as an index, then
Size(I) does return the index length rather than the value length, even when
I is a self-indexed array or dynamic index.
Two other reliable ways to obtain the length of an index are:
Or by using a User-Defined Function:
Function Index_Length(I : Index) := Size(I).
Length of the implicit dimension
All dimensions of an Analytica array correspond to an explicit index object, except for one -- the implicit dimension. See the article Implicit Dimensions for more details.
When «A» has an implicit dimension, its length can be obtained using:
Size(A, listLen: true)
You can also use this to determine the number of repeated parameters supplied to a User-Defined Function. For example:
Function GeoAve(x : ... Number )
Definition: Exp(Sum(Ln(x))/Size(x, ListLen: true))
Array Abstraction Considerations
Although Size does return a result when the number of dimensions of an array changes, this function does not strictly obey the law of array abstraction. This is because it operations over all indexes that are present, rather than only over a set of explicit specified indexes. Because of this, if used inappropriately within a model, incorrect results from Parametric Analyses could result.
In this context, use of Size to find the length of an index or the length of the implicit dimension is a usage that is consistent with the law of array abstraction.
Inside a dynamic loop,
Size(Time) returns 1. This occurs because in a value context within a dynamic loop, the expression
@Time) evaluates to the current time point (or time position), not the full array of time values. Since there is only one time point at a time in a dynamic loop, the size is 1.
This case is worth remembering since it can be kind of confusing when you (incorrectly) attempt to use
@Time/Size(Time) to compute progress, which of course does not produce the desired result. The remedy here is to remember to use
Size(IndexValue(Time)) to obtain the index length.
Enable comment auto-refresher