Error Messages/40045

Error Text

Trying to combine two arrays with implicit indexes. An array can contain only one implicit index. One cure might be to define at least one of these as an explicit index.

Description

Each dimension of a multi-dimensional array in Analytica is associated with an index. The one exception to this rule is that an array can have one implicit dimension, but only one. This error message occurs when you perform an operation would result in two or more implicit dimensions.

The constraint of allowing at most one implicit dimension in an array ensures that we can always unambiguously specify which dimension we want to operate over whenever we perform an array operation. For example, if we want to find the maximum value along the I index, we can write Max(A,I). Since an implicit dimension has no name (because it is implicit), we can't name it in this fashion; however, in most cases, Analytica allows you to omit the index, such that if the array contains an implicit dimension, you want to operate over that dimension. If an array were to contain multiple implicit dimensions, it would be impossible to unambiguously identify the dimension of interest; hence, more than one implicit dimension results in this error.

An implicit dimension gets promoted to become a self-index if it still exists in the final result for a variable (after the promotion, the dimension is no longer implicit since at that point, it has a name). Again, if there were two implicit dimensions, it would be ambigous as to which one should be promoted.

Examples

Usually, you'll see this because you are combining two arrays, each of which already has its own explicit index. These are treated as two separate dimensions, even if they are the same length:

[1,2,3] * [4,5,6] → Error: Trying to combine two arrays with implicit indexes.

The problem can arise when you attempt to array abstract over a function that returns a list, since you'll have a list result for each case. Functions in this class include SplitText, Sequence, Subset, Unique, SortIndex. For example:

SplitText( ["1,2,3","4,5","8","9,10,11,12"], ',' ) → Error: Trying to combine two arrays with implicit indexes.

Remedies

The remedy to this problem is to replace one of the implicit dimensions with an explicit dimension.

Index X1 := [1,2,3] Do X1 * [4,5,6] →
(implicit dimension)
X1 1 4 5 6
2 8 10 12
3 12 15 18


In the case where you are array abstracting over a function that returns a list result, there is not a single simple answer to what the appropriate remedy is. Theoretically, the result of such an operation could be a non-rectangular array, which is not allowed in Analytica. To see this, consider Sequence(1, [2,4,6]) which would produce sequences [1,2], [1,2,3,4], and [1,2,3,4,5,6]. If these could be combined in to an array, each row of the array would have a different number of columns. So, in such a situation, you need to determine what the best way is in your case to deal with the non-rectangularity.

One approach is to introduce an explicit dimension with enough elements to handle the longest case you care about. You would then pad all unused cells with Null values. In the Sequence example, that looks like this:

Index D := 1..6;
For v = [2,4,6] do (
IgnoreWarnings(Array(D,Sequence(1,v)))
)

.D →
1 2 3 4 5 6
implicit dimension 2 1 2 «null» «null» «null» «null»
4 1 2 3 4 «null» «null»
6 1 2 3 4 5 6


Several built-in functions (e.g., SplitText, Subset) have optional parameters to do this mapping of the implicit index in the result to an existing index for you. For example:

IndexIndex D := 1..3;
SplitText( ["1,2,3,4","5","6,7","8,9,10"], ",", resultindex:D)
.D →
1 2 3
implicit dimension "1,2,3,4" "1" "2" "3,4"
"5" "5" «null» «null»
"6,7" "6" "7" «null»
"8,9,10" "8" "9" "10"
Comments


You are not allowed to post comments.