-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathApply2Elements.ecl
36 lines (34 loc) · 1.32 KB
/
Apply2Elements.ecl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*##############################################################################
## HPCC SYSTEMS software Copyright (C) 2016 HPCC Systems. All rights reserved.
############################################################################## */
IMPORT $ as PBblas;
IMPORT PBblas.Types;
IMPORT Std.BLAS;
//Alias entries for convenience
Layout_Cell := Types.Layout_Cell;
value_t := Types.value_t;
IElementFunc := PBblas.IElementFunc;
dim_t := PBblas.Types.dimension_t;
/**
* Apply a user-defined function to each element of the matrix.
*
* <p>Use PBblas.IElementFunc as the prototype function.
* Input and output may be a single matrix, or myriad matrixes with
* different work item ids.
*
* @param X A matrix (or multiple matrices) in Layout_Cell form.
* @param f A function based on the IElementFunc prototype.
* @return A matrix (or multiple matrices) in Layout_Cell form.
* @see PBblas/IElementFunc
* @see PBblas/Types.Layout_Cell
*/
EXPORT DATASET(Layout_Cell) Apply2Elements(DATASET(Layout_Cell) X,
IElementFunc f) := FUNCTION
Layout_Cell apply_func(Layout_Cell lr) := TRANSFORM
new_v := f(lr.v, lr.x, lr.y);
SELF.v := new_v;
SELF := lr;
END;
DATASET(Layout_Cell) rslt := PROJECT(X, apply_func(LEFT));
return rslt;
END;