Package org.apache.sysds.runtime.compress.colgroup

## Class ColGroupSDCSingle

- java.lang.Object
- - org.apache.sysds.runtime.compress.colgroup.AColGroup
  - - org.apache.sysds.runtime.compress.colgroup.AColGroupCompressed
    - - org.apache.sysds.runtime.compress.colgroup.ADictBasedColGroup
      - - org.apache.sysds.runtime.compress.colgroup.AColGroupValue
        - - org.apache.sysds.runtime.compress.colgroup.AMorphingMMColGroup
          - - org.apache.sysds.runtime.compress.colgroup.ASDC
            - - org.apache.sysds.runtime.compress.colgroup.ColGroupSDCSingle

All Implemented Interfaces:
  `Serializable`, `AOffsetsGroup`, `IContainADictionary`, `IContainDefaultTuple`

    public class ColGroupSDCSingle
    extends ASDC

Column group that sparsely encodes the dictionary values. The idea is that all values is encoded with indexes except the most common one. the most common one can be inferred by not being included in the indexes. If the values are very sparse then the most common one is zero. This column group is handy in cases where sparse unsafe operations is executed on very sparse columns. Then the zeros would be materialized in the group without any overhead.

See Also:
  Serialized Form

### Nested Class Summary

### Nested classes/interfaces inherited from class org.apache.sysds.runtime.compress.colgroup.AColGroup

`AColGroup.CompressionType`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`AColGroup` `append​(AColGroup g)` Append the other column group to this column group.
`AColGroup` `appendNInternal​(AColGroup[] g, int blen, int rlen)`
`AColGroup` `binaryRowOpLeft​(BinaryOperator op, double[] v, boolean isRowSafe)` Perform a binary row operation.
`AColGroup` `binaryRowOpRight​(BinaryOperator op, double[] v, boolean isRowSafe)` Perform a binary row operation.
`CM_COV_Object` `centralMoment​(CMOperator op, int nRows)` Central Moment instruction executed on a column group.
`AColGroupCompressed` `combineWithSameIndex​(int nRow, int nCol, List<AColGroup> right)` C bind the list of column groups with this column group.
`AColGroupCompressed` `combineWithSameIndex​(int nRow, int nCol, AColGroup right)` C bind the given column group to this.
`void` `computeColSums​(double[] c, int nRows)` Compute the column sum
`boolean` `containsValue​(double pattern)` Detect if the column group contains a specific value.
`static AColGroup` `create​(IColIndex colIndexes, int numRows, IDictionary dict, double[] defaultTuple, AOffset offsets, int[] cachedCounts)`
`long` `estimateInMemorySize()` Get the upper bound estimate of in memory allocation for the column group.
`AColGroup` `extractCommon​(double[] constV)` extract common value from group and return non morphing group
`org.apache.sysds.runtime.compress.colgroup.AColGroup.ColGroupType` `getColGroupType()`
`double[]` `getCommon()` Get common vector, note this should not materialize anything but simply point to things that are already allocated.
`AColGroup.CompressionType` `getCompType()` Obtain the compression type.
`double` `getCost​(ComputationCostEstimator e, int nRows)` Get the computation cost associated with this column group.
`int[]` `getCounts​(int[] counts)`
`double[]` `getDefaultTuple()`
`IEncode` `getEncoding()` Get encoding of this column group.
`long` `getExactSizeOnDisk()` Returns the exact serialized size of column group.
`double` `getIdx​(int r, int colIdx)` Get the value at a colGroup specific row/column index position.
`long` `getNumberNonZeros​(int nRows)` Get the number of nonZeros contained in this column group.
`int` `getNumberOffsets()`
`static ColGroupSDCSingle` `read​(DataInput in, int nRows)`
`AColGroup` `recompress()` Recompress this column group into a new column group.
`AColGroup` `replace​(double pattern, double replace)` Make a copy of the column group values, and replace all values that match pattern with replacement value.
`AColGroup` `rexpandCols​(int max, boolean ignore, boolean cast, int nRows)` Expand the column group to multiple columns.
`boolean` `sameIndexStructure​(AColGroupCompressed that)`
`AColGroup` `scalarOperation​(ScalarOperator op)` Perform the specified scalar operation directly on the compressed column group, without decompressing individual cells if possible.
`AColGroup` `sliceRows​(int rl, int ru)` Slice range of rows out of the column group and return a new column group only containing the row segment.
`AColGroup[]` `splitReshape​(int multiplier, int nRow, int nColOrg)` This method returns a list of column groups that are naive splits of this column group as if it is reshaped.
`String` `toString()`
`AColGroup` `unaryOperation​(UnaryOperator op)` Perform unary operation on the column group and return a new column group
`void` `write​(DataOutput out)`

### Methods inherited from class org.apache.sysds.runtime.compress.colgroup.ASDC

`getCompressionInfo, getCompressionScheme, getNumRows, getOffsets, morph`

### Methods inherited from class org.apache.sysds.runtime.compress.colgroup.AMorphingMMColGroup

`decompressToSparseBlockTransposed, leftMultByAColGroup, leftMultByMatrixNoPreAgg, tsmmAColGroup`

### Methods inherited from class org.apache.sysds.runtime.compress.colgroup.AColGroupValue

`clear, getCounts, getNumValues`

### Methods inherited from class org.apache.sysds.runtime.compress.colgroup.ADictBasedColGroup

`copyAndSet, copyAndSet, decompressToDenseBlock, decompressToDenseBlockTransposed, decompressToSparseBlock, getDictionary, getSparsity, reduceCols, rightMultByMatrix`

### Methods inherited from class org.apache.sysds.runtime.compress.colgroup.AColGroupCompressed

`getMax, getMin, getSum, isEmpty, preAggRows, sameIndexStructure, tsmm, unaryAggregateOperations, unaryAggregateOperations`

### Methods inherited from class org.apache.sysds.runtime.compress.colgroup.AColGroup

`addVector, appendN, colSum, combine, decompressToDenseBlock, decompressToSparseBlock, get, getColIndices, getNumCols, rightDecompressingMult, rightMultByMatrix, selectionMultiply, shiftColIndices, sliceColumn, sliceColumns, sortColumnIndexes, splitReshapePushDown`

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

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

### Method Detail

#### create

    public static AColGroup create​(IColIndex colIndexes,
                                   int numRows,
                                   IDictionary dict,
                                   double[] defaultTuple,
                                   AOffset offsets,
                                   int[] cachedCounts)

#### getCompType

    public AColGroup.CompressionType getCompType()

Description copied from class: `AColGroup`
Obtain the compression type.

Specified by:
  `getCompType` in class `AColGroup`
Returns:
  How the elements of the column group are compressed.

#### getColGroupType

    public org.apache.sysds.runtime.compress.colgroup.AColGroup.ColGroupType getColGroupType()

#### getDefaultTuple

    public double[] getDefaultTuple()

#### getIdx

    public double getIdx​(int r,
                         int colIdx)

Description copied from class: `AColGroup`
Get the value at a colGroup specific row/column index position.

Specified by:
  `getIdx` in class `AColGroup`
Parameters:
  `r` - row
  `colIdx` - column index in the _colIndexes.
Returns:
  value at the row/column index position

#### computeColSums

    public void computeColSums​(double[] c,
                               int nRows)

Description copied from class: `AColGroup`
Compute the column sum

Overrides:
  `computeColSums` in class `AColGroupValue`
Parameters:
  `c` - The array to add the column sum to.
  `nRows` - The number of rows in the column group.

#### getCounts

    public int[] getCounts​(int[] counts)

#### estimateInMemorySize

    public long estimateInMemorySize()

Description copied from class: `AColGroup`
Get the upper bound estimate of in memory allocation for the column group.

Overrides:
  `estimateInMemorySize` in class `AColGroupValue`
Returns:
  an upper bound on the number of bytes used to store this ColGroup in memory.

#### scalarOperation

    public AColGroup scalarOperation​(ScalarOperator op)

Description copied from class: `AColGroup`
Perform the specified scalar operation directly on the compressed column group, without decompressing individual cells if possible.

Specified by:
  `scalarOperation` in class `AColGroup`
Parameters:
  `op` - operation to perform
Returns:
  version of this column group with the operation applied

#### unaryOperation

    public AColGroup unaryOperation​(UnaryOperator op)

Description copied from class: `AColGroup`
Perform unary operation on the column group and return a new column group

Specified by:
  `unaryOperation` in class `AColGroup`
Parameters:
  `op` - The operation to perform
Returns:
  The new column group

#### binaryRowOpLeft

    public AColGroup binaryRowOpLeft​(BinaryOperator op,
                                     double[] v,
                                     boolean isRowSafe)

Description copied from class: `AColGroup`
Perform a binary row operation.

Specified by:
  `binaryRowOpLeft` in class `AColGroup`
Parameters:
  `op` - The operation to execute
  `v` - The vector of values to apply the values contained should be at least the length of the highest value in the column index
  `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 AColGroup binaryRowOpRight​(BinaryOperator op,
                                      double[] v,
                                      boolean isRowSafe)

Description copied from class: `AColGroup`
Perform a binary row operation.

Specified by:
  `binaryRowOpRight` in class `AColGroup`
Parameters:
  `op` - The operation to execute
  `v` - The vector of values to apply the values contained should be at least the length of the highest value in the column index
  `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.

#### write

    public void write​(DataOutput out)
               throws IOException

Overrides:
  `write` in class `ADictBasedColGroup`
Throws:
  `IOException`

#### read

    public static ColGroupSDCSingle read​(DataInput in,
                                         int nRows)
                                  throws IOException

Throws:
  `IOException`

#### getExactSizeOnDisk

    public long getExactSizeOnDisk()

Description copied from class: `AColGroup`
Returns the exact serialized size of column group. This can be used for example for buffer preallocation.

Overrides:
  `getExactSizeOnDisk` in class `ADictBasedColGroup`
Returns:
  exact serialized size for column group

#### replace

    public AColGroup replace​(double pattern,
                             double replace)

Description copied from class: `AColGroup`
Make a copy of the column group values, and replace all values that match pattern with replacement value.

Overrides:
  `replace` in class `AColGroupValue`
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.

#### extractCommon

    public AColGroup extractCommon​(double[] constV)

Description copied from class: `AMorphingMMColGroup`
extract common value from group and return non morphing group

Specified by:
  `extractCommon` in class `AMorphingMMColGroup`
Parameters:
  `constV` - a vector to contain all values, note length = nCols in total matrix.
Returns:
  A non morphing column group with decompression instructions.

#### getNumberNonZeros

    public long getNumberNonZeros​(int nRows)

Description copied from class: `AColGroup`
Get the number of nonZeros contained in this column group.

Overrides:
  `getNumberNonZeros` in class `AColGroupValue`
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.

#### centralMoment

    public CM_COV_Object centralMoment​(CMOperator op,
                                       int nRows)

Description copied from class: `AColGroup`
Central Moment instruction executed on a column group.

Overrides:
  `centralMoment` in class `AColGroupValue`
Parameters:
  `op` - The Operator to use.
  `nRows` - The number of rows contained in the ColumnGroup.
Returns:
  A Central Moment object.

#### rexpandCols

    public AColGroup rexpandCols​(int max,
                                 boolean ignore,
                                 boolean cast,
                                 int nRows)

Description copied from class: `AColGroup`
Expand the column group to multiple columns. (one hot encode the column group)

Overrides:
  `rexpandCols` in class `AColGroupValue`
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 double getCost​(ComputationCostEstimator e,
                          int nRows)

Description copied from class: `AColGroup`
Get the computation cost associated with this column group.

Specified by:
  `getCost` in class `AColGroup`
Parameters:
  `e` - The computation cost estimator
  `nRows` - the number of rows in the column group
Returns:
  The cost of this column group

#### containsValue

    public boolean containsValue​(double pattern)

Description copied from class: `AColGroup`
Detect if the column group contains a specific value.

Specified by:
  `containsValue` in class `AColGroup`
Parameters:
  `pattern` - The value to look for.
Returns:
  boolean saying true if the value is contained.

#### getCommon

    public double[] getCommon()

Description copied from class: `AMorphingMMColGroup`
Get common vector, note this should not materialize anything but simply point to things that are already allocated.

Specified by:
  `getCommon` in class `AMorphingMMColGroup`
Returns:
  the common double vector

#### sliceRows

    public AColGroup sliceRows​(int rl,
                               int ru)

Description copied from class: `AColGroup`
Slice range of rows out of the column group and return a new column group only containing the row segment. Note that this slice should maintain pointers back to the original dictionaries and only modify index structures.

Specified by:
  `sliceRows` in class `AColGroup`
Parameters:
  `rl` - The row to start at
  `ru` - The row to end at (not included)
Returns:
  A new column group containing the specified row range.

#### append

    public AColGroup append​(AColGroup g)

Description copied from class: `AColGroup`
Append the other column group to this column group. This method tries to combine them to return a new column group containing both. In some cases it is possible in reasonable time, in others it is not. The result is first this column group followed by the other column group in higher row values. If it is not possible or very inefficient null is returned.

Specified by:
  `append` in class `AColGroup`
Parameters:
  `g` - The other column group
Returns:
  A combined column group or null

#### appendNInternal

    public AColGroup appendNInternal​(AColGroup[] g,
                                     int blen,
                                     int rlen)

#### recompress

    public AColGroup recompress()

Description copied from class: `AColGroup`
Recompress this column group into a new column group.

Specified by:
  `recompress` in class `AColGroup`
Returns:
  A new or the same column group depending on optimization goal.

#### getEncoding

    public IEncode getEncoding()

Description copied from class: `AColGroup`
Get encoding of this column group.

Overrides:
  `getEncoding` in class `AColGroup`
Returns:
  The encoding of the index structure.

#### getNumberOffsets

    public int getNumberOffsets()

Specified by:
  `getNumberOffsets` in class `ASDC`

#### sameIndexStructure

    public boolean sameIndexStructure​(AColGroupCompressed that)

Specified by:
  `sameIndexStructure` in class `AColGroupCompressed`

#### combineWithSameIndex

    public AColGroupCompressed combineWithSameIndex​(int nRow,
                                                    int nCol,
                                                    AColGroup right)

Description copied from class: `AColGroup`
C bind the given column group to this.

Overrides:
  `combineWithSameIndex` in class `AColGroup`
Parameters:
  `nRow` - The number of rows contained in the right and this column group.
  `nCol` - The number of columns in this.
  `right` - The column group to c-bind.
Returns:
  a new combined column groups.

#### combineWithSameIndex

    public AColGroupCompressed combineWithSameIndex​(int nRow,
                                                    int nCol,
                                                    List<AColGroup> right)

Description copied from class: `AColGroup`
C bind the list of column groups with this column group. the list of elements provided in the index of each list is guaranteed to have the same index structures

Overrides:
  `combineWithSameIndex` in class `AColGroup`
Parameters:
  `nRow` - The number of rows contained in all right and this column group.
  `nCol` - The number of columns to shift the right hand side column groups over when combining, this should only effect the column indexes
  `right` - The right hand side column groups to combine. NOTE only the index offset of the second nested list should be used. The reason for providing this nested list is to avoid redundant allocations in calling methods.
Returns:
  A combined compressed column group of the same type as this!.

#### splitReshape

    public AColGroup[] splitReshape​(int multiplier,
                                    int nRow,
                                    int nColOrg)

Description copied from class: `AColGroup`
This method returns a list of column groups that are naive splits of this column group as if it is reshaped. This means the column groups rows are split into x number of other column groups where x is the multiplier. The indexes are assigned round robbin to each of the output groups, meaning the first index is assigned. If for instance the 4. column group is split by a 2 multiplier and there was 5 columns in total originally. The output becomes 2 column groups at column index 4 and one at 9. If possible the split column groups should reuse pointers back to the original dictionaries!

Specified by:
  `splitReshape` in class `AColGroup`
Parameters:
  `multiplier` - The number of column groups to split into
  `nRow` - The number of rows in this column group in case the underlying column group does not know
  `nColOrg` - The number of overall columns in the host CompressedMatrixBlock.
Returns:
  a list of split column groups

#### toString

    public String toString()

Overrides:
  `toString` in class `AColGroupValue`