Search in sources :

Example 36 with IJV

use of org.apache.sysml.runtime.matrix.data.IJV in project incubator-systemml by apache.

the class SGDNesterovUpdate method copy.

// Assumption dest is zero-ed out.
private static void copy(MatrixBlock src, double[] dest) {
    if (src.isInSparseFormat()) {
        Iterator<IJV> iter = src.getSparseBlockIterator();
        while (iter.hasNext()) {
            IJV ijv = iter.next();
            dest[ijv.getI() * ijv.getJ()] = ijv.getV();
        }
    } else {
        double[] denseBlock = src.getDenseBlockValues();
        if (denseBlock != null) {
            // If not empty block
            System.arraycopy(denseBlock, 0, dest, 0, dest.length);
        }
    }
}
Also used : IJV(org.apache.sysml.runtime.matrix.data.IJV)

Example 37 with IJV

use of org.apache.sysml.runtime.matrix.data.IJV in project incubator-systemml by apache.

the class DataConverter method convertToLongVector.

public static long[] convertToLongVector(MatrixBlock mb) {
    int rows = mb.getNumRows();
    int cols = mb.getNumColumns();
    // 0-initialized
    long[] ret = new long[rows * cols];
    if (mb.isEmptyBlock(false))
        return ret;
    if (mb.isInSparseFormat()) {
        Iterator<IJV> iter = mb.getSparseBlockIterator();
        while (iter.hasNext()) {
            IJV cell = iter.next();
            ret[cell.getI() * cols + cell.getJ()] = (int) cell.getV();
        }
    } else {
        // memcopy row major representation if at least 1 non-zero
        for (int i = 0, cix = 0; i < rows; i++) for (int j = 0; j < cols; j++, cix++) ret[cix] = (int) (mb.getValueDenseUnsafe(i, j));
    }
    return ret;
}
Also used : IJV(org.apache.sysml.runtime.matrix.data.IJV)

Example 38 with IJV

use of org.apache.sysml.runtime.matrix.data.IJV in project incubator-systemml by apache.

the class DataConverter method convertToDenseBlock.

public static DenseBlock convertToDenseBlock(MatrixBlock mb, boolean deep) {
    int rows = mb.getNumRows();
    int cols = mb.getNumColumns();
    DenseBlock ret = (!mb.isInSparseFormat() && mb.isAllocated() && !deep) ? mb.getDenseBlock() : // 0-initialized
    DenseBlockFactory.createDenseBlock(rows, cols);
    if (!mb.isEmptyBlock(false)) {
        if (mb.isInSparseFormat()) {
            Iterator<IJV> iter = mb.getSparseBlockIterator();
            while (iter.hasNext()) {
                IJV cell = iter.next();
                ret.set(cell.getI(), cell.getJ(), cell.getV());
            }
        } else if (deep) {
            ret.set(mb.getDenseBlock());
        }
    }
    return ret;
}
Also used : DenseBlock(org.apache.sysml.runtime.matrix.data.DenseBlock) IJV(org.apache.sysml.runtime.matrix.data.IJV)

Example 39 with IJV

use of org.apache.sysml.runtime.matrix.data.IJV in project incubator-systemml by apache.

the class DataConverter method convertToIntVector.

public static int[] convertToIntVector(MatrixBlock mb) {
    int rows = mb.getNumRows();
    int cols = mb.getNumColumns();
    // 0-initialized
    int[] ret = new int[rows * cols];
    if (mb.isEmptyBlock(false))
        return ret;
    if (mb.isInSparseFormat()) {
        Iterator<IJV> iter = mb.getSparseBlockIterator();
        while (iter.hasNext()) {
            IJV cell = iter.next();
            ret[cell.getI() * cols + cell.getJ()] = (int) cell.getV();
        }
    } else {
        // memcopy row major representation if at least 1 non-zero
        for (int i = 0, cix = 0; i < rows; i++) for (int j = 0; j < cols; j++, cix++) ret[cix] = (int) (mb.getValueDenseUnsafe(i, j));
    }
    return ret;
}
Also used : IJV(org.apache.sysml.runtime.matrix.data.IJV)

Example 40 with IJV

use of org.apache.sysml.runtime.matrix.data.IJV in project incubator-systemml by apache.

the class DataConverter method convertToBooleanVector.

public static boolean[] convertToBooleanVector(MatrixBlock mb) {
    int rows = mb.getNumRows();
    int cols = mb.getNumColumns();
    // false-initialized
    boolean[] ret = new boolean[rows * cols];
    if (mb.getNonZeros() > 0) {
        if (mb.isInSparseFormat()) {
            Iterator<IJV> iter = mb.getSparseBlockIterator();
            while (iter.hasNext()) {
                IJV cell = iter.next();
                ret[cell.getI() * cols + cell.getJ()] = (cell.getV() != 0.0);
            }
        } else {
            for (int i = 0, cix = 0; i < rows; i++) for (int j = 0; j < cols; j++, cix++) ret[cix] = (mb.getValueDenseUnsafe(i, j) != 0.0);
        }
    }
    return ret;
}
Also used : IJV(org.apache.sysml.runtime.matrix.data.IJV)

Aggregations

IJV (org.apache.sysml.runtime.matrix.data.IJV)43 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)12 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)7 BufferedWriter (java.io.BufferedWriter)6 OutputStreamWriter (java.io.OutputStreamWriter)6 FileSystem (org.apache.hadoop.fs.FileSystem)6 SequenceFile (org.apache.hadoop.io.SequenceFile)6 SparseBlock (org.apache.sysml.runtime.matrix.data.SparseBlock)6 File (java.io.File)5 Path (org.apache.hadoop.fs.Path)5 JobConf (org.apache.hadoop.mapred.JobConf)5 IOException (java.io.IOException)4 Iterator (java.util.Iterator)4 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)4 MatrixCell (org.apache.sysml.runtime.matrix.data.MatrixCell)4 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)4 ArrayList (java.util.ArrayList)3 KahanFunction (org.apache.sysml.runtime.functionobjects.KahanFunction)3 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)3 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)3