### Forcing a Series Result

The SERIES modifier forces an SPL routine to always return a series.

Consider three similar SPL routines:

smax1(x)

{

return(max(x));

}

SERIES smax2(x)

{

return(max(x));

}

ITERATE smax3(x)

{

return(max(x));

}

A = {{1, 2, 3},

{2, 4, 6},

{3, 6, 9}};

m1 = smax1(A);

m2 = smax2(A);

m3 = smax3(A);

m1 == 9

m2 == {9}

m3 == {{3, 6, 9}}

smax is defined as a standard SPL function and returns the maximum of the array A as a scalar.

Because smax2 is declared as a SERIES function, it automatically converts the return value to a series. Thus, smax2 behaves as:

{max(A)}

or

castseries(A)

Since smax3 is declared as an ITERATE function, it returns the maximum of each column and behaves as:

colmax(A)

The SERIES modifier forces an SPL routine to always return a series. This behavior optimizes evaluation since the return type is already known before the calculation takes place. The optimizations are similar to what occurs with internal functions that always return a series such as FFT or INTEG.

The series mode of an SPL function can be temporarily set or cleared at run time with the series function. For example:

series("smax1", 1)

or

series smax1

converts smax1 to a series function such that it operates identically to smax2. This behavior persists only for the duration of the current session. Use the SERIES modifier in the function definition to make the behavior permanent.