Class AColGroup

    • Method Detail

      • getColIndices

        public final int[] getColIndices()
        Obtain the offsets of the columns in the matrix block that make up the group
        Returns:
        offsets of the columns in the matrix block that make up the group
      • getNumCols

        public final int getNumCols()
        Obtain the number of columns in this column group.
        Returns:
        number of columns in this column group
      • shiftColIndices

        public final void shiftColIndices​(int offset)
        Shift all column indexes contained by an offset. This is used for rbind to combine compressed matrices. Since column indexes are reused between operations, we allocate a new list here to be safe
        Parameters:
        offset - The offset to move all columns
      • estimateInMemorySize

        public long estimateInMemorySize()
        Get the upper bound estimate of in memory allocation for the column group.
        Returns:
        an upper bound on the number of bytes used to store this ColGroup in memory.
      • decompressToSparseBlock

        public final void decompressToSparseBlock​(SparseBlock sb,
                                                  int rl,
                                                  int ru)
        Decompress a range of rows into a sparse block Note that this is using append, so the sparse column indexes need to be sorted afterwards.
        Parameters:
        sb - Sparse Target block
        rl - Row to start at
        ru - Row to end at
      • decompressToDenseBlock

        public final void decompressToDenseBlock​(DenseBlock db,
                                                 int rl,
                                                 int ru)
        Decompress a range of rows into a dense block
        Parameters:
        db - Sparse Target block
        rl - Row to start at
        ru - Row to end at
      • write

        public void write​(DataOutput out)
                   throws IOException
        Serializes column group to data output.
        Parameters:
        out - data output
        Throws:
        IOException - if IOException occurs
      • readFields

        public void readFields​(DataInput in)
                        throws IOException
        Deserialize column group from data input.
        Parameters:
        in - data input
        Throws:
        IOException - if IOException occurs
      • getExactSizeOnDisk

        public long getExactSizeOnDisk()
        Returns the exact serialized size of column group. This can be used for example for buffer preallocation.
        Returns:
        exact serialized size for column group
      • sliceColumns

        public final AColGroup sliceColumns​(int cl,
                                            int cu)
        Slice out the columns within the range of cl and cu to remove the dictionary values related to these columns. If the ColGroup slicing from does not contain any columns within the range null is returned.
        Parameters:
        cl - The lower bound of the columns to select
        cu - The upper bound of the columns to select (not inclusive).
        Returns:
        A cloned Column Group, with a copied pointer to the old column groups index structure, but reduced dictionary and _columnIndexes correctly aligned with the expected sliced compressed matrix.
      • sliceColumn

        public final AColGroup sliceColumn​(int col)
        Slice out a single column from the column group.
        Parameters:
        col - The column to slice, the column could potentially not be inside the column group
        Returns:
        A new column group that is a single column, if the column requested is not in this column group null is returned.
      • colSum

        public static double[] colSum​(List<AColGroup> groups,
                                      double[] res,
                                      int nRows)
        Compute the column sum of the given list of groups
        Parameters:
        groups - The Groups to sum
        res - The result to put the values into
        nRows - The number of rows in the groups
        Returns:
        The given res list, where the sum of the column groups is added
      • get

        public double get​(int r,
                          int c)
        Get the value at a global row/column position. In general this performs since a binary search of colIndexes is performed for each lookup.
        Parameters:
        r - row
        c - column
        Returns:
        value at the row/column position
      • getIdx

        public abstract double getIdx​(int r,
                                      int colIdx)
        Get the value at a colGroup specific row/column index position.
        Parameters:
        r - row
        colIdx - column index in the _colIndexes.
        Returns:
        value at the row/column index position
      • getNumValues

        public abstract int getNumValues()
        Obtain number of distinct tuples in contained sets of values associated with this column group. If the column group is uncompressed the number or rows is returned.
        Returns:
        the number of distinct sets of values associated with the bitmaps in this column group
      • getCompType

        public abstract AColGroup.CompressionType getCompType()
        Obtain the compression type.
        Returns:
        How the elements of the column group are compressed.
      • decompressToDenseBlock

        public abstract void decompressToDenseBlock​(DenseBlock db,
                                                    int rl,
                                                    int ru,
                                                    int offR,
                                                    int offC)
        Decompress into the DenseBlock. (no NNZ handling)
        Parameters:
        db - Target DenseBlock
        rl - Row to start decompression from
        ru - Row to end decompression at
        offR - Row offset into the target to decompress
        offC - Column offset into the target to decompress
      • decompressToSparseBlock

        public abstract void decompressToSparseBlock​(SparseBlock sb,
                                                     int rl,
                                                     int ru,
                                                     int offR,
                                                     int offC)
        Decompress into the SparseBlock. (no NNZ handling) Note this method is allowing to calls to append since it is assumed that the sparse column indexes are sorted afterwards
        Parameters:
        sb - Target SparseBlock
        rl - Row to start decompression from
        ru - Row to end decompression at
        offR - Row offset into the target to decompress
        offC - Column offset into the target to decompress
      • rightMultByMatrix

        public abstract AColGroup rightMultByMatrix​(MatrixBlock right)
        Right matrix multiplication with this column group. This method can return null, meaning that the output overlapping group would have been empty.
        Parameters:
        right - The MatrixBlock on the right of this matrix multiplication
        Returns:
        The new Column Group or null that is the result of the matrix multiplication.
      • tsmm

        public abstract void tsmm​(MatrixBlock ret,
                                  int nRows)
        Do a transposed self matrix multiplication on the left side t(x) %*% x. but only with this column group. This gives better performance since there is no need to iterate through all the rows of the matrix, but the execution can be limited to its number of distinct values. Note it only calculate the upper triangle
        Parameters:
        ret - The return matrix block [numColumns x numColumns]
        nRows - The number of rows in the column group
      • leftMultByMatrixNoPreAgg

        public abstract void leftMultByMatrixNoPreAgg​(MatrixBlock matrix,
                                                      MatrixBlock result,
                                                      int rl,
                                                      int ru,
                                                      int cl,
                                                      int cu)
        Left multiply with this column group.
        Parameters:
        matrix - The matrix to multiply with on the left
        result - The result to output the values into, always dense for the purpose of the column groups parallelizing
        rl - The row to begin the multiplication from on the lhs matrix
        ru - The row to end the multiplication at on the lhs matrix
        cl - The column to begin the multiplication from on the lhs matrix
        cu - The column to end the multiplication at on the lhs matrix
      • leftMultByAColGroup

        public abstract void leftMultByAColGroup​(AColGroup lhs,
                                                 MatrixBlock result)
        Left side matrix multiplication with a column group that is transposed.
        Parameters:
        lhs - The left hand side Column group to multiply with, the left hand side should be considered transposed.
        result - The result matrix to insert the result of the multiplication into
      • tsmmAColGroup

        public abstract void tsmmAColGroup​(AColGroup other,
                                           MatrixBlock result)
        Matrix multiply with this other column group, but: 1. Only output upper triangle values. 2. Multiply both ways with "this" being on the left and on the right. It should be guaranteed that the input is not the same as the caller of the method. The second step is achievable by treating the initial multiplied matrix, and adding its values to the correct locations in the output.
        Parameters:
        other - The other Column group to multiply with
        result - The result matrix to put the results into
      • scalarOperation

        public abstract AColGroup scalarOperation​(ScalarOperator op)
        Perform the specified scalar operation directly on the compressed column group, without decompressing individual cells if possible.
        Parameters:
        op - operation to perform
        Returns:
        version of this column group with the operation applied
      • binaryRowOpLeft

        public abstract AColGroup binaryRowOpLeft​(BinaryOperator op,
                                                  double[] v,
                                                  boolean isRowSafe)
        Perform a binary row operation.
        Parameters:
        op - The operation to execute
        v - The vector of values to apply, should be same length as dictionary length.
        isRowSafe - True if the binary op is applied to an entire zero row and all results are zero
        Returns:
        A updated column group with the new values.
      • binaryRowOpRight

        public abstract AColGroup binaryRowOpRight​(BinaryOperator op,
                                                   double[] v,
                                                   boolean isRowSafe)
        Perform a binary row operation.
        Parameters:
        op - The operation to execute
        v - The vector of values to apply, should be same length as dictionary length.
        isRowSafe - True if the binary op is applied to an entire zero row and all results are zero
        Returns:
        A updated column group with the new values.
      • unaryAggregateOperations

        public abstract void unaryAggregateOperations​(AggregateUnaryOperator op,
                                                      double[] c,
                                                      int nRows,
                                                      int rl,
                                                      int ru)
        Unary Aggregate operator, since aggregate operators require new object output, the output becomes an uncompressed matrix.
        Parameters:
        op - The operator used
        c - The output matrix block
        nRows - The total number of rows in the Column Group
        rl - The Starting Row to do aggregation from
        ru - The last Row to do aggregation to (not included)
      • getMin

        public abstract double getMin()
        Short hand method for getting minimum value contained in this column group.
        Returns:
        The minimum value contained in this ColumnGroup
      • getMax

        public abstract double getMax()
        Short hand method for getting maximum value contained in this column group.
        Returns:
        The maximum value contained in this ColumnGroup
      • copy

        public abstract AColGroup copy()
        Get a copy of this column group note this is only a shallow copy. Meaning only the object wrapping index structures, column indexes and dictionaries are copied.
        Returns:
        Get a copy of this column group.
      • containsValue

        public abstract boolean containsValue​(double pattern)
        Detect if the column group contains a specific value.
        Parameters:
        pattern - The value to look for.
        Returns:
        boolean saying true if the value is contained.
      • getNumberNonZeros

        public abstract long getNumberNonZeros​(int nRows)
        Get the number of nonZeros contained in this column group.
        Parameters:
        nRows - The number of rows in the column group, this is used for groups that does not contain information about how many rows they have.
        Returns:
        The nnz.
      • replace

        public abstract AColGroup replace​(double pattern,
                                          double replace)
        Make a copy of the column group values, and replace all values that match pattern with replacement value.
        Parameters:
        pattern - The value to look for
        replace - The value to replace the other value with
        Returns:
        A new Column Group, reusing the index structure but with new values.
      • computeColSums

        public abstract void computeColSums​(double[] c,
                                            int nRows)
        Compute the column sum
        Parameters:
        c - The array to add the column sum to.
        nRows - The number of rows in the column group.
      • centralMoment

        public abstract CM_COV_Object centralMoment​(CMOperator op,
                                                    int nRows)
        Central Moment instruction executed on a column group.
        Parameters:
        op - The Operator to use.
        nRows - The number of rows contained in the ColumnGroup.
        Returns:
        A Central Moment object.
      • rexpandCols

        public abstract AColGroup rexpandCols​(int max,
                                              boolean ignore,
                                              boolean cast,
                                              int nRows)
        Expand the column group to multiple columns. (one hot encode the column group)
        Parameters:
        max - The number of columns to expand to and cutoff values at.
        ignore - If zero and negative values should be ignored.
        cast - If the double values contained should be cast to whole numbers.
        nRows - The number of rows in the column group.
        Returns:
        A new column group containing max number of columns.
      • getCost

        public abstract double getCost​(ComputationCostEstimator e,
                                       int nRows)
        Get the computation cost associated with this column group.
        Parameters:
        e - The computation cost estimator
        nRows - the number of rows in the column group
        Returns:
        The cost of this column group