eachPre#
- swordfish.function.eachPre()#
Apply func over all pairs of consecutive elements of X. It is equivalent to: F(X[0], pre), F(X[1], X[0]), …, F(X[n], X[n-1]).
- Parameters:
func (Constant) – A binary function.
X (Constant) – A vector/matrix/table. When X is a matrix, pre must be a scalar or vector; when X is a table, pre must be a scalar or table. When pre is absent, the first element in the result would be NULL.
pre (Constant, optional) – Provides an initial pre-value for the calculation. Its data form depends on the data form of X.
assembleRule (Constant, optional) –
Indicates how the results of sub-tasks are merged into the final result. It accepts either an integer or a string, with the following options:
0 (or “D”): The default value, which indicates the DolphinDB rule. This means the data type and form of the final result are determined by all sub results. If all sub results have the same data type and form, scalars will be combined into a vector, vectors into a matrix, matrices into a tuple, and dictionaries into a table. Otherwise, all sub results are combined into a tuple.
1 (or “C”): The Consistent rule, which assumes all sub results match the type and form of the first sub result. This means the first sub result determines the data type and form of the final output. The system will attempt to convert any subsequent sub results that don’t match the first sub result. If conversion fails, an exception is thrown. This rule should only be used when the sub results’ types and forms are known to be consistent. This rule avoids having to cache and check each sub result individually, improving performance.
2 (or “U”): The Tuple rule, which directly combines all sub results into a tuple without checking for consistency in their types or forms.
3 (or “K”): The kdb+ rule. Like the DolphinDB rule, it checks all sub results to determine the final output. However, under the kdb+ rule, if any sub result is a vector, the final output will be a tuple. In contrast, under the DolphinDB rule, if all sub results are vectors of the same length, the final output will be a matrix. In all other cases, the output of the kdb+ rule is the same as the DolphinDB rule.