Search in sources :

Example 1 with DoubleIntListHashMap

use of org.apache.sysml.runtime.compress.utils.DoubleIntListHashMap 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);
}
Also used : DoubleIntListHashMap(org.apache.sysml.runtime.compress.utils.DoubleIntListHashMap) SparseBlock(org.apache.sysml.runtime.matrix.data.SparseBlock) IntArrayList(org.apache.sysml.runtime.compress.utils.IntArrayList)

Example 2 with DoubleIntListHashMap

use of org.apache.sysml.runtime.compress.utils.DoubleIntListHashMap 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);
}
Also used : DoubleIntListHashMap(org.apache.sysml.runtime.compress.utils.DoubleIntListHashMap) IntArrayList(org.apache.sysml.runtime.compress.utils.IntArrayList)

Aggregations

DoubleIntListHashMap (org.apache.sysml.runtime.compress.utils.DoubleIntListHashMap)2 IntArrayList (org.apache.sysml.runtime.compress.utils.IntArrayList)2 SparseBlock (org.apache.sysml.runtime.matrix.data.SparseBlock)1