org.apache.sysds.runtime.compress.colgroup

## Class AColGroup

- java.lang.Object
- - org.apache.sysds.runtime.compress.colgroup.AColGroup

- All Implemented Interfaces:
    Serializable
  Direct Known Subclasses:
    ColGroupCompressed, ColGroupUncompressed

      public abstract class AColGroup
      extends Object
      implements Serializable

  Abstract Class that is the lowest class type for the Compression framework. AColGroup store information about a number of columns.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `AColGroup.CompressionType` Public super types of compression ColGroups supported

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract AColGroup` | `binaryRowOp(BinaryOperator op, double[] v, boolean sparseSafe, boolean left)` Perform a binary row operation.
    `abstract boolean` | `containsValue(double pattern)` Detect if the column group contains a specific value.
    `abstract AColGroup` | `copy()` Get a copy of this column group.
    `abstract void` | `countNonZerosPerRow(int[] rnnz, int rl, int ru)` Count the number of non-zeros per row
    `static void` | `decompressColumnToBlockUnSafe(MatrixBlock target, int rl, int ru, List<AColGroup> colGroups)` Decompress part of the col groups into the target matrix block, this decompression maintain the number of non zeros.
    `abstract void` | `decompressToBlockSafe(MatrixBlock target, int rl, int ru, int offT)` Decompress the contents of this column group into the specified full matrix block while managing the number of non zeros.
    `void` | `decompressToBlockUnSafe(MatrixBlock target, int rl, int ru)` Decompress the contents of the columngroup unsafely, meaning that it does not count nonzero values.
    `abstract void` | `decompressToBlockUnSafe(MatrixBlock target, int rl, int ru, int offT)` Decompress the contents of the columngroup unsafely, meaning that it does not count nonzero values.
    `long` | `estimateInMemorySize()` Get the upper bound estimate of in memory allocation for the column group.
    `abstract double` | `get(int r, int c)` Get the value at a global row/column position.
    `int[]` | `getColIndices()` Obtain the offsets of the columns in the matrix block that make up the group
    `abstract AColGroup.CompressionType` | `getCompType()` Obtain the compression type.
    `long` | `getExactSizeOnDisk()` Returns the exact serialized size of column group.
    `abstract double` | `getMax()` Short hand method for getting maximum value contained in this column group.
    `abstract double` | `getMin()` Short hand method for getting minimum value contained in this column group.
    `abstract long` | `getNumberNonZeros()` Get the number of nonZeros contained in this column group.
    `int` | `getNumCols()` Obtain the number of columns in this column group.
    `abstract int` | `getNumRows()` Get number of rows contained in the ColGroup.
    `abstract int` | `getNumValues()` Obtain number of distinct tuples in contained sets of values associated with this column group.
    `abstract double[]` | `getValues()` Get all the values in the colGroup.
    `abstract MatrixBlock` | `getValuesAsBlock()` Returns the ColGroup as a MatrixBlock.
    `abstract boolean` | `isDense()` Is dense, signals that the entire column group is allocated an processed.
    `abstract boolean` | `isLossy()` Is Lossy
    `abstract void` | `leftMultByAColGroup(AColGroup lhs, MatrixBlock result)` Left side matrix multiplication with a column group that is transposed.
    `void` | `leftMultByMatrix(MatrixBlock matrix, MatrixBlock result)` Left multiply with this column group
    `abstract void` | `leftMultByMatrix(MatrixBlock matrix, MatrixBlock result, int rl, int ru)` Left multiply with this column group.
    `void` | `readFields(DataInput in)` Deserialize column group from data input.
    `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.
    `abstract AColGroup` | `rightMultByMatrix(MatrixBlock right)` Right matrix multiplication with this column group.
    `abstract AColGroup` | `scalarOperation(ScalarOperator op)` Perform the specified scalar operation directly on the compressed column group, without decompressing individual cells if possible.
    `void` | `shiftColIndices(int offset)` Shift all column indexes contained by an offset.
    `AColGroup` | `sliceColumn(int col)` Slice out a single column from the column group.
    `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.
    `String` | `toString()`
    `abstract void` | `tsmm(double[] result, int numColumns)` Do a transposed self matrix multiplication on the left side t(x) %*% x.
    `abstract void` | `tsmm(double[] result, int numColumns, int idxStart, int idxEnd)` Do a transposed self matrix multiplication on the left side t(x) %*% x.
    `abstract void` | `unaryAggregateOperations(AggregateUnaryOperator op, double[] c)` Unary Aggregate operator, since aggregate operators require new object output, the output becomes an uncompressed matrix.
    `abstract void` | `unaryAggregateOperations(AggregateUnaryOperator op, double[] c, int rl, int ru)` Unary Aggregate operator, since aggregate operators require new object output, the output becomes an uncompressed matrix.
    `void` | `write(DataOutput out)` Serializes column group to data output.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### getColIndices

          public 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

    - #### getNumRows

          public abstract int getNumRows()

      Get number of rows contained in the ColGroup.
      Returns:
        An integer that is the number of rows.

    - #### 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

    - #### getNumCols

          public int getNumCols()

      Obtain the number of columns in this column group.
      Returns:
        number of columns in this column group

    - #### getCompType

          public abstract AColGroup.CompressionType getCompType()

      Obtain the compression type.
      Returns:
        How the elements of the column group are compressed.

    - #### shiftColIndices

          public final void shiftColIndices(int offset)

      Shift all column indexes contained by an offset. This is used for rbind to combine compressed matrices.
      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.

    - #### decompressToBlockSafe

          public abstract void decompressToBlockSafe(MatrixBlock target,
                                                     int rl,
                                                     int ru,
                                                     int offT)

      Decompress the contents of this column group into the specified full matrix block while managing the number of non zeros.
      Parameters:
        `target` - a matrix block where the columns covered by this column group have not yet been filled in.
        `rl` - row lower
        `ru` - row upper
        `offT` - Offset into target to assign from

    - #### decompressToBlockUnSafe

          public void decompressToBlockUnSafe(MatrixBlock target,
                                              int rl,
                                              int ru)

      Decompress the contents of the columngroup unsafely, meaning that it does not count nonzero values.
      Parameters:
        `target` - a matrix block where the columns covered by this column group have not yet been filled in.
        `rl` - row lower
        `ru` - row upper

    - #### decompressToBlockUnSafe

          public abstract void decompressToBlockUnSafe(MatrixBlock target,
                                                       int rl,
                                                       int ru,
                                                       int offT)

      Decompress the contents of the columngroup unsafely, meaning that it does not count nonzero values.
      Parameters:
        `target` - a matrix block where the columns covered by this column group have not yet been filled in.
        `rl` - row lower
        `ru` - row upper
        `offT` - Offset into target to assign from

    - #### decompressColumnToBlockUnSafe

          public static final void decompressColumnToBlockUnSafe(MatrixBlock target,
                                                                 int rl,
                                                                 int ru,
                                                                 List<AColGroup> colGroups)

      Decompress part of the col groups into the target matrix block, this decompression maintain the number of non zeros.
      Parameters:
        `target` - The Target matrix block to decompress into
        `rl` - The row to start the decompression from
        `ru` - The row to end the decompression at
        `colGroups` - The list of column groups to decompress.

    - #### 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

    - #### get

          public abstract double get(int r,
                                     int c)

      Get the value at a global row/column position.
      Parameters:
        `r` - row
        `c` - column
      Returns:
        value at the row/column position

    - #### getValues

          public abstract double[] getValues()

      Get all the values in the colGroup. Note that this is only the stored values not the way they are stored. Making the output a list of values used in that colGroup not the actual full column.
      Returns:
        a double list of values.

    - #### getValuesAsBlock

          public abstract MatrixBlock getValuesAsBlock()

      Returns the ColGroup as a MatrixBlock. Used as a fall back solution in case a operation is not supported. Use in connection to getIfCountsType to get if the values are repeated.
      Returns:
        Matrix Block of the contained Values. Possibly contained in groups.

    - #### rightMultByMatrix

          public abstract AColGroup rightMultByMatrix(MatrixBlock right)

      Right matrix multiplication with this column group.
      Parameters:
        `right` - The matrixBlock on the right of this matrix multiplication
      Returns:
        The new Column Group that is the result of the matrix multiplication.

    - #### tsmm

          public abstract void tsmm(double[] result,
                                    int numColumns)

      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:
        `result` - A row major dense allocation of a matrixBlock, of size [numColumns x numColumns]
        `numColumns` - The number of columns in the row major result matrix.

    - #### tsmm

          public abstract void tsmm(double[] result,
                                    int numColumns,
                                    int idxStart,
                                    int idxEnd)

      Do a transposed self matrix multiplication on the left side t(x) %*% x. but only with this column group, and only on a subset of the columns contained in this columnGroup. 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:
        `result` - A row major dense allocation of a matrixBlock, of size [numColumns x numColumns]
        `numColumns` - The number of columns in the row major result matrix.
        `idxStart` - The starting index in the _colIndexes.
        `idxEnd` - The ending index in the _colIndexes.

    - #### leftMultByMatrix

          public final void leftMultByMatrix(MatrixBlock matrix,
                                             MatrixBlock result)

      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

    - #### leftMultByMatrix

          public abstract void leftMultByMatrix(MatrixBlock matrix,
                                                MatrixBlock result,
                                                int rl,
                                                int ru)

      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

    - #### 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

    - #### 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

    - #### binaryRowOp

          public abstract AColGroup binaryRowOp(BinaryOperator op,
                                                double[] v,
                                                boolean sparseSafe,
                                                boolean left)

      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.
        `sparseSafe` - True if the operation return 0 on all instances of values in v -- op(v[?], 0)
        `left` - Specifies if the operation is executed on the left or right side of the values contained.
      Returns:
        A updated column group with the new values.

    - #### unaryAggregateOperations

          public abstract void unaryAggregateOperations(AggregateUnaryOperator op,
                                                        double[] c)

      Unary Aggregate operator, since aggregate operators require new object output, the output becomes an uncompressed matrix.
      Parameters:
        `op` - The operator used
        `c` - Rhe output matrix block.

    - #### unaryAggregateOperations

          public abstract void unaryAggregateOperations(AggregateUnaryOperator op,
                                                        double[] c,
                                                        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.
        `rl` - The Starting Row to do aggregation from
        `ru` - The last Row to do aggregation to (not included)

    - #### countNonZerosPerRow

          public abstract void countNonZerosPerRow(int[] rnnz,
                                                   int rl,
                                                   int ru)

      Count the number of non-zeros per row
      Parameters:
        `rnnz` - non-zeros per row
        `rl` - row lower bound, inclusive
        `ru` - row upper bound, exclusive

    - #### isLossy

          public abstract boolean isLossy()

      Is Lossy
      Returns:
        returns if the ColGroup is compressed in a lossy manner.

    - #### isDense

          public abstract boolean isDense()

      Is dense, signals that the entire column group is allocated an processed. This is useful in Row wise min and max for instance, to avoid having to scan through each row to look for empty rows. an example where it is true is DDC, Const and Uncompressed. examples where false is OLE and RLE.
      Returns:
        returns if the colGroup is allocated in a dense fashion.

    - #### 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.

    - #### 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. Depending on which column group is copied it is a deep or shallow copy. If the primitives for the underlying column groups is Immutable then only shallow copies is performed.
      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()

      Get the number of nonZeros contained in this column group.
      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.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

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