public class CumSumProd extends PackageFunction
cumsum_prod = function (Matrix[double] X, Matrix[double] C, double start) return (Matrix[double] Y)
# Computes the following recurrence in log-number of steps:
# Y [1, ] = X [1, ] + C [1, ] * start;
# Y [i+1, ] = X [i+1, ] + C [i+1, ] * Y [i, ]
{
Y = X; P = C; m = nrow(X); k = 1;
Y [1, ] = Y [1, ] + C [1, ] * start;
while (k < m) {
Y [k+1 : m, ] = Y [k+1 : m, ] + Y [1 : m-k, ] * P [k+1 : m, ];
P [k+1 : m, ] = P [1 : m-k, ] * P [k+1 : m, ];
k = 2 * k;
}
}
cumsum_prod_reverse = function (Matrix[double] X, Matrix[double] C, double start) return (Matrix[double] Y)
# Computes the reverse recurrence in log-number of steps:
# Y [m, ] = X [m, ] + C [m, ] * start;
# Y [i-1, ] = X [i-1, ] + C [i-1, ] * Y [i, ]
{
Y = X; P = C; m = nrow(X); k = 1;
Y [m, ] = Y [m, ] + C [m, ] * start;
while (k < m) {
Y [1 : m-k, ] = Y [1 : m-k, ] + Y [k+1 : m, ] * P [1 : m-k, ];
P [1 : m-k, ] = P [k+1 : m, ] * P [1 : m-k, ];
k = 2 * k;
}
}
The API of this external built-in function is as follows:
func = externalFunction(matrix[double] X, matrix[double] C, double start, boolean isReverse) return (matrix[double] Y)
implemented in (classname="org.apache.sysml.udf.lib.CumSumProd",exectype="mem");
Constructor and Description |
---|
CumSumProd() |
Modifier and Type | Method and Description |
---|---|
void |
execute()
Method that will be executed to perform this function.
|
FunctionParameter |
getFunctionOutput(int pos)
Method to get a specific output of this package function.
|
int |
getNumFunctionOutputs()
Method to get the number of outputs of this package function.
|
createOutputFilePathAndName, execute, getBaseDir, getConfiguration, getFunctionInput, getNumFunctionInputs, hasVarNumFunctionOutputs, setBaseDir, setConfiguration, setFunctionInputs, setInput, setNumFunctionInputs
public int getNumFunctionOutputs()
PackageFunction
getNumFunctionOutputs
in class PackageFunction
public FunctionParameter getFunctionOutput(int pos)
PackageFunction
getFunctionOutput
in class PackageFunction
pos
- function positionpublic void execute()
PackageFunction
execute
in class PackageFunction
Copyright © 2018 The Apache Software Foundation. All rights reserved.