org.apache.sysml.udf.lib

Class CumSumProd

  • All Implemented Interfaces:
    Serializable


    public class CumSumProd
    extends PackageFunction
    Variant of cumsum:
    Computes following two functions:
     
     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");
     
     
    See Also:
    Serialized Form
    • Constructor Detail

      • CumSumProd

        public CumSumProd()
    • Method Detail

      • getNumFunctionOutputs

        public int getNumFunctionOutputs()
        Description copied from class: PackageFunction
        Method to get the number of outputs of this package function. This method should be implemented in the user's function.
        Specified by:
        getNumFunctionOutputs in class PackageFunction
        Returns:
        number of outputs
      • getFunctionOutput

        public FunctionParameter getFunctionOutput(int pos)
        Description copied from class: PackageFunction
        Method to get a specific output of this package function. This method should be implemented in the user's function.
        Specified by:
        getFunctionOutput in class PackageFunction
        Parameters:
        pos - function position
        Returns:
        function parameter
      • execute

        public void execute()
        Description copied from class: PackageFunction
        Method that will be executed to perform this function.
        Specified by:
        execute in class PackageFunction

Copyright © 2017 The Apache Software Foundation. All rights reserved.