Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYSTEMDS-2831] CLA DeltaDDC Column Group
This commit adds a new column group type named DeltaDDC, with support for a few operations. While merging I added a interface for future readers for delta encoding, a future tasks is to enable analysis of delta encoding. DIA project WS2021/22. Closes #1518
- Loading branch information
1 parent
7f67226
commit 31f2653
Showing
17 changed files
with
557 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/main/java/org/apache/sysds/runtime/compress/colgroup/ColGroupDeltaDDC.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.sysds.runtime.compress.colgroup; | ||
|
||
import org.apache.commons.lang.NotImplementedException; | ||
import org.apache.sysds.runtime.compress.colgroup.dictionary.ADictionary; | ||
import org.apache.sysds.runtime.compress.colgroup.mapping.AMapToData; | ||
import org.apache.sysds.runtime.data.DenseBlock; | ||
import org.apache.sysds.runtime.data.SparseBlock; | ||
import org.apache.sysds.runtime.matrix.operators.ScalarOperator; | ||
|
||
/** | ||
* Class to encapsulate information about a column group that is first delta encoded then encoded with dense dictionary | ||
* encoding (DeltaDDC). | ||
*/ | ||
public class ColGroupDeltaDDC extends ColGroupDDC { | ||
|
||
/** | ||
* Constructor for serialization | ||
* | ||
* @param numRows number of rows | ||
*/ | ||
protected ColGroupDeltaDDC(int numRows) { | ||
super(numRows); | ||
} | ||
|
||
protected ColGroupDeltaDDC(int[] colIndices, int numRows, ADictionary dict, AMapToData data, int[] cachedCounts) { | ||
super(colIndices, numRows, dict, data, cachedCounts); | ||
_zeros = false; | ||
_data = data; | ||
} | ||
|
||
public CompressionType getCompType() { | ||
return CompressionType.DeltaDDC; | ||
} | ||
|
||
@Override | ||
protected void decompressToDenseBlockDenseDictionary(DenseBlock db, int rl, int ru, int offR, int offC, | ||
double[] values) { | ||
final int nCol = _colIndexes.length; | ||
for(int i = rl, offT = rl + offR; i < ru; i++, offT++) { | ||
final double[] c = db.values(offT); | ||
final int off = db.pos(offT) + offC; | ||
final int rowIndex = _data.getIndex(i) * nCol; | ||
final int prevOff = (off == 0) ? off : off - nCol; | ||
for(int j = 0; j < nCol; j++) { | ||
// Here we use the values in the previous row to compute current values along with the delta | ||
double newValue = c[prevOff + j] + values[rowIndex + j]; | ||
c[off + _colIndexes[j]] += newValue; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void decompressToSparseBlockDenseDictionary(SparseBlock ret, int rl, int ru, int offR, int offC, | ||
double[] values) { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
@Override | ||
public AColGroup scalarOperation(ScalarOperator op) { | ||
return new ColGroupDeltaDDC(_colIndexes, _numRows, _dict.applyScalarOp(op), _data, getCachedCounts()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/org/apache/sysds/runtime/compress/colgroup/dictionary/DeltaDictionary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.apache.sysds.runtime.compress.colgroup.dictionary; | ||
|
||
import org.apache.commons.lang.NotImplementedException; | ||
import org.apache.sysds.runtime.functionobjects.Divide; | ||
import org.apache.sysds.runtime.functionobjects.Multiply; | ||
import org.apache.sysds.runtime.functionobjects.Plus; | ||
import org.apache.sysds.runtime.functionobjects.Minus; | ||
import org.apache.sysds.runtime.matrix.operators.ScalarOperator; | ||
|
||
/** | ||
* This dictionary class is a specialization for the DeltaDDCColgroup. Here the adjustments for operations for the delta | ||
* encoded values are implemented. | ||
*/ | ||
public class DeltaDictionary extends Dictionary { | ||
|
||
private final int _numCols; | ||
|
||
public DeltaDictionary(double[] values, int numCols) { | ||
super(values); | ||
_numCols = numCols; | ||
} | ||
|
||
@Override | ||
public DeltaDictionary applyScalarOp(ScalarOperator op) { | ||
final double[] retV = new double[_values.length]; | ||
if (op.fn instanceof Multiply || op.fn instanceof Divide) { | ||
for(int i = 0; i < _values.length; i++) | ||
retV[i] = op.executeScalar(_values[i]); | ||
} | ||
else if (op.fn instanceof Plus || op.fn instanceof Minus) { | ||
// With Plus and Minus only the first row needs to be updated when delta encoded | ||
for(int i = 0; i < _values.length; i++) { | ||
if (i < _numCols) | ||
retV[i] = op.executeScalar(_values[i]); | ||
else | ||
retV[i] = _values[i]; | ||
} | ||
} else | ||
throw new NotImplementedException(); | ||
|
||
return new DeltaDictionary(retV, _numCols); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.