use of org.apache.sysml.runtime.compress.utils.IntArrayList in project incubator-systemml by apache.
the class BitmapEncoder method extractBitmap.
private static UncompressedBitmap extractBitmap(int colIndex, MatrixBlock rawblock, boolean skipZeros) {
// probe map for distinct items (for value or value groups)
DoubleIntListHashMap distinctVals = new DoubleIntListHashMap();
// scan rows and probe/build distinct items
final int m = CompressedMatrixBlock.TRANSPOSE_INPUT ? rawblock.getNumColumns() : rawblock.getNumRows();
if (// SPARSE
rawblock.isInSparseFormat() && CompressedMatrixBlock.TRANSPOSE_INPUT) {
SparseBlock a = rawblock.getSparseBlock();
if (a != null && !a.isEmpty(colIndex)) {
int apos = a.pos(colIndex);
int alen = a.size(colIndex);
int[] aix = a.indexes(colIndex);
double[] avals = a.values(colIndex);
// for 0 values
IntArrayList lstPtr0 = new IntArrayList();
int last = -1;
// iterate over non-zero entries but fill in zeros
for (int j = apos; j < apos + alen; j++) {
// fill in zero values
if (!skipZeros)
for (int k = last + 1; k < aix[j]; k++) lstPtr0.appendValue(k);
// handle non-zero value
IntArrayList lstPtr = distinctVals.get(avals[j]);
if (lstPtr == null) {
lstPtr = new IntArrayList();
distinctVals.appendValue(avals[j], lstPtr);
}
lstPtr.appendValue(aix[j]);
last = aix[j];
}
// fill in remaining zero values
if (!skipZeros) {
for (int k = last + 1; k < m; k++) lstPtr0.appendValue(k);
if (lstPtr0.size() > 0)
distinctVals.appendValue(0, lstPtr0);
}
} else if (!skipZeros) {
// full 0 column
IntArrayList lstPtr = new IntArrayList();
for (int i = 0; i < m; i++) lstPtr.appendValue(i);
distinctVals.appendValue(0, lstPtr);
}
} else // GENERAL CASE
{
for (int i = 0; i < m; i++) {
double val = CompressedMatrixBlock.TRANSPOSE_INPUT ? rawblock.quickGetValue(colIndex, i) : rawblock.quickGetValue(i, colIndex);
if (val != 0 || !skipZeros) {
IntArrayList lstPtr = distinctVals.get(val);
if (lstPtr == null) {
lstPtr = new IntArrayList();
distinctVals.appendValue(val, lstPtr);
}
lstPtr.appendValue(i);
}
}
}
return new UncompressedBitmap(distinctVals);
}
use of org.apache.sysml.runtime.compress.utils.IntArrayList in project incubator-systemml by apache.
the class RowClassMeet method execute.
@Override
public void execute() {
try {
MatrixBlock A = ((Matrix) getFunctionInput(0)).getMatrixObject().acquireRead();
MatrixBlock B = ((Matrix) getFunctionInput(1)).getMatrixObject().acquireRead();
int nr = Math.max(A.getNumRows(), B.getNumRows());
int nc = Math.max(A.getNumColumns(), B.getNumColumns());
MatrixBlock C = new MatrixBlock(nr, nc, false).allocateBlock();
MatrixBlock N = new MatrixBlock(nr, nc, false).allocateBlock();
double[] dC = C.getDenseBlockValues();
double[] dN = N.getDenseBlockValues();
// wrap both A and B into side inputs for efficient sparse access
SideInput sB = CodegenUtils.createSideInput(B);
boolean mv = (B.getNumRows() == 1);
int numCols = Math.min(A.getNumColumns(), B.getNumColumns());
HashMap<ClassLabel, IntArrayList> classLabelMapping = new HashMap<>();
for (int i = 0, ai = 0; i < A.getNumRows(); i++, ai += A.getNumColumns()) {
classLabelMapping.clear();
sB.reset();
if (A.isInSparseFormat()) {
if (A.getSparseBlock() == null || A.getSparseBlock().isEmpty(i))
continue;
int alen = A.getSparseBlock().size(i);
int apos = A.getSparseBlock().pos(i);
int[] aix = A.getSparseBlock().indexes(i);
double[] avals = A.getSparseBlock().values(i);
for (int k = apos; k < apos + alen; k++) {
if (aix[k] >= numCols)
break;
int bval = (int) sB.getValue(mv ? 0 : i, aix[k]);
if (bval != 0) {
ClassLabel key = new ClassLabel((int) avals[k], bval);
if (!classLabelMapping.containsKey(key))
classLabelMapping.put(key, new IntArrayList());
classLabelMapping.get(key).appendValue(aix[k]);
}
}
} else {
double[] denseBlk = A.getDenseBlockValues();
if (denseBlk == null)
break;
for (int j = 0; j < numCols; j++) {
int aVal = (int) denseBlk[ai + j];
int bVal = (int) sB.getValue(mv ? 0 : i, j);
if (aVal != 0 && bVal != 0) {
ClassLabel key = new ClassLabel(aVal, bVal);
if (!classLabelMapping.containsKey(key))
classLabelMapping.put(key, new IntArrayList());
classLabelMapping.get(key).appendValue(j);
}
}
}
int labelID = 1;
for (Entry<ClassLabel, IntArrayList> entry : classLabelMapping.entrySet()) {
int nVal = entry.getValue().size();
int[] list = entry.getValue().extractValues();
for (int k = 0, off = i * nc; k < nVal; k++) {
dN[off + list[k]] = nVal;
dC[off + list[k]] = labelID;
}
labelID++;
}
}
((Matrix) getFunctionInput(0)).getMatrixObject().release();
((Matrix) getFunctionInput(1)).getMatrixObject().release();
// prepare outputs
C.recomputeNonZeros();
C.examSparsity();
CMat = new Matrix(createOutputFilePathAndName("TMP"), nr, nc, ValueType.Double);
CMat.setMatrixDoubleArray(C, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo);
N.recomputeNonZeros();
N.examSparsity();
NMat = new Matrix(createOutputFilePathAndName("TMP"), nr, nc, ValueType.Double);
NMat.setMatrixDoubleArray(N, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo);
} catch (DMLRuntimeException | IOException e) {
throw new RuntimeException("Error while executing RowClassMeet", e);
}
}
use of org.apache.sysml.runtime.compress.utils.IntArrayList in project incubator-systemml by apache.
the class BitmapEncoder method extractBitmap.
private static UncompressedBitmap extractBitmap(int[] colIndices, MatrixBlock rawblock, ReaderColumnSelection rowReader) {
// probe map for distinct items (for value or value groups)
DblArrayIntListHashMap distinctVals = new DblArrayIntListHashMap();
// scan rows and probe/build distinct items
DblArray cellVals = null;
while ((cellVals = rowReader.nextRow()) != null) {
IntArrayList lstPtr = distinctVals.get(cellVals);
if (lstPtr == null) {
// create new objects only on demand
lstPtr = new IntArrayList();
distinctVals.appendValue(new DblArray(cellVals), lstPtr);
}
lstPtr.appendValue(rowReader.getCurrentRowIndex());
}
return new UncompressedBitmap(distinctVals, colIndices.length);
}
use of org.apache.sysml.runtime.compress.utils.IntArrayList in project incubator-systemml by apache.
the class BitmapEncoder method extractBitmap.
private static UncompressedBitmap extractBitmap(int colIndex, MatrixBlock rawblock, int[] sampleIndexes, boolean skipZeros) {
// note: general case only because anyway binary search for small samples
// probe map for distinct items (for value or value groups)
DoubleIntListHashMap distinctVals = new DoubleIntListHashMap();
// scan rows and probe/build distinct items
final int m = sampleIndexes.length;
for (int i = 0; i < m; i++) {
int rowIndex = sampleIndexes[i];
double val = CompressedMatrixBlock.TRANSPOSE_INPUT ? rawblock.quickGetValue(colIndex, rowIndex) : rawblock.quickGetValue(rowIndex, colIndex);
if (val != 0 || !skipZeros) {
IntArrayList lstPtr = distinctVals.get(val);
if (lstPtr == null) {
lstPtr = new IntArrayList();
distinctVals.appendValue(val, lstPtr);
}
lstPtr.appendValue(i);
}
}
return new UncompressedBitmap(distinctVals);
}
use of org.apache.sysml.runtime.compress.utils.IntArrayList in project systemml by apache.
the class RowClassMeet method execute.
@Override
public void execute() {
try {
MatrixBlock A = ((Matrix) getFunctionInput(0)).getMatrixObject().acquireRead();
MatrixBlock B = ((Matrix) getFunctionInput(1)).getMatrixObject().acquireRead();
int nr = Math.max(A.getNumRows(), B.getNumRows());
int nc = Math.max(A.getNumColumns(), B.getNumColumns());
MatrixBlock C = new MatrixBlock(nr, nc, false).allocateBlock();
MatrixBlock N = new MatrixBlock(nr, nc, false).allocateBlock();
double[] dC = C.getDenseBlockValues();
double[] dN = N.getDenseBlockValues();
// wrap both A and B into side inputs for efficient sparse access
SideInput sB = CodegenUtils.createSideInput(B);
boolean mv = (B.getNumRows() == 1);
int numCols = Math.min(A.getNumColumns(), B.getNumColumns());
HashMap<ClassLabel, IntArrayList> classLabelMapping = new HashMap<>();
for (int i = 0, ai = 0; i < A.getNumRows(); i++, ai += A.getNumColumns()) {
classLabelMapping.clear();
sB.reset();
if (A.isInSparseFormat()) {
if (A.getSparseBlock() == null || A.getSparseBlock().isEmpty(i))
continue;
int alen = A.getSparseBlock().size(i);
int apos = A.getSparseBlock().pos(i);
int[] aix = A.getSparseBlock().indexes(i);
double[] avals = A.getSparseBlock().values(i);
for (int k = apos; k < apos + alen; k++) {
if (aix[k] >= numCols)
break;
int bval = (int) sB.getValue(mv ? 0 : i, aix[k]);
if (bval != 0) {
ClassLabel key = new ClassLabel((int) avals[k], bval);
if (!classLabelMapping.containsKey(key))
classLabelMapping.put(key, new IntArrayList());
classLabelMapping.get(key).appendValue(aix[k]);
}
}
} else {
double[] denseBlk = A.getDenseBlockValues();
if (denseBlk == null)
break;
for (int j = 0; j < numCols; j++) {
int aVal = (int) denseBlk[ai + j];
int bVal = (int) sB.getValue(mv ? 0 : i, j);
if (aVal != 0 && bVal != 0) {
ClassLabel key = new ClassLabel(aVal, bVal);
if (!classLabelMapping.containsKey(key))
classLabelMapping.put(key, new IntArrayList());
classLabelMapping.get(key).appendValue(j);
}
}
}
int labelID = 1;
for (Entry<ClassLabel, IntArrayList> entry : classLabelMapping.entrySet()) {
int nVal = entry.getValue().size();
int[] list = entry.getValue().extractValues();
for (int k = 0, off = i * nc; k < nVal; k++) {
dN[off + list[k]] = nVal;
dC[off + list[k]] = labelID;
}
labelID++;
}
}
((Matrix) getFunctionInput(0)).getMatrixObject().release();
((Matrix) getFunctionInput(1)).getMatrixObject().release();
// prepare outputs
C.recomputeNonZeros();
C.examSparsity();
CMat = new Matrix(createOutputFilePathAndName("TMP"), nr, nc, ValueType.Double);
CMat.setMatrixDoubleArray(C, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo);
N.recomputeNonZeros();
N.examSparsity();
NMat = new Matrix(createOutputFilePathAndName("TMP"), nr, nc, ValueType.Double);
NMat.setMatrixDoubleArray(N, OutputInfo.BinaryBlockOutputInfo, InputInfo.BinaryBlockInputInfo);
} catch (DMLRuntimeException | IOException e) {
throw new RuntimeException("Error while executing RowClassMeet", e);
}
}
Aggregations