Error Messages/40259

< Error Messages
Revision as of 19:19, 5 February 2016 by Bbecane (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Error message example

In call to function Sum, the second parameter, I, is not a valid index.

General form:

In call to function %1%, the %2% parameter, %3%, is not a valid index.

What caused it?

The indicated parameter is not the identifier of a valid index.

Omission of Index qualifier in Parameters

If the error occurs inside a User-Defined Function (UDF) that you have created, and the index parameter in the error message in the message is a parameter of your function, then you probably forgot to decorate the parameter with the Index qualifier. In this case, the fix is to modify the Parameters attribute of your UDF. For example, if your Parameters are currently

( x, y, i )

change this to be

( x, y; i : Index )

Notice the use of a semi-colon here, so that the qualifier applies only to the «i» parameter and not to x and y. In this case, values are passed for x and y, but the «i» denotes the original index supplied by the caller.

Self-index ambiguity

Note that Class of the variable may but does not have to be Index (shown as a parallelogram). It is sufficient that its value is a list of elements, or that it has a "self-index" -- for example, its Domain is a list of numbers or text values.

There are several ways in which a variable can have a self-index:

  • It could be a self-indexed table (where Self is being used as one of the table dimensions). In this case, the index values are placed in the IndexVals attribute.
  • When the definition evaluates to a result that contains an implicit dimension, the implicit dimension is promoted to be a self-index. An implicit dimension is created when your expression operates over an explicit list, or over the result of function that returns a list, such as Sequence, Subset, SplitText, or Unique.
  • With Analytica 4.2 or earlier, or with Analytica 4.3 and the Domain as Self-Index preference is checked, it sets a self-index when the Domain is set to be a list or a list-of numbers. If you load a model built with Analytica pre-4.3 into a more recent release, this preference is checked automatically. If you subsequently uncheck it in the Preferences dialog, it could cause this error.


Notes on the Domain as Self-Index Preference

If you have recently migrated your model from 4.2 or earlier into Analytica 4.3, then you might see this error as the result of 4.3's cleaner domain semantics. To illustrate, consider the following scenario.

Variable A := Choice(Self, 1)
Domain A := ['apple', 'banana', 'cherry', 'date']
Variable B := Choice(A, 1)

Prior to Analytica 4.3, Analytica would be perfectly happy with Variable B. Its set of choices are pulled from the domain of A. However, on inspection, this is a bit strange. Variable A is actually defined to be a single value -- essentially it is "apple". So why should A be considered to be a valid index for the call to Choice in B? The Domain of A specified the possible values of A, but not the actual value of A. This usage of domain of A as a self-index created a confused semantics over exactly what the domain attribute means.

Analytica 4.3 cleans up this semantics -- the domain of A is the set of values that Variable A can take on -- and is not the actual value of A. Hence, when Variable A is defined as "apple" (or as Choice(Self, 1), which is equivalent to "apple"), then Variable A is scalar-valued, and is not a valid index.

When you are starting fresh, this cleaner semantics for the domain of A is to be preferred. But as you can see, if you are migrating a pre-4.3 model to 4.3, it opens up a potential backward compatibility problem. We have always believed in ensuring that Analytica remain backward compatible as you migrate models forward through new releases, and hence, Analytica 4.3 includes a preference setting called Domain as Self-Index which preserves the old (confused) semantics, and is automatically enabled when you load a pre-4.3 model into 4.3. However, whenever possible, we recommend that you turn off that preference if you can. But, if you have a situation like this, you may encounter the current error as a result of turning off that preference.

How to fix it

To diagnose this, view the result of your variable, «I». If it has a self-index, in most cases you will see its own identifier listed among the pivot controls for its result table. Or, if it a list, it'll display as a list of elements with no named pivoter. If it isn't there, then view the domain attribute for the same variable. If that is not set to a list, then you've found the reason your variable is not a valid index.

If your variable, «I», is a 1-D array, and those values are what you want to use as your index values, it may mean you need to wrap the definition inside an IndexValue function call.

If you encountered this as a result of turning off the Domain as Self-Index preference, then you can turn the preference back on, of course. Since there are benefits to turning off that preference, you may need to refine your model a bit so that it isn't relying on the domain values for the source of the index values. Most likely, if your expression is Choice(A, 1), the preferred option is to move the domain values of A into a separate index variable, say Avals, and change your choice to Choice(Avals,1). If your choice is really asking for a selection among the possible values of A, rather than from the actual value of A, then you could also change your choice definition to Choice(Domain of A, 1) to fix the problem. This later fix will resolve the problem regardless, but whether it is the best change depends on what you are really intending to encode, and whether this accurately reflects the intention of your model logic.

See Also

Comments


You are not allowed to post comments.