Search in sources :

Example 6 with IntArrayList

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

Example 7 with IntArrayList

use of org.apache.sysml.runtime.compress.utils.IntArrayList in project 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 8 with IntArrayList

use of org.apache.sysml.runtime.compress.utils.IntArrayList in project 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

IntArrayList (org.apache.sysml.runtime.compress.utils.IntArrayList)8 DoubleIntListHashMap (org.apache.sysml.runtime.compress.utils.DoubleIntListHashMap)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)2 SideInput (org.apache.sysml.runtime.codegen.SpoofOperator.SideInput)2 DblArray (org.apache.sysml.runtime.compress.utils.DblArray)2 DblArrayIntListHashMap (org.apache.sysml.runtime.compress.utils.DblArrayIntListHashMap)2 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)2 SparseBlock (org.apache.sysml.runtime.matrix.data.SparseBlock)2 Matrix (org.apache.sysml.udf.Matrix)2