Difference between revisions of "Size"
Line 2: | Line 2: | ||
[[Category:Doc Status C]] <!-- For Lumina use, do not change --> | [[Category:Doc Status C]] <!-- For Lumina use, do not change --> | ||
− | = Size(A) = | + | == Size(A) == |
− | [[Size]] | + | [[Size]] returns the total number of elements in array «A». |
When applied to a scalar (a zero-dimensional array), it returns 1. | When applied to a scalar (a zero-dimensional array), it returns 1. | ||
Line 10: | Line 10: | ||
[[Size]] does not count elements that are contained within a [[Using References|reference]]. So if a [[Using References|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. | [[Size]] does not count elements that are contained within a [[Using References|reference]]. So if a [[Using References|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. | ||
− | = Library = | + | == Library == |
− | |||
Array library | Array library | ||
− | = Length of an index = | + | == Length of an index == |
− | |||
When used on an index, [[Size]](I) returns the length of the index. However, be careful -- if used with a self-indexed array, it is the size of the array, not the size of the index, that is returned. When an array is one-dimensional, these are the same, but a self-indexed array could be multi-dimensional. Two safer ways to obtain the length of an index are: | When used on an index, [[Size]](I) returns the length of the index. However, be careful -- if used with a self-indexed array, it is the size of the array, not the size of the index, that is returned. When an array is one-dimensional, these are the same, but a self-indexed array could be multi-dimensional. Two safer ways to obtain the length of an index are: | ||
− | + | :<code>Size(IndexValue(I))</code> | |
or | or | ||
− | + | :<code>Sum(1, I)</code> | |
− | = Length of the [[Implicit Dimensions|implicit dimension]] = | + | == Length of the [[Implicit Dimensions|implicit dimension]] == |
All dimensions of an Analytica array correspond to an explicit index object, except for one -- the [[Implicit Dimensions|implicit dimension]]. See the article [[Implicit Dimensions]] for more details. | All dimensions of an Analytica array correspond to an explicit index object, except for one -- the [[Implicit Dimensions|implicit dimension]]. See the article [[Implicit Dimensions]] for more details. | ||
− | + | When «A» has an implicit dimension, its length can be obtained using: | |
− | + | :<code>Size(A, listLen: true)</code> | |
You can also use this to determine the number of [[Function Parameter Qualifiers#Ellipsis|repeated parameters]] supplied to a [[User-Defined Function]]. For example: | You can also use this to determine the number of [[Function Parameter Qualifiers#Ellipsis|repeated parameters]] supplied to a [[User-Defined Function]]. For example: | ||
− | + | :<code>Function GeoAve(x : ... Number )</code> | |
− | + | :<code>Definition: Exp(Sum(Ln(x))/Size(x, ListLen: true))</code> | |
− | = Array Abstraction Considerations = | + | == 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. | + | 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|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. | 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. | ||
− | = Notes = | + | == Notes == |
− | |||
− | |||
− | + | Inside a [[Dynamic|dynamic loop]], <code>Size(Time)</code> returns 1. This occurs because in a value context within a [[Dynamic|dynamic loop]], the expression <code>Time</code> (or <code>@Time</code>) 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 <code>@Time/Size(Time)</code> to compute progress, which of course does not produce the desired result. The remedy here is to remember to use <code>Size(IndexValue(Time))</code> to obtain the index length. | |
+ | == See Also == | ||
* [[Sum]] | * [[Sum]] | ||
* [[Implicit Dimensions]] | * [[Implicit Dimensions]] | ||
− | + | * [[Time]] | |
− |
Revision as of 18:42, 15 January 2016
Size(A)
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.
Library
Array library
Length of an index
When used on an index, Size(I) returns the length of the index. However, be careful -- if used with a self-indexed array, it is the size of the array, not the size of the index, that is returned. When an array is one-dimensional, these are the same, but a self-indexed array could be multi-dimensional. Two safer ways to obtain the length of an index are:
Size(IndexValue(I))
or
Sum(1, 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.
Notes
Inside a dynamic loop, Size(Time)
returns 1. This occurs because in a value context within a dynamic loop, the expression Time
(or @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