Multi-dimensional Structures

FPP supports arrays, matrices, cubes and lists.

Arrays

An array is a set of scalar values. Currently, it can only contain floating point values, but it will be extended to support all scalar types in the future. You can create an array with the keyword array and you can access its elements with square brackets (like in C / JAVA). Due to the fact that all scalar values are floating point, you can very well require access element #4.2 of an array. In this case, the index is rounded to the nearest value:

a[4.2] == a[4]
a[4.51] == a[5]
a[4.5] == a[5]

Due to the nature of the GPU target platform, there is a huge performance difference between creating an array of static size (i.e. array(10)) and creating an array of dynamic size (i.e. a = 25 then array(a)). You are advised to to use fixed size arrays and use resize functions to shape your arrays.

Matrices

A matrix behaves just like an array, but it has two dimensions. You can access its elements with the square brackets notation, i.e. matrix[2][3] for the element located on line 2, column 3. The same recommendation of using fixed sized matrices holds true, as for the arrays.

Cubes

A cube behaves just like an array, but with three dimensions. You can access its elements with the square brackets notation, i.e. cube[2][3][2], for the element located at line 2, column 3, depth 2. The same recommendation of using fixed sized matrices holds true, as for the arrays and matrices.

Lists

A list is a set of string values. It is not represented on the GPU because it is never transferred there. You cannot use it as a local variable and is only used in a few scenario related functions.

An example illustrating how each type of multi-dimensional structure is declared and initialized is provided in the code block below:

// Array
def a = array(10)
a[5] = 3

// Matrix (first argument corresponds to rows; second argument to columns)
def m = matrix(10,10)
m[0][2] = 4

/*
* Cube (first argument corresponds to rows; second argument to columns; third 
* argument to ranks)
*/
def c = cube(10,10,10)
c[5][5][3] = 5

// List
data0D("type", ["p1", "p2"], calculationDate())

Alternatively, you can declare and initialize arrays, matrices and cubes using an additional argument that will “fill” the structure with that value:

// Array
def a = array(10, 3) // a 10 values array initialized with values of 3

// Matrix
def m = matrix(10, 10, 4) // a 10x10 matrix initialized with values of 4
m[0][2] = 4

// Cube
def c = cube(10,10,10, 5) // a 10x10x10 cube initialized with values of 5